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

97 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-05-15 12:42:39 -05:00
import { COPYRIGHT_MESSAGE } from 'core/config';
2020-06-13 09:33:44 -05:00
import {
LOG_PARSER_PLAYER_POSSESS,
LOG_PARSER_PLAYER_UNPOSSESS
} from 'squad-server/events/log-parser';
2020-05-15 12:42:39 -05:00
2020-06-13 09:33:44 -05:00
export default async function(server, discordClient, channelID, options = {}) {
2020-05-15 12:42:39 -05:00
if (!server)
throw new Error(
'DiscordAdminCamLogs must be provided with a reference to the server.'
);
if (!discordClient)
throw new Error(
'DiscordAdminCamLogs must be provided with a Discord.js client.'
);
if (!channelID)
throw new Error('DiscordAdminCamLogs must be provided with a channel ID.');
options = {
color: 16761867,
...options
};
const channel = await discordClient.channels.fetch(channelID);
const adminsInCam = {};
server.on(LOG_PARSER_PLAYER_POSSESS, info => {
2020-05-15 14:23:16 -05:00
if (info.player === null || info.possessClassname !== 'CameraMan') return;
2020-05-15 12:42:39 -05:00
2020-05-15 14:23:16 -05:00
adminsInCam[info.player.steamID] = info.time;
2020-05-15 12:42:39 -05:00
2020-05-15 14:23:16 -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
2020-05-15 12:42:39 -05:00
}
2020-05-15 14:23:16 -05:00
],
timestamp: info.time.toISOString(),
footer: {
text: COPYRIGHT_MESSAGE
2020-05-15 12:42:39 -05:00
}
2020-05-15 14:23:16 -05:00
}
});
});
server.on(LOG_PARSER_PLAYER_UNPOSSESS, info => {
2020-06-13 09:33:44 -05:00
if (info.switchPossess === true || !(info.player.steamID in adminsInCam))
return;
2020-05-15 12:42:39 -05:00
2020-05-15 14:23:16 -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()) /
2020-06-13 09:33:44 -05:00
60000
2020-05-15 14:23:16 -05:00
)} mins`
2020-05-15 12:42:39 -05:00
}
2020-05-15 14:23:16 -05:00
],
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-05-15 12:42:39 -05:00
2020-05-15 14:23:16 -05:00
delete adminsInCam[info.player.steamID];
2020-05-15 12:42:39 -05:00
});
}