From d7d30946663d1731e1aefdc0154fb11dd25c17f3 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 28 Mar 2023 21:37:25 -0700 Subject: [PATCH] debug a whole bunch of stuff --- commands/gamertag-link.js | 11 ++++---- package.json | 2 +- structures/DayzArmbands.js | 56 ++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/commands/gamertag-link.js b/commands/gamertag-link.js index dd53e58..09cc7e8 100644 --- a/commands/gamertag-link.js +++ b/commands/gamertag-link.js @@ -39,17 +39,16 @@ module.exports = { } let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].value ); - if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** This player cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least ` 5 minutes `.')] }); + if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] }); playerStat.discordID = interaction.member.user.id; let playerStatIndex = GuildDB.playerstats.indexOf(playerStat); - let playerstats = GuildDB.playerstats; - playerstats[playerStatIndex] = playerStatIndex; + GuildDB.playerstats[playerStatIndex] = playerStat; - client.dbo.collectin("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, { + client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, { $set: { - 'server.playerstats': playerstats, + 'server.playerstats': GuildDB.playerstats, } }) @@ -59,7 +58,7 @@ module.exports = { let connectedEmbed = new EmbedBuilder() .setColor(client.config.Colors.Default) - .setDescription(`Successfully connected \` ${playerstats.gamertag} \` as your gamertag.`); + .setDescription(`Successfully connected \` ${playerStat.gamertag} \` as your gamertag.`); return interaction.send({ embeds: [connectedEmbed] }) }, diff --git a/package.json b/package.json index 4bb970e..ddeb8b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "5.8.2", + "version": "5.8.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 3cfa5b4..a68d619 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -140,6 +140,8 @@ class DayzArmbands extends Client { distance: data[12] }; + if (!this.exists(info.victim) || !this.exists(info.victimID) || !this.exists(info.killer) || !this.exists(info.killerID)) return; + let killerStat = guild.playerstats.find(stat => stat.playerID == info.killerID) let victimStat = guild.playerstats.find(stat => stat.playerID == info.victimID) let killerStatIndex = guild.playerstats.indexOf(killerStat); @@ -196,7 +198,7 @@ class DayzArmbands extends Client { const newBalance = banking.guilds[guild.serverID].bankAccount.balance + totalBounty; - this.dbo.collection("users").updateOne({ "user.userID": killerStat.discordID }, { + await this.dbo.collection("users").updateOne({ "user.userID": killerStat.discordID }, { $set: { [`banking.guilds.${guild.serverID}.bankAccount.balance`]: newBalance, } @@ -214,7 +216,7 @@ class DayzArmbands extends Client { if (victimStatIndex == -1) guild.playerstats.push(victimStat); else guild.playerstats[victimStatIndex] = victimStat; - this.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, { + await this.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, { $set: { "server.playerstats": guild.playerstats } @@ -232,6 +234,7 @@ class DayzArmbands extends Client { if (this.exists(channel)) channel.send({ embeds: [killEvent] }); if (this.exists(receivedBounty) && this.exists(channel)) channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] }); + return; } async handleAlarms(guildId, data) { @@ -239,7 +242,7 @@ class DayzArmbands extends Client { if (!this.exists(guild.alarms)) { guild.alarms = []; - this.dbo.collection("guilds").updateOne({ 'server.serverID': guildId }, { + await this.dbo.collection("guilds").updateOne({ 'server.serverID': guildId }, { $set: { 'server.alarms': [], } @@ -345,8 +348,9 @@ class DayzArmbands extends Client { const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; const damangeTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP: (.*)\] hit by Player \"(.*)\"\(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; - if (line.includes('connected')) { + if (line.includes(' connected')) { let data = [...line.matchAll(connectTemplate)][0]; + if (!data) return; let info = { time: data[1], @@ -355,6 +359,8 @@ class DayzArmbands extends Client { connected: true, }; + if (!this.exists(info.player) || !this.exists(info.playerID)) return; + let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID) let playerStatIndex = guild.playerstats.indexOf(playerStat); if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); @@ -368,7 +374,7 @@ class DayzArmbands extends Client { if (playerStatIndex == -1) guild.playerstats.push(playerStat); else guild.playerstats[playerStatIndex] = playerStat; - this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { + await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { $set: { "server.playerstats": guild.playerstats } @@ -384,8 +390,9 @@ class DayzArmbands extends Client { }); } - if (line.includes('disconnected')) { + if (line.includes(' disconnected')) { let data = [...line.matchAll(disconnectTemplate)][0]; + if (!data) return; let info = { time: data[1], @@ -394,6 +401,8 @@ class DayzArmbands extends Client { connected: false } + if (!this.exists(info.player) || !this.exists(info.playerID)) return; + let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID) let playerStatIndex = guild.playerstats.indexOf(playerStat); if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); @@ -403,7 +412,7 @@ class DayzArmbands extends Client { if (playerStatIndex == -1) guild.playerstats.push(playerStat); else guild.playerstats[playerStatIndex] = playerStat; - this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { + await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { $set: { "server.playerstats": guild.playerstats } @@ -428,14 +437,17 @@ class DayzArmbands extends Client { if (line.includes('pos=<')) { let data = [...line.matchAll(positionTemplate)][0]; + if (!data) return; let info = { time: data[1], player: data[2], playerID: data[3], - pos: data[4].split(', ').map(v => parseFloat(v)).pop() + pos: data[4].split(', ').map(v => parseFloat(v)) }; + if (!this.exists(info.player) || !this.exists(info.playerID)) return; + let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID) let playerStatIndex = guild.playerstats.indexOf(playerStat); if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); @@ -452,7 +464,7 @@ class DayzArmbands extends Client { if (playerStatIndex == -1) guild.playerstats.push(playerStat); else guild.playerstats[playerStatIndex] = playerStat; - this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { + await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { $set: { "server.playerstats": guild.playerstats } @@ -463,6 +475,7 @@ class DayzArmbands extends Client { if (line.includes('hit by Player')) { let data = [...line.matchAll(damangeTemplate)]; + if (!data) return; let info = { time: data[1], @@ -470,6 +483,8 @@ class DayzArmbands extends Client { playerID: data[3], } + if (!this.exists(info.player) || !this.exists(info.playerID)) return; + let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID) let playerStatIndex = guild.playerstats.indexOf(playerStat); if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); @@ -477,13 +492,13 @@ class DayzArmbands extends Client { let today = new Date(); let newDt = new Date(`${today.toLocaleDateString('default', { month: 'long' })} ${today.getDate()}, ${today.getFullYear()} ${info.time} EST`); - playerStats.lastDamageDate = newDt; - playerStats.lastHitBy = data[6]; + playerStat.lastDamageDate = newDt; + playerStat.lastHitBy = data[6]; if (playerStatIndex == -1) guild.playerstats.push(playerStat); else guild.playerstatus[playerStatIndex] = playerStat; - this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { + await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { $set: { "server.playerstats": guild.playerstats } @@ -491,6 +506,7 @@ class DayzArmbands extends Client { if (err) this.error(err); }); } + return; } async handleActivePlayersList(guildId) { @@ -540,8 +556,8 @@ class DayzArmbands extends Client { for await (const line of rl) { lines.push(line); } for (let i = lines.indexOf(history.lastLog) + 1; i < lines.length; i++) { - if (lines[i].includes('connected') || lines[i].includes('disconnected') || lines[i].includes('pos=<')) this.handlePlayerLogs(guildId, lines[i]); - if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player')) this.handleKillfeed(guildId, lines[i]); + if (lines[i].includes('connected') || lines[i].includes('disconnected') || lines[i].includes('pos=<') || lines[1].includes['hit by Player']) await this.handlePlayerLogs(guildId, lines[i]); + if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player')) await this.handleKillfeed(guildId, lines[i]); } history.lastLog = lines[lines.length-1]; @@ -556,11 +572,12 @@ class DayzArmbands extends Client { await this.downloadFile(`/games/${this.config.Nitrado.UserID}/noftp/dayzxb/config/DayZServer_X1_x64.ADM`, './logs/server-logs.ADM').then(async () => { await this.readLogs('1019008625269801032').then(() => { - if (this.activePlayersTick == 12) this.handleActivePlayersList(guild.id); + if (this.activePlayersTick == 12) this.handleActivePlayersList('1019008625269801032'); }) }); this.logsUpdateTimer(); // restart this function - }, minute * 5); // restart every 5 minutes + // }, minute * 5); // restart every 5 minutes + }, minute / 4); } async connectMongo(mongoURI, dbo) { @@ -698,7 +715,9 @@ class DayzArmbands extends Client { botAdminRoles: [], playerstats: [], alarms: [], - incomeRoles: [] + incomeRoles: [], + linkedGamertagRole: "", + startingBalance: 500, } } @@ -753,6 +772,9 @@ class DayzArmbands extends Client { connectionLogsChannel: guild.server.connectionLogsChannel, welcomeChannel: guild.server.welcomeChannel, activePlayersChannel: guild.server.activePlayersChannel, + linkedGamertagRole: guild.server.linkedGamertagRole, + incomeRoles: guild.server.incomeRoles, + startingBalance: guild.server.startingBalance, }; }