mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 14:04:25 -05:00
DiscordDebug plugin
This commit is contained in:
parent
e0691cc0a7
commit
a6f3db94be
26
README.md
26
README.md
@ -358,6 +358,32 @@ The following is a list of plugins built into SquadJS, you can click their title
|
||||
]</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>DiscordDebug</summary>
|
||||
<h2>DiscordDebug</h2>
|
||||
<p>The <code>DiscordDebug</code> plugin can be used to help debug SquadJS by dumping SquadJS events to a Discord channel.</p>
|
||||
<h3>Options</h3>
|
||||
<h4>discordClient (Required)</h4>
|
||||
<h6>Description</h6>
|
||||
<p>Discord connector name.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>discord</code></pre>
|
||||
<h4>channelID (Required)</h4>
|
||||
<h6>Description</h6>
|
||||
<p>The ID of the channel to log events to.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code></code></pre><h6>Example</h6>
|
||||
<pre><code>667741905228136459</code></pre>
|
||||
<h4>events (Required)</h4>
|
||||
<h6>Description</h6>
|
||||
<p>A list of events to dump.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>[]</code></pre><h6>Example</h6>
|
||||
<pre><code>[
|
||||
"PLAYER_DIED"
|
||||
]</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>DiscordPlaceholder</summary>
|
||||
<h2>DiscordPlaceholder</h2>
|
||||
|
@ -115,6 +115,13 @@
|
||||
"ChatSquad"
|
||||
]
|
||||
},
|
||||
{
|
||||
"plugin": "DiscordDebug",
|
||||
"enabled": false,
|
||||
"discordClient": "discord",
|
||||
"channelID": "",
|
||||
"events": []
|
||||
},
|
||||
{
|
||||
"plugin": "DiscordPlaceholder",
|
||||
"enabled": true,
|
||||
|
@ -26,7 +26,7 @@ export default class DiscordBasePlugin extends BasePlugin {
|
||||
async sendDiscordMessage(message, channelID = this.channelID) {
|
||||
if (this.channel === null) this.channel = await this.discordClient.channels.fetch(channelID);
|
||||
|
||||
if ('embed' in message) message.embed.footer = { text: COPYRIGHT_MESSAGE };
|
||||
if (typeof message === 'object' && 'embed' in message) message.embed.footer = { text: COPYRIGHT_MESSAGE };
|
||||
|
||||
await this.channel.send(message);
|
||||
}
|
||||
|
42
squad-server/plugins/discord-debug.js
Normal file
42
squad-server/plugins/discord-debug.js
Normal file
@ -0,0 +1,42 @@
|
||||
import DiscordBasePlugin from './discord-base-plugin.js';
|
||||
|
||||
export default class DiscordDebug extends DiscordBasePlugin {
|
||||
static get description() {
|
||||
return (
|
||||
'The <code>DiscordDebug</code> plugin can be used to help debug SquadJS by dumping SquadJS events to a ' +
|
||||
'Discord channel.'
|
||||
);
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
...DiscordBasePlugin.optionsSpecification,
|
||||
channelID: {
|
||||
required: true,
|
||||
description: 'The ID of the channel to log events to.',
|
||||
default: '',
|
||||
example: '667741905228136459'
|
||||
},
|
||||
events: {
|
||||
required: true,
|
||||
description: 'A list of events to dump.',
|
||||
default: [],
|
||||
example: ['PLAYER_DIED']
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super(server, options);
|
||||
|
||||
for (const event of options.events) {
|
||||
server.on(event, async (info) => {
|
||||
await this.sendDiscordMessage(`\`\`\`${JSON.stringify({ ...info, event }, null, 2)}\`\`\``);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import DiscordAdminBroadcast from './discord-admin-broadcast.js';
|
||||
import DiscordAdminCamLogs from './discord-admin-cam-logs.js';
|
||||
import DiscordAdminRequest from './discord-admin-request.js';
|
||||
import DiscordChat from './discord-chat.js';
|
||||
import DiscordDebug from './discord-debug.js';
|
||||
import DiscordPlaceholder from './discord-placeholder.js';
|
||||
import DiscordRcon from './discord-rcon.js';
|
||||
import DiscordSubsystemRestarter from './discord-subsystem-restarter.js';
|
||||
@ -17,6 +18,7 @@ const plugins = [
|
||||
DiscordAdminCamLogs,
|
||||
DiscordAdminRequest,
|
||||
DiscordChat,
|
||||
DiscordDebug,
|
||||
DiscordPlaceholder,
|
||||
DiscordRcon,
|
||||
DiscordSubsystemRestarter,
|
||||
|
Loading…
Reference in New Issue
Block a user