@@ -23,6 +23,10 @@ const inMemoryJobList: { id: string; job: CronJob }[] = [];
23
23
24
24
export type Frequency = keyof typeof cronTime ;
25
25
26
+ export const isFrequency = ( frequency : string ) : frequency is Frequency => {
27
+ return Object . keys ( cronTime ) . includes ( frequency ) ;
28
+ } ;
29
+
26
30
export const hasPermission = ( interaction : ChatInputCommandInteraction ) => {
27
31
if ( ! isModo ( interaction . member ) ) {
28
32
interaction . reply ( 'You are not allowed to use this command' ) . catch ( console . error ) ;
@@ -45,7 +49,7 @@ export const createRecurringMessage = (
45
49
console . error ( `Channel ${ channelId } not found` ) ;
46
50
return ;
47
51
}
48
- channel . send ( message ) . catch ( console . error ) ;
52
+ void channel . send ( message ) ;
49
53
} ,
50
54
null ,
51
55
true ,
@@ -56,18 +60,20 @@ export const createRecurringMessage = (
56
60
export const addRecurringMessage = async ( interaction : ChatInputCommandInteraction ) => {
57
61
const jobId = randomUUID ( ) ;
58
62
const channelId = interaction . channelId ;
59
- const frequency = interaction . options . getString ( 'frequency' , true ) as Frequency ;
63
+ const frequency = interaction . options . getString ( 'frequency' , true ) ;
64
+ if ( ! isFrequency ( frequency ) ) {
65
+ await interaction . reply ( `${ frequency } is not a valid frequency` ) ;
66
+ return ;
67
+ }
60
68
const message = interaction . options . getString ( 'message' , true ) ;
61
69
62
70
const displayIdInMessage = `\n (id: ${ jobId } )` ;
63
71
const jobMessage = message + displayIdInMessage ;
64
72
65
73
if ( jobMessage . length > MAX_MESSAGE_LENGTH ) {
66
- interaction
67
- . reply (
68
- `Message is too long (max ${ MAX_MESSAGE_LENGTH - displayIdInMessage . length } characters)` ,
69
- )
70
- . catch ( console . error ) ;
74
+ await interaction . reply (
75
+ `Message is too long (max ${ MAX_MESSAGE_LENGTH - displayIdInMessage . length } characters)` ,
76
+ ) ;
71
77
return ;
72
78
}
73
79
@@ -98,7 +104,7 @@ export const removeRecurringMessage = async (interaction: ChatInputCommandIntera
98
104
99
105
const job = inMemoryJobList . find ( ( { id } ) => id === jobId ) ?. job ;
100
106
if ( ! job ) {
101
- interaction . reply ( 'Recurring message not found' ) . catch ( console . error ) ;
107
+ await interaction . reply ( 'Recurring message not found' ) ;
102
108
return ;
103
109
}
104
110
@@ -111,7 +117,7 @@ export const listRecurringMessages = async (interaction: ChatInputCommandInterac
111
117
const recurringMessages = await cache . get ( 'recurringMessages' , [ ] ) ;
112
118
113
119
if ( recurringMessages . length === 0 ) {
114
- interaction . reply ( 'No recurring message found' ) . catch ( console . error ) ;
120
+ await interaction . reply ( 'No recurring message found' ) ;
115
121
return ;
116
122
}
117
123
0 commit comments