val stats: make weapn, maps and roles optional

This commit is contained in:
Ayden Jahola 2024-10-06 00:25:11 +01:00
parent c9a411779f
commit 455ae98287
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -22,10 +22,31 @@ module.exports = {
{ name: "All Acts Stats", value: "all" }
)
.setRequired(true)
)
.addBooleanOption((option) =>
option
.setName("include_weapons")
.setDescription("Include top weapons stats?")
.setRequired(false)
)
.addBooleanOption((option) =>
option
.setName("include_maps")
.setDescription("Include top maps stats?")
.setRequired(false)
)
.addBooleanOption((option) =>
option
.setName("include_roles")
.setDescription("Include roles stats?")
.setRequired(false)
),
async execute(interaction) {
const username = interaction.options.getString("username");
const statsType = interaction.options.getString("stats_type");
const includeWeapons = interaction.options.getBoolean("include_weapons");
const includeMaps = interaction.options.getBoolean("include_maps");
const includeRoles = interaction.options.getBoolean("include_roles");
// Convert the username by replacing "#" with "%23"
const formattedUsername = username.replace("#", "%23");
@ -55,37 +76,37 @@ module.exports = {
.addFields(
{
name: "🏆 Current Rank",
value: data.current_rank || "N/A",
value: data.current_rank,
},
{
name: "🔝 Peak Rank",
value: `${data.peak_rank || "N/A"}`,
value: `${data.peak_rank} (${data.peak_rank_episode})`,
},
{
name: "⏳ Hours Played",
value: `${data.playtime_hours || 0}h`,
value: `${data.playtime_hours}h`,
},
{
name: "🎮 Matches Played",
value: `${data.matches_played || 0}`,
value: `${data.matches_played}`,
},
{ name: "🏅 Wins", value: `${data.wins || 0}` },
{ name: "🏅 Wins", value: `${data.wins}` },
{
name: "📊 Win Percentage",
value: `${data.win_percentage || 0}%`,
value: `${data.win_percentage}%`,
},
{ name: "⚔️ Kills", value: `${data.kills || 0}` },
{ name: "⚔️ Kills", value: `${data.kills}` },
{
name: "📈 K/D Ratio",
value: `${data.kd_ratio || 0}`,
value: `${data.kd_ratio}`,
},
{
name: "📊 ACS",
value: `${data.acs || 0}`,
value: `${data.acs}`,
},
{
name: "🎯 Headshot Percentage",
value: `${data.headshot_percentage || 0}%`,
value: `${data.headshot_percentage}%`,
}
);
@ -93,10 +114,14 @@ module.exports = {
if (statsType === "current") {
statsEmbed.addFields({
name: "💯 Tracker Score",
value: `${data.tracker_score || "N/A"}/1000`,
value: `${data.tracker_score}/1000`,
});
}
const embeds = [statsEmbed];
// Optional weapons embed
if (includeWeapons) {
const weaponsEmbed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle(`${data.username}'s Top Weapons`)
@ -113,6 +138,11 @@ module.exports = {
});
});
embeds.push(weaponsEmbed);
}
// Optional maps embed
if (includeMaps) {
const mapsEmbed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle(`${data.username}'s Top Maps`)
@ -126,6 +156,11 @@ module.exports = {
});
});
embeds.push(mapsEmbed);
}
// Optional roles embed
if (includeRoles) {
const rolesEmbed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle(`${data.username}'s Roles`)
@ -146,14 +181,15 @@ module.exports = {
});
});
embeds.push(rolesEmbed);
}
statsEmbed.setTimestamp().setFooter({
text: "Valorant Stats API made by Ayden",
iconURL: interaction.guild.iconURL(),
});
return interaction.editReply({
embeds: [statsEmbed, weaponsEmbed, mapsEmbed, rolesEmbed],
});
return interaction.editReply({ embeds });
} catch (error) {
console.error("Error fetching player stats:", error);
if (error.response) {