@@ -26,6 +26,9 @@ const chartJSNodeCanvas = new ChartJSNodeCanvas({
2626 } ,
2727} ) ;
2828
29+ const ACTIVITY_PERIOD_ID = "activity-period" ;
30+ const ACTIVITY_ROLLING_ID = "activity-rolling" ;
31+
2932const ActivityCommand : Command = {
3033 data : new SlashCommandBuilder ( )
3134 . setName ( "activity" )
@@ -55,7 +58,7 @@ const ActivityCommand: Command = {
5558
5659 const fileBuffer = await plotTrend ( guildId , userLocale , serverName , botName , channel ) ;
5760
58- const trendPeriodSelect = new StringSelectMenuBuilder ( ) . setCustomId ( "activity-period" ) . setOptions ( [
61+ const trendPeriodSelect = new StringSelectMenuBuilder ( ) . setCustomId ( ACTIVITY_PERIOD_ID ) . setOptions ( [
5962 {
6063 label : translations . responses ?. sinceTheBeginning ?. [ userLocale ] ?? "Since the beginning" ,
6164 value : "0" ,
@@ -81,7 +84,7 @@ const ActivityCommand: Command = {
8184 } ,
8285 ] ) ;
8386
84- const rollingMeanSelect = new StringSelectMenuBuilder ( ) . setCustomId ( "activity-rolling" ) . setOptions ( [
87+ const rollingMeanSelect = new StringSelectMenuBuilder ( ) . setCustomId ( ACTIVITY_ROLLING_ID ) . setOptions ( [
8588 {
8689 label : translations . responses ?. rolling14Days ?. [ userLocale ] ?? "Average over 14 days" ,
8790 value : "14" ,
@@ -131,26 +134,29 @@ const ActivityCommand: Command = {
131134 let rolling = 14 ;
132135
133136 collector . on ( "collect" , async ( i ) => {
134- if ( i . customId === "activity-period" ) {
137+ if ( i . customId === ACTIVITY_PERIOD_ID ) {
135138 period = parseInt ( i . values [ 0 ] ?? "0" ) ;
136- } else if ( i . customId === "activity-rolling" ) {
139+ } else if ( i . customId === ACTIVITY_ROLLING_ID ) {
137140 rolling = parseInt ( i . values [ 0 ] ?? "14" ) ;
138141 }
139142 logger . debug ( "Period: %d, Rolling: %d" , period , rolling ) ;
140143
141- const selectedPeriodOption = trendPeriodSelect . options . find ( ( option ) => option . data . value === i . values [ 0 ] ) ;
142- const selectedRollingOption = rollingMeanSelect . options . find ( ( option ) => option . data . value === i . values [ 0 ] ) ;
143- if ( selectedPeriodOption ) {
144- trendPeriodSelect . options . forEach ( ( option ) => {
145- option . setDefault ( false ) ;
146- } ) ;
147- selectedPeriodOption . setDefault ( true ) ;
148- }
149- if ( selectedRollingOption ) {
150- rollingMeanSelect . options . forEach ( ( option ) => {
151- option . setDefault ( false ) ;
152- } ) ;
153- selectedRollingOption . setDefault ( true ) ;
144+ if ( i . customId === ACTIVITY_PERIOD_ID ) {
145+ const selectedPeriodOption = trendPeriodSelect . options . find ( ( option ) => option . data . value === i . values [ 0 ] ) ;
146+ if ( selectedPeriodOption ) {
147+ trendPeriodSelect . options . forEach ( ( option ) => {
148+ option . setDefault ( false ) ;
149+ } ) ;
150+ selectedPeriodOption . setDefault ( true ) ;
151+ }
152+ } else if ( i . customId === ACTIVITY_ROLLING_ID ) {
153+ const selectedRollingOption = rollingMeanSelect . options . find ( ( option ) => option . data . value === i . values [ 0 ] ) ;
154+ if ( selectedRollingOption ) {
155+ rollingMeanSelect . options . forEach ( ( option ) => {
156+ option . setDefault ( false ) ;
157+ } ) ;
158+ selectedRollingOption . setDefault ( true ) ;
159+ }
154160 }
155161
156162 const deferUpdatePromise = i . update ( { content : "" , components : components } ) ;
0 commit comments