DiscordDebug plugin

This commit is contained in:
Thomas Smyth 2020-10-16 16:17:02 +01:00
parent e0691cc0a7
commit a6f3db94be
5 changed files with 78 additions and 1 deletions

View File

@ -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>

View File

@ -115,6 +115,13 @@
"ChatSquad"
]
},
{
"plugin": "DiscordDebug",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"events": []
},
{
"plugin": "DiscordPlaceholder",
"enabled": true,

View File

@ -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);
}

View 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)}\`\`\``);
});
}
}
}

View File

@ -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,