From 63db3f7dffddb6538e8f984a05cfc527196e4798 Mon Sep 17 00:00:00 2001 From: Luis Martin Schick Date: Wed, 9 Sep 2020 18:37:45 +0200 Subject: [PATCH 1/5] Added chat-commands, updated plugin index.js to reflect addition --- plugins/chat-commands/index.js | 26 ++++++++++++++++++++++++++ plugins/index.js | 7 +++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 plugins/chat-commands/index.js diff --git a/plugins/chat-commands/index.js b/plugins/chat-commands/index.js new file mode 100644 index 0000000..9277fd2 --- /dev/null +++ b/plugins/chat-commands/index.js @@ -0,0 +1,26 @@ +import { LOG_PARSER_TEAMKILL } from 'squad-server/events/log-parser'; + +export default { + name: 'auto-tk-warn', + description: + 'The `auto-tk-warn` plugin will automatically warn players in game to apologise for teamkills when they ' + + 'teamkill another player.', + + defaultEnabled: true, + optionsSpec: { + message: { + type: 'String', + required: false, + default: 'Please apologise for ALL TKs in ALL chat!', + description: 'The message to warn players with.' + } + }, + + init: async (server, options) => { + server.on(LOG_PARSER_TEAMKILL, (info) => { + // ignore suicides + if (info.attacker.steamID === info.victim.steamID) return; + server.rcon.warn(info.attacker.steamID, options.message); + }); + } +}; diff --git a/plugins/index.js b/plugins/index.js index fcf6a72..31dfc22 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -12,6 +12,7 @@ import mapvoteDidYouMean from './mapvote/mapvote-did-you-mean.js'; import mysqlLog from './mysql-log/index.js'; import seedingMessage from './seeding-message/index.js'; import teamRandomizer from './team-randomizer/index.js'; +import chatCommands from './chat-commands/index.js'; export { autoTKWarn, @@ -27,7 +28,8 @@ export { mapvoteDidYouMean, mysqlLog, seedingMessage, - teamRandomizer + teamRandomizer, + chatCommands }; const plugins = [ @@ -44,7 +46,8 @@ const plugins = [ mapvoteDidYouMean, mysqlLog, seedingMessage, - teamRandomizer + teamRandomizer, + chatCommands ]; const namedPlugins = {}; From 5f81945f73c55d39f8986b2e5cdd11b40ccde029 Mon Sep 17 00:00:00 2001 From: Luis Martin Schick Date: Wed, 9 Sep 2020 18:51:00 +0200 Subject: [PATCH 2/5] Update chat-commands --- plugins/chat-commands/index.js | 44 ++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/plugins/chat-commands/index.js b/plugins/chat-commands/index.js index 9277fd2..552a3eb 100644 --- a/plugins/chat-commands/index.js +++ b/plugins/chat-commands/index.js @@ -1,26 +1,44 @@ -import { LOG_PARSER_TEAMKILL } from 'squad-server/events/log-parser'; +import { CHAT_MESSAGE } from 'squad-server/events'; export default { - name: 'auto-tk-warn', + name: 'chat-commands', description: - 'The `auto-tk-warn` plugin will automatically warn players in game to apologise for teamkills when they ' + - 'teamkill another player.', + 'The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat.', - defaultEnabled: true, + defaultEnabled: false, optionsSpec: { - message: { - type: 'String', + commands: { + type: 'Array of command configs', required: false, - default: 'Please apologise for ALL TKs in ALL chat!', - description: 'The message to warn players with.' + default: [ + { + command: '!squadjs', + type: 'warn', + response: 'This server is powered by SquadJS.', + ignoreChats: [] + } + ], + description: + 'See the default value as an example of how to configure commands. Type can either be `warn` or `broadcast`' } }, init: async (server, options) => { - server.on(LOG_PARSER_TEAMKILL, (info) => { - // ignore suicides - if (info.attacker.steamID === info.victim.steamID) return; - server.rcon.warn(info.attacker.steamID, options.message); + server.on(CHAT_MESSAGE, (info) => { + console.log(info); + // loop through all possibilities + for (const command of options.commands) { + // check if message is a command + if (!info.message.startsWith(command.command)) continue; + // check if ignored channel + if (command.ignoreChats.includes(info.chat)) continue; + // React to command with either a broadcast or a warning + if (command.type === 'broadcast') { + server.rcon.broadcast(command.response); + } else if (command.type === 'warn') { + server.rcon.warn(info.steamID, command.response); + } + } }); } }; From c741f361d8b460667c00f2431a7edae50875c547 Mon Sep 17 00:00:00 2001 From: Luis Martin Schick Date: Wed, 9 Sep 2020 19:03:39 +0200 Subject: [PATCH 3/5] Finished troubleshooting --- README.md | 19 +++++++++++++++++++ config.json | 12 ++++++++++++ plugins/chat-commands/index.js | 1 - 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 474cfad..8eecb2c 100644 --- a/README.md +++ b/README.md @@ -538,6 +538,25 @@ The `team-randomizer` plugin can be used to randomize teams. It's great for dest commandStringfalse!randomizeThe command used to randomize the teams. + +### chat-commands +The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat. + +##### Options + + + + + + + + + + + + + +
OptionTypeRequiredDefaultDescription
commandsArray of command configsfalse[{"command":"!squadjs","type":"warn","response":"This server is powered by SquadJS.","ignoreChats":[]}]See the default value as an example of how to configure commands. Type can either be `warn` or `broadcast`
## Creating Your Own Plugins To create your own plugin you need a basic knowledge of JavaScript. diff --git a/config.json b/config.json index 9f39b2c..48ea68d 100644 --- a/config.json +++ b/config.json @@ -174,6 +174,18 @@ "plugin": "team-randomizer", "enabled": true, "command": "!randomize" + }, + { + "plugin": "chat-commands", + "enabled": false, + "commands": [ + { + "command": "!squadjs", + "type": "warn", + "response": "This server is powered by SquadJS.", + "ignoreChats": [] + } + ] } ] } \ No newline at end of file diff --git a/plugins/chat-commands/index.js b/plugins/chat-commands/index.js index 552a3eb..07ae609 100644 --- a/plugins/chat-commands/index.js +++ b/plugins/chat-commands/index.js @@ -25,7 +25,6 @@ export default { init: async (server, options) => { server.on(CHAT_MESSAGE, (info) => { - console.log(info); // loop through all possibilities for (const command of options.commands) { // check if message is a command From 822a17ac30acab9ae18f8114bebd23ce6e1cfb3a Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Wed, 9 Sep 2020 18:37:24 +0100 Subject: [PATCH 4/5] Reorder plugins --- plugins/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/index.js b/plugins/index.js index 31dfc22..bbb9996 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -16,6 +16,7 @@ import chatCommands from './chat-commands/index.js'; export { autoTKWarn, + chatCommands, discordAdminBroadcast, discordAdminCamLogs, discordChat, @@ -28,12 +29,12 @@ export { mapvoteDidYouMean, mysqlLog, seedingMessage, - teamRandomizer, - chatCommands + teamRandomizer }; const plugins = [ autoTKWarn, + chatCommands, discordAdminBroadcast, discordAdminCamLogs, discordChat, @@ -46,8 +47,7 @@ const plugins = [ mapvoteDidYouMean, mysqlLog, seedingMessage, - teamRandomizer, - chatCommands + teamRandomizer ]; const namedPlugins = {}; From 9b6d890df84838e9dd56afa92b22eb516c8e9f9a Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Wed, 9 Sep 2020 18:38:08 +0100 Subject: [PATCH 5/5] Rebuild config and readme --- README.md | 38 +++++++++++++++++++------------------- config.json | 24 ++++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8eecb2c..73b6e5f 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,25 @@ The `auto-tk-warn` plugin will automatically warn players in game to apologise f +### chat-commands +The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat. + +##### Options + + + + + + + + + + + + + +
OptionTypeRequiredDefaultDescription
commandsArray of command configsfalse[{"command":"!squadjs","type":"warn","response":"This server is powered by SquadJS.","ignoreChats":[]}]See the default value as an example of how to configure commands. Type can either be `warn` or `broadcast`
+ ### discord-admin-broadcast The `discord-admin-broadcast` plugin will send a copy of admin broadcasts made in game to a Discord channel. @@ -538,25 +557,6 @@ The `team-randomizer` plugin can be used to randomize teams. It's great for dest commandStringfalse!randomizeThe command used to randomize the teams. - -### chat-commands -The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat. - -##### Options - - - - - - - - - - - - - -
OptionTypeRequiredDefaultDescription
commandsArray of command configsfalse[{"command":"!squadjs","type":"warn","response":"This server is powered by SquadJS.","ignoreChats":[]}]See the default value as an example of how to configure commands. Type can either be `warn` or `broadcast`
## Creating Your Own Plugins To create your own plugin you need a basic knowledge of JavaScript. diff --git a/config.json b/config.json index 48ea68d..6a02afd 100644 --- a/config.json +++ b/config.json @@ -66,6 +66,18 @@ "enabled": true, "message": "Please apologise for ALL TKs in ALL chat!" }, + { + "plugin": "chat-commands", + "enabled": false, + "commands": [ + { + "command": "!squadjs", + "type": "warn", + "response": "This server is powered by SquadJS.", + "ignoreChats": [] + } + ] + }, { "plugin": "discord-admin-broadcast", "enabled": true, @@ -174,18 +186,6 @@ "plugin": "team-randomizer", "enabled": true, "command": "!randomize" - }, - { - "plugin": "chat-commands", - "enabled": false, - "commands": [ - { - "command": "!squadjs", - "type": "warn", - "response": "This server is powered by SquadJS.", - "ignoreChats": [] - } - ] } ] } \ No newline at end of file