SquadJS/squad-server/plugins/discord-teamkill.js

97 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-10-21 16:18:34 -05:00
import DiscordBasePlugin from './discord-base-plugin.js';
export default class DiscordTeamkill extends DiscordBasePlugin {
static get description() {
2020-10-21 16:49:07 -05:00
return (
'The <code>DiscordTeamkill</code> plugin logs teamkills and related information to a Discord channel for ' +
'admins to review.'
);
2020-10-21 16:18:34 -05:00
}
static get defaultEnabled() {
return true;
}
static get optionsSpecification() {
return {
...DiscordBasePlugin.optionsSpecification,
channelID: {
required: true,
description: 'The ID of the channel to log teamkills to.',
default: '',
example: '667741905228136459'
},
color: {
required: false,
description: 'The color of the embeds.',
default: 16761867
},
disableSCBL: {
required: false,
description: 'Disable Squad Community Ban List information.',
default: false
}
};
}
2020-12-03 08:16:07 -06:00
constructor(server, options, connectors) {
super(server, options, connectors);
2020-10-21 16:18:34 -05:00
2020-12-03 08:16:07 -06:00
this.onTeamkill = this.onTeamkill.bind(this);
}
2020-12-08 06:13:53 -06:00
async mount() {
2020-12-03 08:16:07 -06:00
this.server.on('TEAMKILL', this.onTeamkill);
}
2020-10-21 16:18:34 -05:00
2020-12-08 06:13:53 -06:00
async unmount() {
2020-12-03 08:16:07 -06:00
this.server.removeEventListener('TEAMKILL', this.onTeamkill);
}
async onTeamkill(info) {
if (!info.attacker) return;
2020-10-21 16:18:34 -05:00
2020-12-03 08:16:07 -06:00
const fields = [
{
name: "Attacker's Name",
value: info.attacker.name,
inline: true
},
{
name: "Attacker's SteamID",
value: `[${info.attacker.steamID}](https://steamcommunity.com/profiles/${info.attacker.steamID})`,
inline: true
},
{
name: 'Weapon',
value: info.weapon
},
{
name: "Victim's Name",
value: info.victim.name,
inline: true
},
{
name: "Victim's SteamID",
value: `[${info.victim.steamID}](https://steamcommunity.com/profiles/${info.victim.steamID})`,
inline: true
}
];
2020-10-21 16:18:34 -05:00
2020-12-03 08:16:07 -06:00
if (!this.options.disableSCBL)
fields.push({
name: 'Squad Community Ban List',
value: `[Attacker's Bans](https://squad-community-ban-list.com/search/${info.attacker.steamID})`
2020-10-21 16:18:34 -05:00
});
2020-12-03 08:16:07 -06:00
await this.sendDiscordMessage({
embed: {
title: `Teamkill: ${info.attacker.name}`,
color: this.options.color,
fields: fields,
timestamp: info.time.toISOString()
}
2020-10-21 16:18:34 -05:00
});
}
}