SquadJS/squad-server/plugins/chat-commands.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

import BasePlugin from './base-plugin.js';
export default class ChatCommands extends BasePlugin {
static get description() {
return (
'The <code>ChatCommands</code> plugin can be configured to make chat commands that broadcast or warn the ' +
'caller with present messages.'
);
}
static get defaultEnabled() {
return true;
}
static get optionsSpecification() {
return {
commands: {
required: false,
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>',
default: [
{
command: 'squadjs',
type: 'warn',
response: 'This server is powered by SquadJS.',
ignoreChats: []
}
]
}
};
}
constructor(server, options) {
2020-10-23 05:18:23 -05:00
super(server, options);
2020-10-23 05:18:23 -05:00
for (const command of this.options.commands) {
server.on(`CHAT_COMMAND:${command.command}`, async (data) => {
if (command.ignoreChats.includes(data.chat)) return;
if (command.type === 'broadcast') {
await server.rcon.broadcast(command.response);
} else if (command.type === 'warn') {
await server.rcon.warn(data.player.steamID, command.response);
}
});
}
}
}