From 24aa3726d1c6ca566cf2ecc96e2ca008eb771529 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 26 Nov 2023 21:17:40 +0100 Subject: [PATCH] Fixed same bug found in checkstats button --- src/commands/check.js | 1 - src/events/buttons/checkstats.js | 180 ++++++++++++++++--------------- 2 files changed, 95 insertions(+), 86 deletions(-) diff --git a/src/commands/check.js b/src/commands/check.js index cfe8fc9..64abc12 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -7,7 +7,6 @@ module.exports = { name: "check", description: "Check a player's stats.", type: "slash", - dev: true, data: new SlashCommandBuilder() .setName("check") diff --git a/src/events/buttons/checkstats.js b/src/events/buttons/checkstats.js index a4fa023..1309a77 100644 --- a/src/events/buttons/checkstats.js +++ b/src/events/buttons/checkstats.js @@ -67,58 +67,103 @@ module.exports = { guildTag = " [" + guild.tag + "]" } - //bedwars level - const hsbwexp = player.stats.Bedwars.Experience - const hsbwstars = bedwarsLevel(hsbwexp) - // bedwars fkdr - const hsbwfk = player.stats.Bedwars.final_kills_bedwars - const hsbwfd = player.stats.Bedwars.final_deaths_bedwars - const hsbwfkdr = hsbwfk / hsbwfd - // bedwars wins - const hsbwwins = player.stats.Bedwars.wins_bedwars - // skywars level - const hsswexp = player.stats.SkyWars.skywars_experience - const hsswstars = skywarsLevel(hsswexp) - // skywars kdr - const hsswkills = player.stats.SkyWars.kills - const hsswdeaths = player.stats.SkyWars.deaths - const hsswkd = hsswkills / hsswdeaths - //skywars wins - const hsswwins = player.stats.SkyWars.wins - // dueks kdr - const hsduelskills = player.stats.Duels.kills - const hsduelsdeaths = player.stats.Duels.deaths - const hsduelskd = hsduelskills / hsduelsdeaths - // duels wins - const hsduelswins = player.stats.Duels.wins - // duels wlr - const hsduelslosses = player.stats.Duels.losses - const hsduelswlr = hsduelswins / hsduelslosses + const statsFields = [] + if (!player.stats) { + statsFields.push({ + name: " This player never played any games.", + value: "**➺ Stats:** `None`" + }) + } else { + if (player.stats.Bedwars) { + const hsbwexp = player.stats?.Bedwars?.Experience || 0 + const hsbwstars = bedwarsLevel(hsbwexp) + const hsbwfk = player.stats?.Bedwars?.final_kills_bedwars || 0 + const hsbwfd = player.stats?.Bedwars?.final_deaths_bedwars || 0 + const hsbwfkdr = hsbwfk / hsbwfd || 0 + const hsbwwins = player.stats?.Bedwars?.wins_bedwars || 0 + + let bwtitle = "" + if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { + bwtitle = " This player does not meet the BedWars requirements." + } else { + bwtitle = " This player meets the BedWars requirements." + } + + statsFields.push({ + name: bwtitle, + value: "**➺ Stars:** `" + + hsbwstars.toFixed(2).toString() + " / " + + bwstars.toString() + "`\n" + + "**➺ FKDR:** `" + + hsbwfkdr.toFixed(2).toString() + + " / " + bwfkdr.toString() + "`\n" + + "**➺ Wins:** `" + + hsbwwins.toString() + " / " + + bwwins.toString() + "`" + }) + } + + if (player.stats.SkyWars) { + const hsswexp = player.stats.SkyWars.skywars_experience + const hsswstars = skywarsLevel(hsswexp) + const hsswkills = player.stats.SkyWars.kills + const hsswdeaths = player.stats.SkyWars.deaths + const hsswkd = hsswkills / hsswdeaths + const hsswwins = player.stats.SkyWars.wins + + let swtitle = "" + if (hsswstars < swstars) { + swtitle = " This player does not meet the SkyWars requirements." + } else { + swtitle = " This player meets the SkyWars requirements." + } + + statsFields.push({ + name: swtitle, + value: + "**➺ Stars:** `" + + hsswstars.toFixed(2).toString() + + " / " + swstars.toString() + "`\n" + + "**➺ KDR:** `" + + hsswkd.toFixed(2).toString() + "`\n" + + "**➺ Wins:** `" + + hsswwins.toString() + "`" + }) + } + + if (player.stats.Duels) { + const hsduelskills = player.stats.Duels.kills + const hsduelsdeaths = player.stats.Duels.deaths + const hsduelskd = hsduelskills / hsduelsdeaths + const hsduelswins = player.stats.Duels.wins + const hsduelslosses = player.stats.Duels.losses + const hsduelswlr = hsduelswins / hsduelslosses + + let duelstitle = "" + if (hsduelswins < duelswins || hsduelswlr < duelswlr) { + duelstitle = " This player does not meet the Duels requirements." + } else { + duelstitle = " This player meets the Duels requirements." + } + + statsFields.push({ + name: duelstitle, + value: "**➺ Wins:** `" + + hsduelswins.toString() + + " / " + duelswins.toString() + "`\n" + + "**➺ WLR:** `" + + hsduelswlr.toFixed(2).toString() + + " / " + duelswlr.toString() + "`\n" + + "**➺ KDR:** `" + + hsduelskd.toFixed(2).toString() + "`" + }) + } + } + // network level - const hypixelExp = player.networkExp + const hypixelExp = player.networkExp || 0 const level = hypixelLevel(hypixelExp) - let bwtitle = "" - let swtitle = "" - let duelstitle = "" - if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { - bwtitle = " This player does not meet the BedWars requirements." - } else { - bwtitle = " This player meets the BedWars requirements." - } - - if (hsswstars < swstars) { - swtitle = " This player does not meet the SkyWars requirements." - } else { - swtitle = " This player meets the SkyWars requirements." - } - - if (hsduelswins < duelswins || hsduelswlr < duelswlr) { - duelstitle = " This player does not meet the Duels requirements." - } else { - duelstitle = " This player meets the Duels requirements." - } - await interaction.editReply({ embeds: [{ title: rank + player.displayname + guildTag, @@ -131,42 +176,7 @@ module.exports = { text: interaction.guild.name + " | Developed by @Taken#0002", icon_url: interaction.guild.iconURL() }, - fields: [ - { - name: bwtitle, - value: "**➺ Stars:** `" + - hsbwstars.toFixed(2).toString() + " / " + - bwstars.toString() + "`\n" + - "**➺ FKDR:** `" + - hsbwfkdr.toFixed(2).toString() + - " / " + bwfkdr.toString() + "`\n" + - "**➺ Wins:** `" + - hsbwwins.toString() + " / " + - bwwins.toString() + "`" - }, - { - name: swtitle, - value: - "**➺ Stars:** `" + - hsswstars.toFixed(2).toString() + - " / " + swstars.toString() + "`\n" + - "**➺ KDR:** `" + - hsswkd.toFixed(2).toString() + "`\n" + - "**➺ Wins:** `" + - hsswwins.toString() + "`" - }, - { - name: duelstitle, - value: "**➺ Wins:** `" + - hsduelswins.toString() + - " / " + duelswins.toString() + "`\n" + - "**➺ WLR:** `" + - hsduelswlr.toFixed(2).toString() + - " / " + duelswlr.toString() + "`\n" + - "**➺ KDR:** `" + - hsduelskd.toFixed(2).toString() + "`" - } - ] + fields: statsFields }] }) }