From ab725c7f86eef8a51e6b84a205653f12d1ae7d0a Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 25 Apr 2023 23:21:21 +0000 Subject: [PATCH] feat: unnecessary code in /tanks --- src/commands/{ownedTanks.ts => tanks.ts} | 52 ++++++------------------ 1 file changed, 13 insertions(+), 39 deletions(-) rename src/commands/{ownedTanks.ts => tanks.ts} (63%) diff --git a/src/commands/ownedTanks.ts b/src/commands/tanks.ts similarity index 63% rename from src/commands/ownedTanks.ts rename to src/commands/tanks.ts index e56096e6e..9bf7d5740 100644 --- a/src/commands/ownedTanks.ts +++ b/src/commands/tanks.ts @@ -16,9 +16,7 @@ export async function execute( ) { const server = interaction.options.getString('server') as BlitzServer; const ign = interaction.options.getString('ign')!; - let tier = interaction.options.getNumber('tier'); - - tier = tier === null ? null : Math.round(tier); + const tier = Math.round(interaction.options.getNumber('tier')!); getBlitzAccount(interaction, ign, server, async (account) => { const tankStats = (await ( @@ -29,25 +27,7 @@ export async function execute( const tanks = tankStats.data[account.account_id]!.map( (tankData) => tankopedia.data[tankData.tank_id], - ); - const tierSortedTanks: Record = {}; - const tiers: number[] = []; - - for (const tank of tanks) { - if (!tierSortedTanks[tank.tier]) { - tierSortedTanks[tank.tier] = [tank]; - } else { - tierSortedTanks[tank.tier].push(tank); - } - - if (tier === null && !tiers.includes(tank.tier)) tiers.push(tank.tier); - } - - if (tier === null) { - tiers.sort((a, b) => b - a); - } else { - tiers.push(tier); - } + ).filter((tank) => tank.tier === tier); interaction.reply({ embeds: [ @@ -58,22 +38,16 @@ export async function execute( }tanks`, ) .setDescription( - tiers - .map((iterationTier) => { - return `${tier === null ? `**Tier ${iterationTier}**:\n` : ''}${ - tierSortedTanks[iterationTier] === undefined - ? `No tanks found for player in tier ${tier}` - : tierSortedTanks[iterationTier] - .map( - (tank) => - `${tankTypeEmojis[tank.type]} ${tank.name} ${ - tank.is_premium ? '⭐' : '' - }`, - ) - .join('\n') - }`; - }) - .join('\n\n'), + tanks.length === 0 + ? `No tanks found for player in tier ${tier}` + : tanks + .map( + (tank) => + `${tankTypeEmojis[tank.type]} ${tank.name} ${ + tank.is_premium ? '⭐' : '' + }`, + ) + .join('\n'), ) .setColor(SKILLED_COLOR), ], @@ -82,7 +56,7 @@ export async function execute( } export const data = new SlashCommandBuilder() - .setName('ownedtanks') + .setName('tanks') .setDescription("Shows a player's owned tanks") .addStringOption((option) => option