Skip to content

Commit

Permalink
feat(bot): sort standings
Browse files Browse the repository at this point in the history
  • Loading branch information
shayypy committed Feb 23, 2024
1 parent 491d527 commit 247cd0b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/bot/src/commands/standings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 247cd0b

Please sign in to comment.