2020-10-21 14:28:29 -05:00
|
|
|
import DiscordBasePlugin from './discord-base-plugin.js';
|
|
|
|
|
|
|
|
export default class DiscordRoundWinner extends DiscordBasePlugin {
|
|
|
|
static get description() {
|
|
|
|
return 'The <code>DiscordRoundWinner</code> plugin will send the round winner to a Discord channel.';
|
|
|
|
}
|
|
|
|
|
|
|
|
static get defaultEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get optionsSpecification() {
|
|
|
|
return {
|
|
|
|
...DiscordBasePlugin.optionsSpecification,
|
|
|
|
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.onNewGame = this.onNewGame.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async mount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.server.on('NEW_GAME', this.onNewGame);
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:13:53 -06:00
|
|
|
async unmount() {
|
2020-12-03 08:16:07 -06:00
|
|
|
this.server.removeEventListener('NEW_GAME', this.onNewGame);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onNewGame(info) {
|
|
|
|
await this.sendDiscordMessage({
|
|
|
|
embed: {
|
|
|
|
title: 'Round Winner',
|
|
|
|
color: this.options.color,
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'Message',
|
2021-02-03 14:44:55 -06:00
|
|
|
value: `${info.winner} won on ${this.server.layerHistory[1].layer.name}.`
|
2020-12-03 08:16:07 -06:00
|
|
|
}
|
|
|
|
],
|
|
|
|
timestamp: info.time.toISOString()
|
|
|
|
}
|
2020-10-21 14:28:29 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|