mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 17:34:25 -05:00
Merge pull request #56 from LuisMartinSchick/chat-commands
Chat commands
This commit is contained in:
commit
46283ab5b6
19
README.md
19
README.md
@ -207,6 +207,25 @@ The `auto-tk-warn` plugin will automatically warn players in game to apologise f
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### chat-commands
|
||||
The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat.
|
||||
|
||||
##### Options
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Option</th>
|
||||
<th>Type</th>
|
||||
<th>Required</th>
|
||||
<th>Default</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>commands</td><td>Array of command configs</td><td>false</td><td>[{"command":"!squadjs","type":"warn","response":"This server is powered by SquadJS.","ignoreChats":[]}]</td><td>See the default value as an example of how to configure commands. Type can either be `warn` or `broadcast`</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### discord-admin-broadcast
|
||||
The `discord-admin-broadcast` plugin will send a copy of admin broadcasts made in game to a Discord channel.
|
||||
|
||||
|
12
config.json
12
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,
|
||||
|
43
plugins/chat-commands/index.js
Normal file
43
plugins/chat-commands/index.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { CHAT_MESSAGE } from 'squad-server/events';
|
||||
|
||||
export default {
|
||||
name: 'chat-commands',
|
||||
description:
|
||||
'The `chat-command` plugin will automatically broadcast messages when a player types the corresponding command into any chat.',
|
||||
|
||||
defaultEnabled: false,
|
||||
optionsSpec: {
|
||||
commands: {
|
||||
type: 'Array of command configs',
|
||||
required: false,
|
||||
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(CHAT_MESSAGE, (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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
@ -12,9 +12,11 @@ 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,
|
||||
chatCommands,
|
||||
discordAdminBroadcast,
|
||||
discordAdminCamLogs,
|
||||
discordChat,
|
||||
@ -32,6 +34,7 @@ export {
|
||||
|
||||
const plugins = [
|
||||
autoTKWarn,
|
||||
chatCommands,
|
||||
discordAdminBroadcast,
|
||||
discordAdminCamLogs,
|
||||
discordChat,
|
||||
|
Loading…
Reference in New Issue
Block a user