1
1
import {
2
2
ActionRowBuilder ,
3
- ModalBuilder ,
4
- TextInputBuilder ,
5
3
EmbedBuilder ,
6
4
AttachmentBuilder ,
7
5
type BufferResolvable ,
8
- ButtonBuilder ,
9
- ButtonStyle ,
10
6
type AnyComponentBuilder ,
11
7
type RestOrArray ,
12
- StringSelectMenuBuilder ,
13
- UserSelectMenuBuilder ,
14
- ChannelSelectMenuBuilder ,
15
- RoleSelectMenuBuilder ,
16
- StringSelectMenuOptionBuilder ,
17
- MentionableSelectMenuBuilder
8
+ ClientEvents
18
9
} from 'discord.js'
19
10
import type { Stream } from 'node:stream'
20
11
import type {
21
- ButtonOptions ,
22
- ChannelSelectMenuOptions ,
23
12
CommandConfig ,
24
13
CommandExecute ,
25
14
ContextMenuCallback ,
@@ -28,6 +17,7 @@ import type {
28
17
DefineContextMenuWithOptions ,
29
18
DefineEvent ,
30
19
DefineEventWithOptions ,
20
+ DefineModal ,
31
21
DefinePrecondition ,
32
22
DefinePreconditionWithName ,
33
23
EmbedOptions ,
@@ -38,31 +28,25 @@ import type {
38
28
HarmonixConfig ,
39
29
HarmonixContextMenu ,
40
30
HarmonixEvent ,
41
- HarmonixEvents ,
42
- MentionableSelectMenuOptions ,
43
- ModalOptions ,
44
31
OptionsDef ,
45
- PreconditionCallback ,
46
- RoleSelectMenuOptions ,
47
- SelectMenuOptions ,
48
- StringSelectMenuOptions ,
49
- UserSelectMenuOptions
32
+ PreconditionCallback
50
33
} from './types'
51
- import { createError } from './harmonix'
34
+ import { DefineButton } from './types'
35
+ import { DefineSelectMenu } from './types/select-menus'
52
36
53
37
export const defineHarmonixConfig = ( config : HarmonixConfig ) => {
54
38
return config
55
39
}
56
40
57
41
export const defineEvent : DefineEvent & DefineEventWithOptions = <
58
- Event extends keyof HarmonixEvents = any
42
+ Event extends keyof ClientEvents = any
59
43
> (
60
44
...args : [ EventOptions | EventCallback < Event > , EventCallback < Event > ?]
61
45
) : HarmonixEvent => {
62
46
let options : EventOptions = { }
63
47
64
48
if ( args . length === 1 ) {
65
- const [ callback ] = args as [ EventCallback < keyof HarmonixEvents > ]
49
+ const [ callback ] = args as [ EventCallback < keyof ClientEvents > ]
66
50
67
51
return {
68
52
options,
@@ -71,7 +55,7 @@ export const defineEvent: DefineEvent & DefineEventWithOptions = <
71
55
} else {
72
56
const [ opts , callback ] = args as [
73
57
EventOptions ,
74
- EventCallback < keyof HarmonixEvents >
58
+ EventCallback < keyof ClientEvents >
75
59
]
76
60
77
61
options = opts
@@ -150,42 +134,6 @@ export const defineActionRow = <
150
134
return builder
151
135
}
152
136
153
- export const defineModal = ( options : ModalOptions ) : ModalBuilder => {
154
- const builder = new ModalBuilder ( )
155
- . setCustomId ( options . id )
156
- . setTitle ( options . title )
157
-
158
- if ( options . textInputs ) {
159
- for ( const input of options . textInputs ) {
160
- const inputBuilder = new TextInputBuilder ( )
161
- . setCustomId ( input . id )
162
- . setLabel ( input . label )
163
- . setStyle ( input . style )
164
-
165
- if ( input . maxLength ) {
166
- inputBuilder . setMaxLength ( input . maxLength )
167
- }
168
- if ( input . minLength ) {
169
- inputBuilder . setMinLength ( input . minLength )
170
- }
171
- if ( input . placeholder ) {
172
- inputBuilder . setPlaceholder ( input . placeholder )
173
- }
174
- if ( input . value ) {
175
- inputBuilder . setValue ( input . value )
176
- }
177
- if ( input . required ) {
178
- inputBuilder . setRequired ( input . required )
179
- }
180
- const row = defineActionRow ( inputBuilder )
181
-
182
- builder . addComponents ( row )
183
- }
184
- }
185
-
186
- return builder
187
- }
188
-
189
137
export const defineEmbed = ( options : EmbedOptions ) => {
190
138
const builder = new EmbedBuilder ( )
191
139
const setters : EmbedSetters = {
@@ -214,154 +162,14 @@ export const defineAttachment = (args: BufferResolvable | Stream) => {
214
162
return new AttachmentBuilder ( args )
215
163
}
216
164
217
- export const defineButton = ( options : ButtonOptions ) => {
218
- const builder = new ButtonBuilder ( )
219
- . setCustomId ( options . id )
220
- . setStyle ( options . style ? ButtonStyle [ options . style ] : ButtonStyle . Primary )
221
-
222
- if ( options . label ) {
223
- builder . setLabel ( options . label )
224
- }
225
- if ( options . emoji ) {
226
- builder . setEmoji ( options . emoji )
227
- }
228
- if ( options . url ) {
229
- builder . setURL ( options . url )
230
- }
231
- if ( options . disabled ) {
232
- builder . setDisabled ( options . disabled )
233
- }
234
-
235
- return builder
165
+ export const defineButton : DefineButton = ( config , callback ) => {
166
+ return { config, callback }
236
167
}
237
168
238
- export const defineSelectMenu = ( options : SelectMenuOptions ) => {
239
- const { id, placeholder, type, disabled, minValues, maxValues } = options
240
-
241
- switch ( type ) {
242
- case 'String' : {
243
- const stringOptions = options as StringSelectMenuOptions
244
- const selectMenu = new StringSelectMenuBuilder ( )
245
- . setCustomId ( id )
246
- . setPlaceholder ( placeholder )
247
-
248
- if ( disabled ) {
249
- selectMenu . setDisabled ( disabled )
250
- }
251
- if ( minValues ) {
252
- selectMenu . setMinValues ( minValues )
253
- }
254
- if ( maxValues ) {
255
- selectMenu . setMaxValues ( maxValues )
256
- }
257
- stringOptions . options . forEach ( ( option ) => {
258
- const optionBuilder = new StringSelectMenuOptionBuilder ( )
259
- . setLabel ( option . label )
260
- . setValue ( option . value )
261
-
262
- if ( option . description ) {
263
- optionBuilder . setDescription ( option . description )
264
- }
265
- if ( option . emoji ) {
266
- optionBuilder . setEmoji ( option . emoji )
267
- }
268
- if ( option . default ) {
269
- optionBuilder . setDefault ( true )
270
- }
271
-
272
- selectMenu . addOptions ( optionBuilder )
273
- } )
274
-
275
- return selectMenu
276
- }
277
- case 'User' : {
278
- const userOptions = options as UserSelectMenuOptions
279
- const selectMenu = new UserSelectMenuBuilder ( )
280
- . setCustomId ( id )
281
- . setPlaceholder ( placeholder )
282
-
283
- if ( disabled ) {
284
- selectMenu . setDisabled ( disabled )
285
- }
286
- if ( minValues ) {
287
- selectMenu . setMinValues ( minValues )
288
- }
289
- if ( maxValues ) {
290
- selectMenu . setMaxValues ( maxValues )
291
- }
292
- if ( userOptions . defaultUsers ) {
293
- selectMenu . setDefaultUsers ( userOptions . defaultUsers )
294
- }
295
-
296
- return selectMenu
297
- }
298
- case 'Channel' : {
299
- const channelOptions = options as ChannelSelectMenuOptions
300
- const selectMenu = new ChannelSelectMenuBuilder ( )
301
- . setCustomId ( id )
302
- . setPlaceholder ( placeholder )
303
-
304
- if ( disabled ) {
305
- selectMenu . setDisabled ( disabled )
306
- }
307
- if ( minValues ) {
308
- selectMenu . setMinValues ( minValues )
309
- }
310
- if ( maxValues ) {
311
- selectMenu . setMaxValues ( maxValues )
312
- }
313
- if ( channelOptions . channelTypes ) {
314
- selectMenu . addChannelTypes ( ...channelOptions . channelTypes )
315
- }
316
- if ( channelOptions . defaultChannels ) {
317
- selectMenu . setDefaultChannels ( channelOptions . defaultChannels )
318
- }
319
-
320
- return selectMenu
321
- }
322
- case 'Role' : {
323
- const roleOptions = options as RoleSelectMenuOptions
324
- const selectMenu = new RoleSelectMenuBuilder ( )
325
- . setCustomId ( id )
326
- . setPlaceholder ( placeholder )
327
-
328
- if ( disabled ) {
329
- selectMenu . setDisabled ( disabled )
330
- }
331
- if ( minValues ) {
332
- selectMenu . setMinValues ( minValues )
333
- }
334
- if ( maxValues ) {
335
- selectMenu . setMaxValues ( maxValues )
336
- }
337
- if ( roleOptions . defaultRoles ) {
338
- selectMenu . setDefaultRoles ( roleOptions . defaultRoles )
339
- }
340
-
341
- return selectMenu
342
- }
343
- case 'Mentionable' : {
344
- const mentionableOptions = options as MentionableSelectMenuOptions
345
- const selectMenu = new MentionableSelectMenuBuilder ( )
346
- . setCustomId ( id )
347
- . setPlaceholder ( placeholder )
348
-
349
- if ( disabled ) {
350
- selectMenu . setDisabled ( disabled )
351
- }
352
- if ( minValues ) {
353
- selectMenu . setMinValues ( minValues )
354
- }
355
- if ( maxValues ) {
356
- selectMenu . setMaxValues ( maxValues )
357
- }
358
- if ( mentionableOptions . defaultValues ) {
359
- selectMenu . setDefaultValues ( mentionableOptions . defaultValues )
360
- }
169
+ export const defineModal : DefineModal = ( config , callback ) => {
170
+ return { config, callback }
171
+ }
361
172
362
- return selectMenu
363
- }
364
- default :
365
- throw createError ( 'Invalid select menu type' )
366
- }
173
+ export const defineSelectMenu : DefineSelectMenu = ( config , callback ) => {
174
+ return { config, callback }
367
175
}
0 commit comments