From d62ca080e94b96fae20471cbd4a1ed372313ee73 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 13 May 2023 17:50:03 +0000 Subject: [PATCH] feat: no battles in period --- src/commands/stats.ts | 153 ++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 72 deletions(-) diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 0eeac6bd0..7d1aaa79d 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -129,78 +129,87 @@ export default { } stats`, ) .setDescription( - `${ - period === 'today' - ? '**⚠ "Today" stats are in development. Some stats are not available/wrong.**\n\n' - : '' - }${[ - [ - 'Winrate', - `${(100 * (stats.all.wins / stats.all.battles)).toFixed(2)}%`, - ], - [ - 'Survival', - `${( - 100 * - (stats.all.survived_battles / stats.all.battles) - ).toFixed(2)}%`, - ], - [ - 'Accuracy', - `${((stats.all.hits / stats.all.shots) * 100).toFixed(2)}%`, - ], - ['WN8', stats.wn8.toFixed(0)], - ['WN7', stats.wn7.toFixed(0)], - [], - ['Battles', stats.all.battles], - ['Wins', stats.all.wins], - ['Losses', stats.all.losses], - ['Average tier', stats.avg_tier.toFixed(2)], - [], - [ - 'Shots per battle', - (stats.all.shots / stats.all.battles).toFixed(2), - ], - [ - 'Hits per battle', - (stats.all.hits / stats.all.battles).toFixed(2), - ], - [ - 'Damage per battle', - (stats.all.damage_dealt / stats.all.battles).toFixed(0), - ], - [ - 'Kills per battle', - (stats.all.frags / stats.all.battles).toFixed(2), - ], - [ - 'Spots per battle', - (stats.all.spotted / stats.all.battles).toFixed(2), - ], - [ - 'XP per battle', - (stats.all.xp / stats.all.battles).toFixed(0), - ], - [], - [ - 'Damage ratio', - (stats.all.damage_dealt / stats.all.damage_received).toFixed( - 2, - ), - ], - [ - 'Kills to death ratio', - ( - stats.all.frags / - (stats.all.battles - stats.all.survived_battles) - ).toFixed(2), - ], - ] - .filter((array) => array[1] !== `${-Infinity}`) - .map((array) => - array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`, - ) - .join('\n')}\n\n${blitzLinks(server, blitzAccount.nickname)}`, + stats.all.battles > 0 + ? `${ + period === 'today' + ? '**⚠ "Today" stats are in development. Some stats are not available/wrong.**\n\n' + : '' + }${[ + [ + 'Winrate', + `${(100 * (stats.all.wins / stats.all.battles)).toFixed( + 2, + )}%`, + ], + [ + 'Survival', + `${( + 100 * + (stats.all.survived_battles / stats.all.battles) + ).toFixed(2)}%`, + ], + [ + 'Accuracy', + `${((stats.all.hits / stats.all.shots) * 100).toFixed( + 2, + )}%`, + ], + ['WN8', stats.wn8.toFixed(0)], + ['WN7', stats.wn7.toFixed(0)], + [], + ['Battles', stats.all.battles], + ['Wins', stats.all.wins], + ['Losses', stats.all.losses], + ['Average tier', stats.avg_tier.toFixed(2)], + [], + [ + 'Shots per battle', + (stats.all.shots / stats.all.battles).toFixed(2), + ], + [ + 'Hits per battle', + (stats.all.hits / stats.all.battles).toFixed(2), + ], + [ + 'Damage per battle', + (stats.all.damage_dealt / stats.all.battles).toFixed(0), + ], + [ + 'Kills per battle', + (stats.all.frags / stats.all.battles).toFixed(2), + ], + [ + 'Spots per battle', + (stats.all.spotted / stats.all.battles).toFixed(2), + ], + [ + 'XP per battle', + (stats.all.xp / stats.all.battles).toFixed(0), + ], + [], + [ + 'Damage ratio', + ( + stats.all.damage_dealt / stats.all.damage_received + ).toFixed(2), + ], + [ + 'Kills to death ratio', + ( + stats.all.frags / + (stats.all.battles - stats.all.survived_battles) + ).toFixed(2), + ], + ] + .filter((array) => array[1] !== `${-Infinity}`) + .map((array) => + array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`, + ) + .join('\n')}\n\n${blitzLinks( + server, + blitzAccount.nickname, + )}` + : 'No battles played in this period.', ), ), ],