@@ -28,13 +28,19 @@ export type MessageCommandOptionsSchema = Record<
28
28
export class MessageCommandParser {
29
29
#parsed: ParsedMessageCommand | null = null ;
30
30
#options: MessageCommandOptions | null = null ;
31
+ #args: string [ ] = [ ] ;
31
32
32
33
public constructor (
33
34
public message : Message ,
34
35
private prefix : string [ ] ,
35
36
private schema : ( command : string ) => MessageCommandOptionsSchema ,
36
37
) { }
37
38
39
+ public getArgs ( ) {
40
+ void this . parse ( ) ;
41
+ return this . #args;
42
+ }
43
+
38
44
public get options ( ) {
39
45
if ( ! this . #options) {
40
46
this . #options = new MessageCommandOptions ( this ) ;
@@ -89,6 +95,8 @@ export class MessageCommandParser {
89
95
const parts = content . slice ( prefix . length ) . trim ( ) . split ( ' ' ) ;
90
96
const command = parts . shift ( ) ;
91
97
98
+ this . #args = parts ;
99
+
92
100
let subcommandGroup : string | undefined ;
93
101
let subcommand : string | undefined ;
94
102
@@ -109,49 +117,54 @@ export class MessageCommandParser {
109
117
110
118
const options = parts
111
119
. map ( ( part ) => {
112
- const [ name , value ] = part . split ( ':' ) ;
113
-
114
- if ( ! ( name in schema ) ) return null ;
115
-
116
- switch ( schema [ name ] ) {
117
- case ApplicationCommandOptionType . Boolean :
118
- return { name, value : value === 'true' } ;
119
- case ApplicationCommandOptionType . Integer :
120
- return { name, value : parseInt ( value , 10 ) } ;
121
- case ApplicationCommandOptionType . Number :
122
- return { name, value : parseFloat ( value ) } ;
123
- case ApplicationCommandOptionType . String :
124
- return { name, value } ;
125
- case ApplicationCommandOptionType . User :
126
- return {
127
- name,
128
- value : this . message . mentions . users . find ( ( u ) => {
129
- return u . id === value . replace ( / [ < @ ! > ] / g, '' ) ;
130
- } ) ,
131
- } ;
132
- case ApplicationCommandOptionType . Channel :
133
- return {
134
- name,
135
- value : this . message . mentions . channels . find ( ( c ) => {
136
- return c . id === value . replace ( / [ < # > ] / g, '' ) ;
137
- } ) ,
138
- } ;
139
- case ApplicationCommandOptionType . Role :
140
- return {
141
- name,
142
- value : this . message . mentions . roles . find ( ( r ) => {
143
- return r . id === value . replace ( / [ < @ & > ] / g, '' ) ;
144
- } ) ,
145
- } ;
146
- case ApplicationCommandOptionType . Attachment :
147
- return {
148
- name,
149
- value : this . message . attachments . find ( ( a ) => {
150
- return a . name === value ;
151
- } ) ,
152
- } ;
153
- default :
154
- return null ;
120
+ try {
121
+ const [ name , value ] = part . split ( ':' ) ;
122
+
123
+ if ( ! ( name in schema ) ) return null ;
124
+
125
+ switch ( schema [ name ] ) {
126
+ case ApplicationCommandOptionType . Boolean :
127
+ return { name, value : value === 'true' } ;
128
+ case ApplicationCommandOptionType . Integer :
129
+ return { name, value : parseInt ( value , 10 ) } ;
130
+ case ApplicationCommandOptionType . Number :
131
+ return { name, value : parseFloat ( value ) } ;
132
+ case ApplicationCommandOptionType . String :
133
+ return { name, value } ;
134
+ case ApplicationCommandOptionType . User :
135
+ return {
136
+ name,
137
+ value : this . message . mentions . users . find ( ( u ) => {
138
+ return u . id === value . replace ( / [ < @ ! > ] / g, '' ) ;
139
+ } ) ,
140
+ } ;
141
+ case ApplicationCommandOptionType . Channel :
142
+ return {
143
+ name,
144
+ value : this . message . mentions . channels . find ( ( c ) => {
145
+ return c . id === value . replace ( / [ < # > ] / g, '' ) ;
146
+ } ) ,
147
+ } ;
148
+ case ApplicationCommandOptionType . Role :
149
+ return {
150
+ name,
151
+ value : this . message . mentions . roles . find ( ( r ) => {
152
+ return r . id === value . replace ( / [ < @ & > ] / g, '' ) ;
153
+ } ) ,
154
+ } ;
155
+ case ApplicationCommandOptionType . Attachment :
156
+ return {
157
+ name,
158
+ value : this . message . attachments . find ( ( a ) => {
159
+ return a . name === value ;
160
+ } ) ,
161
+ } ;
162
+ default :
163
+ return null ;
164
+ }
165
+ } catch {
166
+ // Invalid option
167
+ return null ;
155
168
}
156
169
} )
157
170
. filter ( ( v ) => v !== null ) ;
0 commit comments