From 774d6dc9f5e466ea591503f5c062e3a2be7d2c2a Mon Sep 17 00:00:00 2001 From: tresabhi Date: Mon, 24 Apr 2023 00:18:17 +0000 Subject: [PATCH] feat: better not tracked checks --- src/commands/inactive.ts | 2 ++ src/utilities/getBlitzStarsAccount.ts | 30 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 83ede074a..615bb8b53 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -12,6 +12,8 @@ import { CLANS } from './eligible.js'; const DEFAULT_THRESHOLD = 7; +export const inDev = true; + export async function execute( interaction: ChatInputCommandInteraction, ) { diff --git a/src/utilities/getBlitzStarsAccount.ts b/src/utilities/getBlitzStarsAccount.ts index b75dfc4f4..bc27438d9 100644 --- a/src/utilities/getBlitzStarsAccount.ts +++ b/src/utilities/getBlitzStarsAccount.ts @@ -13,18 +13,26 @@ export default async function getBlitzStarsAccount( ign: string, callback: (account: PlayerStatistics) => void, ) { + function notTracked() { + interaction.reply({ + embeds: [ + new EmbedBuilder() + .setTitle('No data to display') + .setDescription(`${ign} is not tracked by BlitzStars.`) + .setColor(NEGATIVE_COLOR), + ], + }); + } + fetch(`https://www.blitzstars.com/api/top/player/${accountId}`) .then(async (response) => { - callback((await response.json()) as PlayerStatistics); + const data = (await response.json()) as PlayerStatistics; + + if (data.statistics) { + callback(data); + } else { + notTracked(); + } }) - .catch(() => { - interaction.reply({ - embeds: [ - new EmbedBuilder() - .setTitle('No data to display') - .setDescription(`${ign} is not tracked by BlitzStars.`) - .setColor(NEGATIVE_COLOR), - ], - }); - }); + .catch(notTracked); }