From 8d822a352ac149772a631b0e3e0ec784f50caea0 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Sun, 17 Nov 2024 11:47:07 -0800 Subject: [PATCH] fix/convert admin logs to webhooks --- package.json | 2 +- util/AdminLogsHandler.js | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 498be83..5fac438 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/util/AdminLogsHandler.js b/util/AdminLogsHandler.js index 35f7e6b..b9142d9 100644 --- a/util/AdminLogsHandler.js +++ b/util/AdminLogsHandler.js @@ -1,12 +1,14 @@ 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 - \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 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}>` }); - - return channel.send({ embeds: [combatLog] }); + const NAME = "DayZ.R Admin Logs"; + const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel); + + let content = { embeds: [combatLog] }; + if (client.exists(guild.adminRole)) content.content = `<@&${guild.adminRole}>`; + WebhookSend(client, webhook, content); + // return channel.send({ embeds: [combatLog] }); } };