@@ -26,6 +26,9 @@ const chartJSNodeCanvas = new ChartJSNodeCanvas({
26
26
} ,
27
27
} ) ;
28
28
29
+ const ACTIVITY_PERIOD_ID = "activity-period" ;
30
+ const ACTIVITY_ROLLING_ID = "activity-rolling" ;
31
+
29
32
const ActivityCommand : Command = {
30
33
data : new SlashCommandBuilder ( )
31
34
. setName ( "activity" )
@@ -55,7 +58,7 @@ const ActivityCommand: Command = {
55
58
56
59
const fileBuffer = await plotTrend ( guildId , userLocale , serverName , botName , channel ) ;
57
60
58
- const trendPeriodSelect = new StringSelectMenuBuilder ( ) . setCustomId ( "activity-period" ) . setOptions ( [
61
+ const trendPeriodSelect = new StringSelectMenuBuilder ( ) . setCustomId ( ACTIVITY_PERIOD_ID ) . setOptions ( [
59
62
{
60
63
label : translations . responses ?. sinceTheBeginning ?. [ userLocale ] ?? "Since the beginning" ,
61
64
value : "0" ,
@@ -81,7 +84,7 @@ const ActivityCommand: Command = {
81
84
} ,
82
85
] ) ;
83
86
84
- const rollingMeanSelect = new StringSelectMenuBuilder ( ) . setCustomId ( "activity-rolling" ) . setOptions ( [
87
+ const rollingMeanSelect = new StringSelectMenuBuilder ( ) . setCustomId ( ACTIVITY_ROLLING_ID ) . setOptions ( [
85
88
{
86
89
label : translations . responses ?. rolling14Days ?. [ userLocale ] ?? "Average over 14 days" ,
87
90
value : "14" ,
@@ -131,26 +134,29 @@ const ActivityCommand: Command = {
131
134
let rolling = 14 ;
132
135
133
136
collector . on ( "collect" , async ( i ) => {
134
- if ( i . customId === "activity-period" ) {
137
+ if ( i . customId === ACTIVITY_PERIOD_ID ) {
135
138
period = parseInt ( i . values [ 0 ] ?? "0" ) ;
136
- } else if ( i . customId === "activity-rolling" ) {
139
+ } else if ( i . customId === ACTIVITY_ROLLING_ID ) {
137
140
rolling = parseInt ( i . values [ 0 ] ?? "14" ) ;
138
141
}
139
142
logger . debug ( "Period: %d, Rolling: %d" , period , rolling ) ;
140
143
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
+ }
154
160
}
155
161
156
162
const deferUpdatePromise = i . update ( { content : "" , components : components } ) ;
0 commit comments