From 9d0e46814224afc61f24bc4c87986dd13de40a30 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sat, 15 Apr 2023 21:42:42 -0700 Subject: [PATCH] enhance / debug combat log detection --- package.json | 2 +- structures/DayzArmbands.js | 1 + util/AdminLogsHandler.js | 7 ++++--- util/KillfeedHandler.js | 9 +++++---- util/LogsHandler.js | 1 + 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fa1f384..efc5898 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.3.14", + "version": "6.3.15", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 851d2bb..64dafb2 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -345,6 +345,7 @@ class DayzArmbands extends Client { lastTime: null, lastConnectionDate: null, lastDamageDate: null, + lastDeathDate: null, lastHitBy: null, connected: false, bounties: [], diff --git a/util/AdminLogsHandler.js b/util/AdminLogsHandler.js index 7d36418..9a78ca7 100644 --- a/util/AdminLogsHandler.js +++ b/util/AdminLogsHandler.js @@ -31,10 +31,11 @@ module.exports = { let newDt = await client.getDateEST(data.time); - let diffMs = (newDt - data.lastDamageDate) - let diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes + let diff = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000 / 60); // diff minutes - if (diffMins > 5) return; + // If diff is greater than 5 minutes, not a combat log + // or if death after last combat and death was before logout event + if (diffMins > 5 || (data.lastDamageDate < data.lastDeathDate && data.lastDeathDate < newDt)) return; let guild = await client.GetGuild(guildId); if (!client.exists(guild.connectionLogsChannel)) return; diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index 7f5e564..9da64a8 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -28,6 +28,9 @@ module.exports = { distance: data[12] }; + let newDt = await client.getDateEST(info.time); + let unixTime = Math.floor(newDt.getTime()/1000); + KillInAlarm(client, guildId, info); // check if kill happened in a no kill zone if (!client.exists(info.victim) || !client.exists(info.victimID) || !client.exists(info.killer) || !client.exists(info.killerID)) return stats; @@ -49,8 +52,9 @@ module.exports = { killerStat.KDR = killerStat.kills / (killerStat.deaths == 0 ? 1 : killerStat.deaths); // prevent division by 0 victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0 victimStat.killStreak = 0; + victimStat.lastDeathDate = newDt; killerStat.deathStreak = 0; - + let receivedBounty = null; if (victimStat.bounties.length > 0 && killerStat.discordID != "") { let totalBounty = 0; @@ -107,9 +111,6 @@ module.exports = { if (victimStatIndex == -1) stats.push(victimStat); else stats[victimStatIndex] = victimStat; - let newDt = await client.getDateEST(info.time); - let unixTime = Math.floor(newDt.getTime()/1000); - const killEvent = new EmbedBuilder() .setColor(client.config.Colors.Default) .setDescription(`**Kill Event** - \n**${info.killer}** killed **${info.victim}**\n> **__Kill Data__**\n> **Weapon:** \` ${info.weapon} \`\n> **Distance:** \` ${info.distance} \`\n> **Body Part:** \` ${info.bodyPart.split('(')[0]} \`\n> **Damage:** \` ${info.damage} \`\n **Killer\n${killerStat.KDR.toFixed(2)} K/D - ${killerStat.kills} Kills - Killstreak: ${killerStat.killStreak}\nVictim\n${victimStat.KDR.toFixed(2)} K/D - ${victimStat.deaths} Deaths - Deathstreak: ${victimStat.deathStreak}**`); diff --git a/util/LogsHandler.js b/util/LogsHandler.js index 8d82e44..da1b983 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -79,6 +79,7 @@ module.exports = { player: info.player, lastDamageDate: playerStat.lastDamageDate, lastHitBy: playerStat.lastHitBy, + lastDeathDate: playerStat.lastDeathDate, }); }