From 247cd0bedf5b50df6769e6bc94c4c825ff689da1 Mon Sep 17 00:00:00 2001 From: shay <43248357+shayypy@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:02:56 -0600 Subject: [PATCH] feat(bot): sort standings --- packages/bot/src/commands/standings.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/bot/src/commands/standings.ts b/packages/bot/src/commands/standings.ts index 9726ce0..0f86aa5 100644 --- a/packages/bot/src/commands/standings.ts +++ b/packages/bot/src/commands/standings.ts @@ -131,6 +131,16 @@ export const standingsCallback: ChatInputAppCommandCallback = async (ctx) => { // biome-ignore lint/style/noNonNullAssertion: Present for KHL leagues return ctx.reply(utils.standings!()); } + const sort = (ctx.getStringOption("sort").value || undefined) as + | "games_played" + | "games_remaining" + | "points" + | "wins" + | "ot_wins" + | "ot_losses" + | "losses" + | "percentage" + | undefined; const client = getHtClient(league, getHtLocale(ctx)); const seasons = (await client.getSeasonList()).SiteKit.Seasons; @@ -149,7 +159,10 @@ export const standingsCallback: ChatInputAppCommandCallback = async (ctx) => { "standings", ) ).SiteKit.Statviewtype as HockeyTechTeamStanding[] - ).filter((team) => !!team.team_code); + ) + .filter((team) => !!team.team_code) + .sort((a, b) => (sort ? Number(b[sort] ?? 0) - Number(a[sort] ?? 0) : 0)); + const embed = getStandingsEmbed( ctx, league, @@ -163,7 +176,9 @@ export const standingsCallback: ChatInputAppCommandCallback = async (ctx) => { "L", "PCT", ], - standings.map((team) => ({ + standings + + .map((team) => ({ teamCode: team.team_code, values: [ team.games_played,