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

99 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-08-12 14:49:59 -05:00
import DiscordBasePlugin from './discord-base-plugin.js';
export default class DiscordKillFeed extends DiscordBasePlugin {
static get description() {
return (
'The <code>DiscordKillFeed</code> plugin logs all wounds and related information to a Discord channel for ' +
'admins to review.'
);
}
static get defaultEnabled() {
return false;
}
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
},
disableCBL: {
2021-08-12 14:49:59 -05:00
required: false,
description: 'Disable Community Ban List information.',
2021-08-12 14:49:59 -05:00
default: false
}
};
}
constructor(server, options, connectors) {
super(server, options, connectors);
this.onWound = this.onWound.bind(this);
}
async mount() {
this.server.on('PLAYER_WOUNDED', this.onWound);
}
async unmount() {
this.server.removeEventListener('PLAYER_WOUNDED', this.onWound);
}
async onWound(info) {
if (!info.attacker) return;
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",
2022-05-27 09:07:09 -05:00
value: info.victim ? info.victim.name : 'Unknown',
2021-08-12 14:49:59 -05:00
inline: true
},
{
name: "Victim's SteamID",
2022-05-27 09:07:09 -05:00
value: info.victim
? `[${info.victim.steamID}](https://steamcommunity.com/profiles/${info.victim.steamID})`
: 'Unknown',
2021-08-12 14:49:59 -05:00
inline: true
}
];
if (!this.options.disableCBL)
2021-08-12 14:49:59 -05:00
fields.push({
name: 'Community Ban List',
value: `[Attacker's Bans](https://communitybanlist.com/search/${info.attacker.steamID})`
2021-08-12 14:49:59 -05:00
});
await this.sendDiscordMessage({
embed: {
title: `KillFeed: ${info.attacker.name}`,
color: this.options.color,
fields: fields,
timestamp: info.time.toISOString()
}
});
}
}