2020-10-13 06:59:07 -05:00
|
|
|
import DiscordBasePlugin from './discord-base-plugin.js';
|
2020-10-12 16:39:56 -05:00
|
|
|
|
2020-10-13 06:59:07 -05:00
|
|
|
export default class DiscordAdminBroadcast extends DiscordBasePlugin {
|
2020-10-12 16:39:56 -05:00
|
|
|
static get description() {
|
|
|
|
return (
|
|
|
|
'The <code>DiscordAdminBroadcast</code> plugin will send a copy of admin broadcasts made in game to a Discord ' +
|
|
|
|
'channel.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get defaultEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get optionsSpecification() {
|
|
|
|
return {
|
2020-10-13 06:59:07 -05:00
|
|
|
...DiscordBasePlugin.optionsSpecification,
|
2020-10-12 16:39:56 -05:00
|
|
|
channelID: {
|
|
|
|
required: true,
|
|
|
|
description: 'The ID of the channel to log admin broadcasts to.',
|
|
|
|
default: '',
|
|
|
|
example: '667741905228136459'
|
|
|
|
},
|
|
|
|
color: {
|
|
|
|
required: false,
|
|
|
|
description: 'The color of the embed.',
|
|
|
|
default: 16761867
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-03 08:16:07 -06:00
|
|
|
constructor(server, options, connectors) {
|
|
|
|
super(server, options, connectors);
|
|
|
|
|
|
|
|
this.onAdminBroadcast = this.onAdminBroadcast.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async mount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.server.on('ADMIN_BROADCAST', this.onAdminBroadcast);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async unmount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.server.removeEventListener('ADMIN_BROADCAST', this.onAdminBroadcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onAdminBroadcast(info) {
|
|
|
|
await this.sendDiscordMessage({
|
|
|
|
embed: {
|
|
|
|
title: 'Admin Broadcast',
|
|
|
|
color: this.options.color,
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'Message',
|
|
|
|
value: `${info.message}`
|
|
|
|
}
|
|
|
|
],
|
|
|
|
timestamp: info.time.toISOString()
|
|
|
|
}
|
2020-10-12 16:39:56 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|