11import {
2- CompetitionDetails ,
2+ CompetitionDetailsResponse ,
33 CompetitionStatus ,
44 CompetitionStatusProps ,
55 CompetitionType ,
66 CompetitionTypeProps ,
77 formatNumber ,
8- isCompetitionStatus ,
98 MetricProps
109} from '@wise-old-man/utils' ;
1110import { ApplicationCommandOptionType , ChatInputCommandInteraction , EmbedBuilder } from 'discord.js' ;
@@ -59,8 +58,11 @@ class GroupCompetitionCommand extends Command {
5958
6059 // Extract the "status" param, or fallback to "ongoing"
6160 const statusParam = interaction . options . getString ( 'status' ) ;
61+
6262 const status =
63- statusParam !== null && isCompetitionStatus ( statusParam ) ? statusParam : CompetitionStatus . ONGOING ;
63+ statusParam !== null && statusParam in CompetitionStatusProps
64+ ? ( statusParam as CompetitionStatus )
65+ : CompetitionStatus . ONGOING ;
6466
6567 // Extract the "competition_id" param, or fallback to the default competition
6668 const competitionIdParam = interaction . options . getInteger ( 'competition_id' ) ;
@@ -82,21 +84,21 @@ class GroupCompetitionCommand extends Command {
8284 }
8385}
8486
85- function getFooterDate ( competition : CompetitionDetails ) {
87+ function getFooterDate ( competition : CompetitionDetailsResponse ) {
8688 return getCompetitionStatus ( competition ) === CompetitionStatus . UPCOMING
8789 ? new Date ( competition . startsAt )
8890 : new Date ( competition . endsAt ) ;
8991}
9092
91- function getFooterLabel ( competition : CompetitionDetails ) {
93+ function getFooterLabel ( competition : CompetitionDetailsResponse ) {
9294 const status = getCompetitionStatus ( competition ) ;
9395
9496 if ( status === CompetitionStatus . UPCOMING ) return 'Starts at' ;
9597 if ( status === CompetitionStatus . ONGOING ) return 'Ends at' ;
9698 return 'Ended at' ;
9799}
98100
99- function buildContent ( competition : CompetitionDetails ) {
101+ function buildContent ( competition : CompetitionDetailsResponse ) {
100102 const { metric, type, participations, participantCount } = competition ;
101103 const timeLeft = getCompetitionTimeLeft ( competition ) . split ( ' ' ) ;
102104
@@ -135,7 +137,7 @@ function buildContent(competition: CompetitionDetails) {
135137 return lines . join ( '\n' ) ;
136138}
137139
138- function aggregateTeamData ( competition : CompetitionDetails ) {
140+ function aggregateTeamData ( competition : CompetitionDetailsResponse ) {
139141 const participants = competition . participations ;
140142
141143 if ( ! participants || participants . length === 0 ) return [ ] ;
0 commit comments