2020-10-14 13:50:35 -05:00
|
|
|
import BasePlugin from './base-plugin.js';
|
|
|
|
|
|
|
|
export default class DiscordSubsystemRestarter extends BasePlugin {
|
|
|
|
static get description() {
|
|
|
|
return (
|
|
|
|
'The <code>DiscordSubSystemRestarter</code> plugin allows you to manually restart SquadJS subsystems in case ' +
|
|
|
|
'an issues arises with them.' +
|
|
|
|
'<ul>' +
|
|
|
|
'<li><code>!squadjs restartsubsystem rcon</code></li>' +
|
|
|
|
'<li><code>!squadjs restartsubsystem logparser</code></li>' +
|
|
|
|
'</ul>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get defaultEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get optionsSpecification() {
|
|
|
|
return {
|
|
|
|
discordClient: {
|
|
|
|
required: true,
|
|
|
|
description: 'Discord connector name.',
|
|
|
|
connector: 'discord',
|
|
|
|
default: 'discord'
|
|
|
|
},
|
|
|
|
role: {
|
|
|
|
required: true,
|
|
|
|
description: 'ID of role required to run the sub system restart commands.',
|
|
|
|
default: '',
|
|
|
|
example: '667741905228136459'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
constructor(server, options, connectors) {
|
|
|
|
super(server, options, connectors);
|
2020-10-14 13:50:35 -05:00
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
this.onMessage = this.onMessage.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async mount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.options.discordClient.on('message', this.onMessage);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async unmount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.options.discordClient.removeEventListener('message', this.onMessage);
|
|
|
|
}
|
2020-10-14 13:50:35 -05:00
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
async onMessage(message) {
|
|
|
|
// check the author of the message is not a bot
|
|
|
|
if (message.author.bot) return;
|
2020-10-14 13:50:35 -05:00
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
if (message.content.match(/!squadjs restartsubsystem rcon/i)) {
|
|
|
|
if (!message.member._roles.includes(this.options.role)) {
|
|
|
|
message.reply('you do not have permission to do that.');
|
2021-01-01 12:40:52 -06:00
|
|
|
return;
|
2020-10-14 13:50:35 -05:00
|
|
|
}
|
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
await this.server.restartRCON();
|
|
|
|
message.reply('restarted the SquadJS RCON subsystem.');
|
|
|
|
}
|
2020-10-14 13:50:35 -05:00
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
if (message.content.match(/!squadjs restartsubsystem logparser/i)) {
|
|
|
|
if (!message.member._roles.includes(this.options.role)) {
|
|
|
|
message.reply('you do not have permission to do that.');
|
2021-01-01 12:40:52 -06:00
|
|
|
return;
|
2020-10-14 13:50:35 -05:00
|
|
|
}
|
2020-12-03 08:16:07 -06:00
|
|
|
|
|
|
|
await this.server.restartLogParser();
|
|
|
|
message.reply('restarted the SquadJS LogParser subsystem.');
|
|
|
|
}
|
2020-10-14 13:50:35 -05:00
|
|
|
}
|
|
|
|
}
|