SquadJS/plugins/discord-teamkill/index.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-05-15 12:42:39 -05:00
import { COPYRIGHT_MESSAGE } from 'core/config';
import { LOG_PARSER_TEAMKILL } from 'squad-server/events/log-parser';
2020-06-13 09:33:44 -05:00
export default async function(server, discordClient, channelID, options = {}) {
2020-06-13 11:35:00 -05:00
if (!server) throw new Error('DiscordTeamKill must be provided with a reference to the server.');
2020-05-15 12:42:39 -05:00
2020-06-13 11:35:00 -05:00
if (!discordClient) throw new Error('DiscordTeamkill must be provided with a Discord.js client.');
2020-05-15 12:42:39 -05:00
2020-06-13 11:35:00 -05:00
if (!channelID) throw new Error('DiscordTeamkill must be provided with a channel ID.');
2020-05-15 12:42:39 -05:00
options = {
2020-05-30 06:13:01 -05:00
teamkillColor: 16761867,
suicideColor: 16761867,
ignoreSuicides: false,
disableSCBL: false,
2020-05-15 12:42:39 -05:00
...options
};
const channel = await discordClient.channels.fetch(channelID);
server.on(LOG_PARSER_TEAMKILL, info => {
if (!info.attacker) return;
2020-06-13 09:33:44 -05:00
if (options.ignoreSuicides && info.suicide) return;
2020-05-15 12:42:39 -05: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-06-13 09:33:44 -05:00
if (!options.disableSCBL)
fields.push({
name: 'Squad Community Ban List',
value: `[Attacker's Bans](https://squad-community-ban-list.com/search/${info.attacker.steamID})\n[Victims's Bans](https://squad-community-ban-list.com/search/${info.victim.steamID})`
});
2020-05-15 12:42:39 -05:00
channel.send({
embed: {
2020-06-13 11:35:00 -05:00
title: `${info.suicide ? 'Suicide' : 'Teamkill'}: ${info.attacker.name}`,
2020-05-30 06:13:01 -05:00
color: info.suicide ? options.suicideColor : options.teamkillColor,
fields: fields,
2020-05-15 12:42:39 -05:00
timestamp: info.time.toISOString(),
footer: {
text: COPYRIGHT_MESSAGE
}
}
});
});
}