diff --git a/commands/config.js b/commands/config.js index c64ea97..cac3ea5 100644 --- a/commands/config.js +++ b/commands/config.js @@ -319,7 +319,7 @@ module.exports = { }] }, { 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)", + description: "Adjust log timeout for combat prevention. (0 disables combat log)", value: "combat-log-timer", type: CommandOptions.SubCommand, options: [{ diff --git a/commands/stats.js b/commands/stats.js index 39559e3..61e5614 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -30,7 +30,7 @@ module.exports = { { name: 'Latency', value: `${end - start}ms`, inline: true }, { name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, inline: true }, { name: 'Bot Version', value: `${client.config.Dev} v${client.config.Version}`, inline: true }, - { name: 'Discord Version', value: 'Discord.js ^14.8.0', inline: true }, + { name: 'Discord Version', value: 'Discord.js v14.8.0', inline: true }, ) return interaction.send({ embeds: [stats] }) diff --git a/package.json b/package.json index 5fe1412..208b697 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "9.9.6", + "version": "9.9.7", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index 28d200a..8819802 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -1,5 +1,6 @@ const { RegisterGlobalCommands, RegisterGuildCommands } = require("../util/RegisterSlashCommands"); const { Collection, Client, EmbedBuilder, Routes } = require('discord.js'); +const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; const MongoClient = require('mongodb').MongoClient; const { REST } = require('@discordjs/rest'); const Logger = require("../util/Logger"); @@ -155,7 +156,6 @@ class DayzRBot extends Client { const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; const playerSessions = new Map(); let previouslyConnected = s.filter(p => p.connected); // All players with connection log captured above and no disconnect log - let detectedAsConnected = []; let lastDetectedTime; for (let i = lines.length - 1; i > 0; i--) { @@ -173,38 +173,37 @@ class DayzRBot extends Client { playerID: data[3], }; - lastDetectedTime = info.time; + lastDetectedTime = await this.getDateEST(info.time); - if (!this.exists(info.player) || !this.exists(info.playerID)) continue; + if (!this.exists(info.player) || !this.exists(info.playerID)) continue; // Skip this player if the player does not exist. + let playerStat = s.find(stat => stat.playerID == info.playerID); + if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry. // Check if the player session exists in the map. if (playerSessions.has(info.playerID)) { // Player is already in a session, update the session's end time. const session = playerSessions.get(info.playerID); - session.endTime = await this.getDateEST(info.time); // Update end time. + session.endTime = lastDetectedTime; // Update end time. } else { // Player is not in a session, create a new session. const newSession = { - startTime: await this.getDateEST(info.time), + startTime: lastDetectedTime, endTime: null, // Initialize end time as null. }; playerSessions.set(info.playerID, newSession); } - let playerStat = s.find(stat => stat.playerID == info.playerID); let playerStatIndex = s.indexOf(playerStat); if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); if (!previouslyConnected.includes(playerStat)) { // Check if the player has been marked as connected before. playerStat.connected = true; - playerStat.lastConnectionDate = await this.getDateEST(info.time); // Update last connection date. - detectedAsConnected.push(playerStat); + playerStat.lastConnectionDate = lastDetectedTime; // Update last connection date. } if (playerStatIndex == -1) s.push(playerStat); else s[playerStatIndex] = playerStat; - detectedAsConnected.push(playerStat); } break; } @@ -433,6 +432,7 @@ class DayzRBot extends Client { time: null, lastTime: null, lastConnectionDate: null, + lastDisconnectionDate: null, lastDamageDate: null, lastDeathDate: null, lastHitBy: null, diff --git a/util/LogsHandler.js b/util/LogsHandler.js index 61d6a4a..f8ab138 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -74,6 +74,7 @@ module.exports = { playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds; playerStat.lastSessionTime = sessionTimeSeconds; playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime; + playerStat.lastDisconnectionDate = newDt; playerStat.connected = false; if (playerStatIndex === -1) stats.push(playerStat);