SquadJS/plugins/chat-commands/index.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-09-09 11:51:00 -05:00
import { CHAT_MESSAGE } from 'squad-server/events';
export default {
2020-09-09 11:51:00 -05:00
name: 'chat-commands',
description:
2020-09-10 08:17:27 -05:00
'The <code>chat-command</code> plugin can be configured to make chat commands that broadcast or warn the caller ' +
'with present messages.',
2020-09-10 08:17:27 -05:00
defaultEnabled: true,
optionsSpec: {
2020-09-09 11:51:00 -05:00
commands: {
required: false,
2020-09-10 08:17:27 -05:00
description:
'An array of objects containing the following properties: ' +
'<ul>' +
'<li><code>command</code> - The command that initiates the message.</li>' +
'<li><code>type</code> - Either <code>warn</code> or <code>broadcast</code>.</li>' +
'<li><code>response</code> - The message to respond with.</li>' +
'<li><code>ignoreChats</code> - A list of chats to ignore the commands in. Use this to limit it to admins.</li>' +
'</ul>',
2020-09-09 11:51:00 -05:00
default: [
{
command: '!squadjs',
type: 'warn',
response: 'This server is powered by SquadJS.',
ignoreChats: []
}
2020-09-10 08:17:27 -05:00
]
}
},
init: async (server, options) => {
2020-09-09 11:51:00 -05:00
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);
}
}
});
}
};