From dd983cf9f23058b5a3e159829fa91cde6819835f Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Sun, 17 Nov 2024 12:20:23 -0800 Subject: [PATCH] fix/convert killfeed to webhooks --- package.json | 2 +- util/KillfeedHandler.js | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e533bf6..d89ec03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "13.3.18", + "version": "13.3.19", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index 0250e1d..3528198 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -5,6 +5,7 @@ const { nearest } = require('../database/destinations'); const { getDefaultPlayer, UpdatePlayer } = require('../database/player'); const { calculateNewCombatRating } = require('./CombatRatingHandler'); const { weapons, weaponClassOf } = require('../database/weapons'); +const { GetWebhook, WebhookSend } = require("../util/WebhookHandler"); const Templates = { Killed: 1, @@ -79,9 +80,10 @@ module.exports = { }, HandleKillfeed: async (NitradoServerID, client, guild, line) => { - + + const NAME = "DayZ.R Killfeed"; const channel = client.GetChannel(guild.killfeedChannel); - + const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead : line.includes('hit by Player') && !line.includes('meters') ? Templates.Melee : // Missing meters indicates it was a melee attack. line.includes('hit by Player') ? Templates.HitBy : @@ -131,6 +133,7 @@ module.exports = { if ([Templates.LandMine, Templates.Explosion, Templates.Vehicle].includes(killedBy)) if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) { + if (!channel) return; let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID}); if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, NitradoServerID); victimStat.lastDeathDate = newDt; @@ -144,9 +147,13 @@ module.exports = { .setColor(client.config.Colors.Default) .setDescription(`**Death Event** - \n**${info.victim}** ${killMessage} a **${cod}.**${coord}`); - if (client.exists(channel)) await channel.send({ embeds: [killEvent] }); + const webhook = await GetWebhook(this, NAME, guild.killfeedChannel); + + WebhookSend(client, webhook, { embeds: [killEvent]}); + + // if (client.exists(channel)) await channel.send({ embeds: [killEvent] }); await UpdatePlayer(client, victimStat); - return + return; } KillInAlarm(client, guild.serverID, info); // check if kill happened in a no kill zone @@ -262,9 +269,16 @@ module.exports = { let weaponClass = weaponClassOf(weapon); killEvent.setThumbnail(weapons[weaponClass][weapon]) } + + if (!channel) return; - if (client.exists(channel)) await channel.send({ embeds: [killEvent] }); - if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] }); + const webhook = await GetWebhook(this, NAME, guild.killfeedChannel); + + WebhookSend(client, webhook, { embeds: [killEvent] }); + if (client.exists(receivedBounty) && client.exists(channel)) WebhookSend(client, webhook, { content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] }); + + // if (client.exists(channel)) await channel.send({ embeds: [killEvent] }); + // if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] }); return; }