diff --git a/apps/discord-bot/src/commands/duels/duels.command.tsx b/apps/discord-bot/src/commands/duels/duels.command.tsx index c18183e31..3a18cdaa2 100644 --- a/apps/discord-bot/src/commands/duels/duels.command.tsx +++ b/apps/discord-bot/src/commands/duels/duels.command.tsx @@ -6,7 +6,12 @@ * https://github.com/Statsify/statsify/blob/main/LICENSE */ -import { ApiModeFromGameModes, DUELS_MODES, DuelsModes, GameModeWithSubModes } from "@statsify/schemas"; +import { + ApiModeFromGameModes, + DUELS_MODES, + DuelsModes, + GameModeWithSubModes, +} from "@statsify/schemas"; import { BaseHypixelCommand, BaseProfileProps, @@ -26,19 +31,36 @@ interface PreProfileData { modeIcons: DuelsModeIcons; } +let modeIcons: DuelsModeIcons | undefined; + +const getModeIcons = async (): Promise => { + if (modeIcons) return modeIcons; + + const paths = await readdir(getAssetPath("duels")); + const modIconEntries = await Promise.all( + paths.map(async (mode) => [ + mode.replace(".png", ""), + await loadImage(getAssetPath(`duels/${mode}`)), + ]), + ); + + const icons = Object.fromEntries(modIconEntries); + modeIcons = icons; + + return icons; +}; + @Command({ description: (t) => t("commands.duels") }) -export class DuelsCommand extends BaseHypixelCommand { +export class DuelsCommand extends BaseHypixelCommand< + DuelsModes, + PreProfileData +> { public constructor() { super(DUELS_MODES); } public async getPreProfileData(): Promise { - const modeIconPaths = await readdir(getAssetPath("duels")); - const modeIcons = await Promise.all( - modeIconPaths.map(async (mode) => [mode.replace(".png", ""), await loadImage(getAssetPath(`duels/${mode}`))]) - ); - - return { modeIcons: Object.fromEntries(modeIcons) }; + return { modeIcons: await getModeIcons() }; } public getModeEmojis(modes: GameModeWithSubModes[]): ModeEmoji[] { @@ -47,12 +69,14 @@ export class DuelsCommand extends BaseHypixelCommand public getProfile( base: BaseProfileProps, - { mode, data }: ProfileData + { mode, data }: ProfileData, ): JSX.Element { return ; } } -export function getDuelsModeEmojis(modes: GameModeWithSubModes[]): ModeEmoji[] { +export function getDuelsModeEmojis( + modes: GameModeWithSubModes[], +): ModeEmoji[] { return modes.map((m) => (t) => t(`emojis:duels.${m.api}`)); } diff --git a/apps/discord-bot/src/commands/leaderboards/base.leaderboard-command.tsx b/apps/discord-bot/src/commands/leaderboards/base.leaderboard-command.tsx index 7c32580d2..a2d2e1868 100644 --- a/apps/discord-bot/src/commands/leaderboards/base.leaderboard-command.tsx +++ b/apps/discord-bot/src/commands/leaderboards/base.leaderboard-command.tsx @@ -241,7 +241,7 @@ export class BaseLeaderboardCommand { cache.clear(); }, 300_000); - currentPage = page || currentPage; + currentPage = page ?? currentPage; return { ...message, components: [row] }; } @@ -271,7 +271,7 @@ export class BaseLeaderboardCommand { getLeaderboardDataIcon ); - if (params.type === LeaderboardQuery.PAGE && page) cache.set(page, message); + if (params.type === LeaderboardQuery.PAGE && page !== null) cache.set(page, message); return [message, page]; }