fix/convert admin logs to webhooks
This commit is contained in:
2 files changed
+17
-8
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "13.3.16",
|
||||
"version": "13.3.17",
|
||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { nearest } = require('../database/destinations');
|
||||
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||
|
||||
module.exports = {
|
||||
|
||||
SendConnectionLogs: async (client, guild, data) => {
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return;
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
@@ -14,6 +16,9 @@ module.exports = {
|
||||
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
||||
.setDescription(`**${data.connected ? 'Connect' : 'Disconnect'} Event - <t:${unixTime}>\n${data.player} ${data.connected ? 'Connected' : 'Disconnected'}**`);
|
||||
|
||||
const NAME = "DayZ.R Admin Logs";
|
||||
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||
|
||||
if (!data.connected) {
|
||||
if (data.lastConnectionDate != null) {
|
||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
||||
@@ -22,17 +27,20 @@ module.exports = {
|
||||
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
||||
}
|
||||
|
||||
if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
||||
// if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
||||
await WebhookSend(client, webhook, {embeds: [connectionLog]});
|
||||
},
|
||||
|
||||
DetectCombatLog: async (client, guild, data) => {
|
||||
if (!client.exists(data.lastDamageDate)) return;
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return; // Ensure channel exists
|
||||
|
||||
const newDt = await client.getDateEST(data.time);
|
||||
const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
||||
|
||||
// If diff is greater than 5 minutes, not a combat log
|
||||
// If diff is greater than configured time in minutes, not a combat log
|
||||
// or if death after last combat
|
||||
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||
@@ -42,9 +50,6 @@ module.exports = {
|
||||
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
||||
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
||||
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return;
|
||||
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
||||
|
||||
@@ -52,8 +57,12 @@ module.exports = {
|
||||
.setColor(client.config.Colors.Red)
|
||||
.setDescription(`**NOTICE:**\n**${data.player}** has combat logged at <t:${unixTime}> when fighting **${data.lastHitBy}\nLocation [${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**\n${destination}`);
|
||||
|
||||
if (client.exists(guild.adminRole)) channel.send({ content: `<@&${guild.adminRole}>` });
|
||||
const NAME = "DayZ.R Admin Logs";
|
||||
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||
|
||||
return channel.send({ embeds: [combatLog] });
|
||||
let content = { embeds: [combatLog] };
|
||||
if (client.exists(guild.adminRole)) content.content = `<@&${guild.adminRole}>`;
|
||||
WebhookSend(client, webhook, content);
|
||||
// return channel.send({ embeds: [combatLog] });
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user