From afdec2395c580414978fb5aa56c59619b16ae6bc Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 10 Sep 2023 00:52:48 -0700 Subject: [PATCH] configure combat log timer/refactor boolean configuration --- commands/admin.js | 12 ------------ commands/config.js | 25 ++++++++++++++++++++++++- structures/DayzRBot.js | 4 +++- util/LogsHandler.js | 20 +++++++++++--------- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/commands/admin.js b/commands/admin.js index 1c875f0..fd88dae 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -148,18 +148,6 @@ module.exports = { description: "Enable/Disable periodic server checks and restart if stopped.", value: "auto-restart", type: CommandOptions.SubCommand, - }, { - name: "combat-log-timer", - description: "Set the number of minutes to elapse for a player to not combat log. (Set to 0 to disbable combat logging detection)", - value: "combat-log-timer", - type: CommandOptions.SubCommand, - options: [{ - name: "minutes", - description: "Minutes to qualify combat log", - value: 5, - type: CommandOptions.Integer, // Integer - - }] }], SlashCommand: { /** diff --git a/commands/config.js b/commands/config.js index bf6c15d..c64ea97 100644 --- a/commands/config.js +++ b/commands/config.js @@ -317,6 +317,18 @@ module.exports = { type: CommandOptions.Boolean, required: true, }] + }, { + name: "combat-log-timer", + description: "Set the number of minutes to elapse for a player to not combat log. (Set to 0 to disbable combat logging detection)", + value: "combat-log-timer", + type: CommandOptions.SubCommand, + options: [{ + name: "minutes", + description: "Minutes to qualify combat log", + value: 5, + type: CommandOptions.Integer, + min_value: 0, + }] } ], SlashCommand: { @@ -522,7 +534,7 @@ module.exports = { return interaction.send({ embeds: [successSetKillfeedChannelEmbed] }); case 'show_killfeed_coords': - const showKillfeedCoordsConfiguration = args[0].options[0].value; + const showKillfeedCoordsConfiguration = args[0].options[0].value ? 1 : 0; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedCoords": showKillfeedCoordsConfiguration}}, (err, res) => { if (err) return client.sendInternalError(interaction, err); @@ -715,6 +727,17 @@ module.exports = { return interaction.send({ embeds: [successEMPPriceEmbed] }); + case 'combat-log-timer': + client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.combatLogTimer":args[0].options[0].value}}, (err, res) => { + if (err) return client.sendInternalError(interaction, err); + }); + + let successCobatLogTimerEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`Successfully set combat log timer to **${args[0].options[0].value.toFixed(0)} minutes.**`); + + return interaction.send({ embeds: [successCobatLogTimerEmbed] }); + default: return client.sendInternalError(interaction, 'There was an error parsing the config command'); } diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index ee57960..28d200a 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -145,7 +145,7 @@ class DayzRBot extends Client { if (lines[i].includes('| ####')) continue; if (lines[i].includes("(id=Unknown") || lines[i].includes("Player \"Unknown Entity\"")) continue; if ((i - 1) >= 0 && lines[i] == lines[i - 1]) continue; // continue if this line is a duplicate of the last line - if (lines[i].includes('connected') || lines[i].includes('pos=<') || lines[i].includes('hit by Player')) s = await HandlePlayerLogs(this, guildId, s, lines[i]); + if (lines[i].includes('connected') || lines[i].includes('pos=<')) s = await HandlePlayerLogs(this, guildId, s, lines[i], guild.combatLogTimer); if (lines[i].includes('killed by with') || lines[i].includes('killed by LandMineTrap')) s = await HandleKillfeed(this, guildId, s, lines[i]); // Handles explosive deaths if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by') && lines[i].includes('TransportHit')) s = await HandleKillfeed(this, guildId, s, lines[i]) // Handles vehicle deaths if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player') && lines[i].includes('hit by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); // Handles regular deaths @@ -411,6 +411,7 @@ class DayzRBot extends Client { empPrice: 500000, memberRole: "", adminRole: "", + combatLogTimer: 5, // minutes } } @@ -484,6 +485,7 @@ class DayzRBot extends Client { uavPrice: guild.server.uavPrice, memberRole: guild.server.memberRole, adminRole: guild.server.adminRole, + combatLogTimer: guild.server.combatLogTimer, }; } diff --git a/util/LogsHandler.js b/util/LogsHandler.js index 428c84d..61d6a4a 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -9,7 +9,7 @@ let lastSendMessage; module.exports = { - HandlePlayerLogs: async (client, guildId, stats, line) => { + HandlePlayerLogs: async (client, guildId, stats, line, combatLogTimer = 5) => { const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g; const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g; @@ -86,14 +86,16 @@ module.exports = { lastConnectionDate: playerStat.lastConnectionDate, }); - DetectCombatLog(client, guildId, { - time: info.time, - player: info.player, - pos: playerStat.pos, - lastDamageDate: playerStat.lastDamageDate, - lastHitBy: playerStat.lastHitBy, - lastDeathDate: playerStat.lastDeathDate, - }); + if (combatLogTimer != 0) { + DetectCombatLog(client, guildId, { + time: info.time, + player: info.player, + pos: playerStat.pos, + lastDamageDate: playerStat.lastDamageDate, + lastHitBy: playerStat.lastHitBy, + lastDeathDate: playerStat.lastDeathDate, + }); + } } if (line.includes('pos=<') && !line.includes('hit by')) {