diff --git a/README.md b/README.md index 9465d1c..01890d9 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,32 @@ The following is a list of plugins built into SquadJS, you can click their title ] +
+ DiscordDebug +

DiscordDebug

+

The DiscordDebug plugin can be used to help debug SquadJS by dumping SquadJS events to a Discord channel.

+

Options

+

discordClient (Required)

+
Description
+

Discord connector name.

+
Default
+
discord
+

channelID (Required)

+
Description
+

The ID of the channel to log events to.

+
Default
+
Example
+
667741905228136459
+

events (Required)

+
Description
+

A list of events to dump.

+
Default
+
[]
Example
+
[
+  "PLAYER_DIED"
+]
+
+
DiscordPlaceholder

DiscordPlaceholder

diff --git a/config.json b/config.json index 4145b6b..7436144 100644 --- a/config.json +++ b/config.json @@ -115,6 +115,13 @@ "ChatSquad" ] }, + { + "plugin": "DiscordDebug", + "enabled": false, + "discordClient": "discord", + "channelID": "", + "events": [] + }, { "plugin": "DiscordPlaceholder", "enabled": true, diff --git a/squad-server/plugins/discord-base-plugin.js b/squad-server/plugins/discord-base-plugin.js index db4b1f1..bf92d56 100644 --- a/squad-server/plugins/discord-base-plugin.js +++ b/squad-server/plugins/discord-base-plugin.js @@ -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); } diff --git a/squad-server/plugins/discord-debug.js b/squad-server/plugins/discord-debug.js new file mode 100644 index 0000000..b69b038 --- /dev/null +++ b/squad-server/plugins/discord-debug.js @@ -0,0 +1,42 @@ +import DiscordBasePlugin from './discord-base-plugin.js'; + +export default class DiscordDebug extends DiscordBasePlugin { + static get description() { + return ( + 'The DiscordDebug 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)}\`\`\``); + }); + } + } +} diff --git a/squad-server/plugins/index.js b/squad-server/plugins/index.js index 5e3ec98..0e32f45 100644 --- a/squad-server/plugins/index.js +++ b/squad-server/plugins/index.js @@ -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,