SquadJS/plugins/discord-admin-cam-logs/index.js

99 lines
2.7 KiB
JavaScript
Raw Normal View History

import { COPYRIGHT_MESSAGE } from 'core/constants';
2020-09-09 03:31:48 -05:00
import { PLAYER_POSSESS, PLAYER_UNPOSSESS } from 'squad-server/events';
2020-05-15 12:42:39 -05:00
export default {
name: 'discord-admin-cam-logs',
2020-08-22 08:32:39 -05:00
description:
2020-09-10 08:17:27 -05:00
'The <code>discord-admin-cam-logs</code> plugin will log in game admin camera usage to a Discord channel.',
2020-05-15 12:42:39 -05:00
defaultEnabled: true,
optionsSpec: {
discordClient: {
required: true,
2020-09-10 08:17:27 -05:00
description: 'The name of the Discord Connector to use.',
default: 'discord'
},
channelID: {
required: true,
2020-09-10 08:17:27 -05:00
description: 'The ID of the channel to log admin cam usage to.',
default: '',
example: '667741905228136459'
},
color: {
required: false,
2020-09-10 08:17:27 -05:00
description: 'The color of the embed.',
default: 16761867
}
},
2020-05-15 12:42:39 -05:00
init: async (server, options) => {
const channel = await options.discordClient.channels.fetch(options.channelID);
2020-05-15 12:42:39 -05:00
const adminsInCam = {};
2020-05-15 12:42:39 -05:00
2020-09-09 03:31:48 -05:00
server.on(PLAYER_POSSESS, (info) => {
if (info.player === null || info.possessClassname !== 'CameraMan') return;
2020-05-15 12:42:39 -05:00
adminsInCam[info.player.steamID] = info.time;
2020-05-15 12:42:39 -05:00
channel.send({
embed: {
title: `Admin Entered Admin Camera`,
color: 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(),
footer: {
text: COPYRIGHT_MESSAGE
2020-05-15 12:42:39 -05:00
}
}
});
2020-05-15 14:23:16 -05:00
});
2020-09-09 03:31:48 -05:00
server.on(PLAYER_UNPOSSESS, (info) => {
if (info.switchPossess === true || !(info.player.steamID in adminsInCam)) return;
2020-05-15 12:42:39 -05:00
channel.send({
embed: {
title: `Admin Left Admin Camera`,
color: 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.time.getTime() - adminsInCam[info.player.steamID].getTime()) / 60000
)} mins`
}
],
timestamp: info.time.toISOString(),
footer: {
text: COPYRIGHT_MESSAGE
2020-05-15 12:42:39 -05:00
}
}
});
2020-05-15 12:42:39 -05:00
delete adminsInCam[info.player.steamID];
});
}
};