SquadJS/squad-server/plugins/discord-admin-cam-logs.js

96 lines
2.5 KiB
JavaScript
Raw Normal View History

import DiscordBasePlugin from './discord-base-plugin.js';
export default class DiscordAdminCamLogs extends DiscordBasePlugin {
static get description() {
return 'The <code>DiscordAdminCamLogs</code> plugin will log in game admin camera usage to a Discord channel.';
}
static get defaultEnabled() {
return false;
}
static get optionsSpecification() {
return {
...DiscordBasePlugin.optionsSpecification,
channelID: {
required: true,
description: 'The ID of the channel to log admin camera usage 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.adminsInCam = {};
this.onEntry = this.onEntry.bind(this);
this.onExit = this.onExit.bind(this);
2020-12-03 08:16:07 -06:00
}
2020-12-08 06:13:53 -06:00
async mount() {
this.server.on('POSSESSED_ADMIN_CAMERA', this.onEntry);
this.server.on('UNPOSSESSED_ADMIN_CAMERA', this.onExit);
2020-12-03 08:16:07 -06:00
}
2020-12-08 06:13:53 -06:00
async unmount() {
this.server.removeEventListener('POSSESSED_ADMIN_CAMERA', this.onEntry);
this.server.removeEventListener('UNPOSSESSED_ADMIN_CAMERA', this.onExit);
2020-12-03 08:16:07 -06:00
}
async onEntry(info) {
2020-12-03 08:16:07 -06:00
await this.sendDiscordMessage({
embed: {
title: `Admin Entered Admin Camera`,
color: this.options.color,
fields: [
{
name: "Admin's Name",
value: info.player.name,
inline: true
},
{
name: "Admin's SteamID",
value: `[${info.player.steamID}](https://steamcommunity.com/profiles/${info.player.steamID})`,
inline: true
}
],
timestamp: info.time.toISOString()
}
});
}
2020-12-03 08:16:07 -06:00
async onExit(info) {
2020-12-03 08:16:07 -06:00
await this.sendDiscordMessage({
embed: {
title: `Admin Left Admin Camera`,
color: this.options.color,
fields: [
{
name: "Admin's Name",
value: info.player.name,
inline: true
},
{
name: "Admin's SteamID",
value: `[${info.player.steamID}](https://steamcommunity.com/profiles/${info.player.steamID})`,
inline: true
},
{
name: 'Time in Admin Camera',
value: `${Math.round(info.duration / 60000)} mins`
2020-12-03 08:16:07 -06:00
}
],
timestamp: info.time.toISOString()
}
});
}
}