From 287b64151bb80dd31b0a3a04e3061409a90b7487 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Mon, 7 Oct 2024 09:24:11 +0100 Subject: [PATCH] cs: update the commanad with new api data --- commands/stats/cs2.js | 106 ++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/commands/stats/cs2.js b/commands/stats/cs2.js index 457b881..d74ecb4 100644 --- a/commands/stats/cs2.js +++ b/commands/stats/cs2.js @@ -10,26 +10,15 @@ module.exports = { .setName("steam_id") .setDescription("The Steam ID to fetch stats for.") .setRequired(true) - ) - .addStringOption((option) => - option - .setName("stats_type") - .setDescription("The type of stats to fetch (premier or competitive).") - .setRequired(true) - .addChoices( - { name: "Premier", value: "premier" }, - { name: "Competitive", value: "competitive" } - ) ), async execute(interaction) { const steamId = interaction.options.getString("steam_id"); - const statsType = interaction.options.getString("stats_type"); const apiUrl = process.env.TRACKER_API_URL; const apiKey = process.env.TRACKER_API_KEY; - const url = `https://${apiUrl}/cs2/player/${steamId}/${statsType}`; + const url = `https://${apiUrl}/cs2/player/${steamId}`; try { await interaction.deferReply(); @@ -44,60 +33,85 @@ module.exports = { const statsEmbed = new EmbedBuilder() .setColor("#ff4500") - .setTitle(`CS2 Stats for Steam ID: ${data.steam_id} (${statsType})`); - - const rankField = { - name: - statsType === "competitive" - ? "🏆 Highest Rank (All maps)" - : "🏆 Current Rank", - value: data.current_rank, - }; + .setTitle(`CS2 Stats for Steam ID: ${data.steam_id}`); const fields = [ - { name: "🎮 Steam Name", value: data.player_name }, - rankField, + { name: "🎮 Steam Name", value: data.player_name || "N/A" }, + { name: "⏳ Hours Played", value: `${data.hours_played}h` }, + { name: "🎮 Kills", value: `${data.kills}` }, + { name: "📈 K/D Ratio", value: `${data.kd_ratio}` }, + { name: "🏅 Total Deaths", value: `${data.total_deaths}` }, + { name: "🏅 Wins", value: `${data.total_wins}` }, + { name: "⚔️ Total Damage Done", value: `${data.total_damage_done}` }, + { name: "💰 Total Money Earned", value: `${data.total_money_earned}` }, + { name: "🏆 Total MVPs", value: `${data.total_mvps}` }, + ]; + + // Adding additional fields dynamically + const additionalFields = [ { - name: "⏳ Hours Played", - value: `${data.hours_played}h`, + name: "Total Planted Bombs", + value: `${data.total_planted_bombs}`, + inline: true, }, { - name: "🎮 Matches Played", - value: `${data.matches_played}`, + name: "Total Defused Bombs", + value: `${data.total_defused_bombs}`, + inline: true, }, { - name: "🏅 Wins", - value: `${data.wins}`, + name: "Total Weapons Donated", + value: `${data.total_weapons_donated}`, + inline: true, }, { - name: "📊 Win Percentage", - value: `${data.win_percentage}%`, + name: "Total Rounds Played", + value: `${data.total_rounds_played}`, + inline: true, }, { - name: "⚔️ Kills", - value: `${data.kills}`, + name: "Total Domination Overkills", + value: `${data.total_domination_overkills}`, + inline: true, }, { - name: "📈 K/D Ratio", - value: `${data.kd_ratio}`, + name: "Total Revenges", + value: `${data.total_revenges}`, + inline: true, }, { - name: "🎯 Headshot Percentage", - value: `${data.headshot_percentage}%`, + name: "Total Kills (AWP)", + value: `${data.total_kills_awp}`, + inline: true, }, { - name: "💯 Tracker Score", - value: `${data.tracker_score}/1000`, + name: "Total Kills (AK47)", + value: `${data.total_kills_ak47}`, + inline: true, + }, + { + name: "Total Kills (Headshot)", + value: `${data.total_kills_headshot}`, + inline: true, + }, + { + name: "Total Wins (Pistol Round)", + value: `${data.total_wins_pistolround}`, + inline: true, + }, + { + name: "Total Rounds (Dust2)", + value: `${data.total_rounds_map_de_dust2}`, + inline: true, }, ]; - // Only add Peak Rank if statsType is not "competitive" - if (statsType !== "competitive") { - fields.splice(1, 0, { - name: "🔝 Peak Rank", - value: data.peak_rank || "N/A", - }); - } + // Add each additional field if it exists and its value is greater than 0 + additionalFields.forEach((field) => { + if (field.value > 0) { + fields.push(field); + } + }); statsEmbed.addFields(fields).setTimestamp().setFooter({ text: "CS2 Stats API made by Ayden",