From ab0cd7fe67aec7dfc8e969d432dfc15816fe378e Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 23 Apr 2023 11:46:50 -0700 Subject: [PATCH] debug online list --- commands/player-list.js | 6 +++--- package.json | 2 +- structures/DayzArmbands.js | 44 +++++++++++++++++++++++++++++--------- util/LogsHandler.js | 9 +------- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/commands/player-list.js b/commands/player-list.js index 2cb7f6c..d6196c9 100644 --- a/commands/player-list.js +++ b/commands/player-list.js @@ -20,10 +20,10 @@ module.exports = { * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }, start) => { - - let activePlayers = GuildDB.playerstats.filter(p => p.connected); - let des = ``; + let activePlayers = GuildDB.playerstats.filter(p => p.connected == true); + + let des = activePlayers.length > 0 ? `` : `**No Players Online**`; for (let i = 0; i < activePlayers.length; i++) { des += `**- ${activePlayers[i].gamertag}\n`; } diff --git a/package.json b/package.json index df523d6..cef8272 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.5.3", + "version": "6.5.4", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 865253e..6e2ac37 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -135,21 +135,45 @@ class DayzArmbands extends Client { let s = guild.playerstats; for (let i = logIndex + 1; i < lines.length; i++) { - for (let j = 0; j < s.length; j++) { - if (!s[j].connected) continue; - let inLog = false; - let connected = true; - if (lines[i].includes(s[j].gamertag)) { - inLog = true; - connected = lines[i].includes(' connected') ? true : lines[i].includes('disconnected') ? false : connected; - } - if (!inLog || !connected) s[j].connected = false; - } if (lines[i].includes("Unknown")) continue; if (lines[i].includes('connected') || lines[i].includes('pos=<') || lines[1].includes['hit by Player']) s = await HandlePlayerLogs(this, guildId, s, lines[i]); if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); } + const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; + s.map(p => p.connected = false) // make all connections false + + for (let i = lines.length; i > 0; i--) { + if (lines[i].includes('PlayerList log:')) { + for (let j = i + 1; i < lines.length; j++) { + let line = lines[j]; + if (line.includes('| ####')) break; + + let data = [...line.matchAll(playerTemplate)][0]; + if (!data) continue; + + let info = { + time: data[1], + player: data[2], + playerID: data[3], + }; + + if (!this.exists(info.player) || !this.exists(info.playerID)) continue; + + let playerStat = s.find(stat => stat.playerID == info.playerID) + let playerStatIndex = s.indexOf(playerStat); + if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); + + playerStat.connected = true; + + if (playerStatIndex == -1) s.push(playerStat); + else s[playerStatIndex] = playerStat; + + } + break; + } + } + await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { $set: { "server.playerstats": s diff --git a/util/LogsHandler.js b/util/LogsHandler.js index 57adf3f..fae491a 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -32,7 +32,6 @@ module.exports = { let newDt = await client.getDateEST(info.time); playerStat.lastConnectionDate = newDt; - playerStat.connected = true; if (playerStatIndex == -1) stats.push(playerStat); else stats[playerStatIndex] = playerStat; @@ -59,13 +58,7 @@ module.exports = { if (!client.exists(info.player) || !client.exists(info.playerID)) return stats; let playerStat = stats.find(stat => stat.playerID == info.playerID) - let playerStatIndex = stats.indexOf(playerStat); if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID); - - playerStat.connected = false; - - if (playerStatIndex == -1) stats.push(playerStat); - else stats[playerStatIndex] = playerStat; SendConnectionLogs(client, guildId, { time: info.time, @@ -155,7 +148,7 @@ module.exports = { const channel = client.channels.cache.get(guild.activePlayersChannel); - let activePlayers = guild.playerstats.filter(p => p.connected); + let activePlayers = guild.playerstats.filter(p => p.connected == true); if (activePlayers.length == 0) return;