From d460eff8cc9c178aec4afbebbe3a35025fabe621 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Sun, 6 Oct 2024 16:39:15 +0100 Subject: [PATCH] val stats: fix naming scheme for maps, roles and weapons after changing the api endpoint --- commands/stats/valorant.js | 66 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/commands/stats/valorant.js b/commands/stats/valorant.js index bed530e..b268631 100644 --- a/commands/stats/valorant.js +++ b/commands/stats/valorant.js @@ -139,14 +139,22 @@ module.exports = { .setDescription(`${data.username}'s top weapons stats:`); data.top_weapons.forEach((weapon) => { - weaponsEmbed.addFields({ - name: weapon.name, - value: - `Type: ${weapon.weapon_type}\n` + - `Kills: ${weapon.kills}\n` + - `Accuracy: ${weapon.accuracy.join(", ")}\n`, - inline: true, - }); + if (weapon.weapon_name) { + weaponsEmbed.addFields({ + name: weapon.weapon_name, + value: + `Type: ${weapon.weapon_type}\n` + + `Kills: ${weapon.weapon_kills}\n` + + `Accuracy: ${ + Array.isArray(weapon.weapon_accuracy) + ? weapon.weapon_accuracy.join(", ") + : "N/A" + }\n`, + inline: true, + }); + } else { + console.warn("Weapon name is undefined:", weapon); + } }); embeds.push(weaponsEmbed); @@ -160,11 +168,15 @@ module.exports = { .setDescription(`${data.username}'s top maps stats:`); data.top_maps.forEach((map) => { - mapsEmbed.addFields({ - name: map.name, - value: `Win Percentage: ${map.win_percentage}%\nMatches: ${map.matches}`, - inline: true, - }); + if (map.map_name) { + mapsEmbed.addFields({ + name: map.map_name, + value: `Win Percentage: ${map.map_win_percentage}%\nMatches: ${map.map_matches}`, + inline: true, + }); + } else { + console.warn("Map name is undefined:", map); + } }); embeds.push(mapsEmbed); @@ -178,18 +190,22 @@ module.exports = { .setDescription(`${data.username}'s performance by role:`); data.roles.forEach((role) => { - rolesEmbed.addFields({ - name: role.name, - value: - `Win Rate: ${role.win_rate}%\n` + - `KDA: ${role.kda}\n` + - `Wins: ${role.wins}\n` + - `Losses: ${role.losses}\n` + - `Kills: ${role.kills}\n` + - `Deaths: ${role.deaths}\n` + - `Assists: ${role.assists}`, - inline: true, - }); + if (role.role_name) { + rolesEmbed.addFields({ + name: role.role_name, + value: + `Win Rate: ${role.role_win_rate}%\n` + + `KDA: ${role.role_kda}\n` + + `Wins: ${role.role_wins}\n` + + `Losses: ${role.role_losses}\n` + + `Kills: ${role.role_kills}\n` + + `Deaths: ${role.role_deaths}\n` + + `Assists: ${role.role_assists}`, + inline: true, + }); + } else { + console.warn("Role name is undefined:", role); + } }); embeds.push(rolesEmbed);