@mostfeatured/dbi 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/.hintrc +7 -7
- package/.vscode/settings.json +2 -2
- package/LICENSE +674 -674
- package/dist/DBI.js.map +1 -1
- package/dist/Events.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/methods/handleMessageCommands.js +1 -1
- package/dist/methods/handleMessageCommands.js.map +1 -1
- package/dist/methods/hookEventListeners.js.map +1 -1
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/ApplicationRoleConnectionMetadata.js.map +1 -1
- package/dist/types/Builders/ButtonBuilder.js.map +1 -1
- package/dist/types/Builders/ChannelSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/MentionableSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/ModalBuilder.js.map +1 -1
- package/dist/types/Builders/RoleSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/StringSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/UserSelectMenuBuilder.js.map +1 -1
- package/dist/types/ChatInput/ChatInput.js.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts +16 -16
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/dist/types/Components/Button.js.map +1 -1
- package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
- package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
- package/dist/types/Components/Modal.js.map +1 -1
- package/dist/types/Components/RoleSelectMenu.js.map +1 -1
- package/dist/types/Components/StringSelectMenu.js.map +1 -1
- package/dist/types/Components/UserSelectMenu.js.map +1 -1
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +1 -0
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js.map +1 -1
- package/dist/types/other/CustomEvent.js.map +1 -1
- package/dist/types/other/FakeMessageInteraction.js.map +1 -1
- package/dist/types/other/InteractionLocale.js.map +1 -1
- package/dist/types/other/Locale.js.map +1 -1
- package/dist/types/other/MessageContextMenu.js.map +1 -1
- package/dist/types/other/UserContextMenu.js.map +1 -1
- package/dist/utils/MemoryStore.js.map +1 -1
- package/dist/utils/UtilTypes.js.map +1 -1
- package/dist/utils/customId.js.map +1 -1
- package/dist/utils/permissions.js.map +1 -1
- package/dist/utils/recursiveImport.js.map +1 -1
- package/dist/utils/recursiveUnload.js.map +1 -1
- package/dist/utils/unloadModule.js.map +1 -1
- package/examples/modal/dbi.js +29 -29
- package/examples/modal/login.js +14 -14
- package/examples/modal/package.json +15 -15
- package/examples/modal/publish.js +12 -12
- package/examples/modal/src/chatInput.js +37 -37
- package/examples/modal/src/components.js +32 -32
- package/examples/modal/src/event.js +19 -19
- package/examples/modal/src/interactionlocales.js +23 -23
- package/examples/modal/src/locales.js +37 -37
- package/examples/modal/src/modal.js +27 -27
- package/generated/namespaceData.d.ts +14 -14
- package/package.json +45 -45
- package/readme.md +591 -591
- package/src/DBI.ts +1090 -1090
- package/src/Events.ts +189 -189
- package/src/data/eventMap.json +247 -247
- package/src/index.ts +23 -23
- package/src/methods/handleMessageCommands.ts +482 -482
- package/src/methods/hookEventListeners.ts +118 -118
- package/src/methods/hookInteractionListeners.ts +260 -260
- package/src/methods/publishInteractions.ts +255 -255
- package/src/types/ApplicationRoleConnectionMetadata.ts +19 -19
- package/src/types/Builders/ButtonBuilder.ts +52 -52
- package/src/types/Builders/ChannelSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/MentionableSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/ModalBuilder.ts +52 -52
- package/src/types/Builders/RoleSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/StringSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/UserSelectMenuBuilder.ts +52 -52
- package/src/types/ChatInput/ChatInput.ts +27 -27
- package/src/types/ChatInput/ChatInputOptions.ts +388 -388
- package/src/types/Components/Button.ts +38 -38
- package/src/types/Components/ChannelSelectMenu.ts +42 -42
- package/src/types/Components/MentionableSelectMenu.ts +42 -42
- package/src/types/Components/Modal.ts +45 -45
- package/src/types/Components/RoleSelectMenu.ts +42 -42
- package/src/types/Components/StringSelectMenu.ts +42 -42
- package/src/types/Components/UserSelectMenu.ts +42 -42
- package/src/types/Event.ts +144 -144
- package/src/types/Interaction.ts +96 -96
- package/src/types/other/CustomEvent.ts +18 -18
- package/src/types/other/FakeMessageInteraction.ts +407 -407
- package/src/types/other/InteractionLocale.ts +33 -33
- package/src/types/other/Locale.ts +69 -69
- package/src/types/other/MessageContextMenu.ts +26 -26
- package/src/types/other/UserContextMenu.ts +24 -24
- package/src/utils/MemoryStore.ts +27 -27
- package/src/utils/UtilTypes.ts +10 -10
- package/src/utils/customId.ts +44 -44
- package/src/utils/permissions.ts +4 -4
- package/src/utils/recursiveImport.ts +22 -22
- package/src/utils/recursiveUnload.ts +24 -24
- package/src/utils/unloadModule.ts +6 -6
- package/tsconfig.json +40 -40
|
@@ -1,388 +1,388 @@
|
|
|
1
|
-
import Discord from "discord.js";
|
|
2
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
3
|
-
import { DBI } from "../../DBI";
|
|
4
|
-
import { IDBIBaseExecuteCtx } from "../Interaction";
|
|
5
|
-
|
|
6
|
-
export type TDBIValueName<T> = { value: T; name: string };
|
|
7
|
-
export type TDBIBaseOption = {
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type TDBIMinMaxLength = { maxLength?: number; minLength?: number };
|
|
14
|
-
export type TDBIMinMaxValue = { maxValue?: number; minValue?: number };
|
|
15
|
-
|
|
16
|
-
export type TDBIValidator<
|
|
17
|
-
TExtends,
|
|
18
|
-
TValue,
|
|
19
|
-
TStep extends string,
|
|
20
|
-
TExpectedResponse = boolean
|
|
21
|
-
> = {
|
|
22
|
-
validate?(
|
|
23
|
-
cfg: TExtends & { value: TValue; step: TStep }
|
|
24
|
-
): Promise<TExpectedResponse> | TExpectedResponse;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export interface IDBIValuedInteraction<
|
|
28
|
-
TNamespace extends NamespaceEnums,
|
|
29
|
-
TInteractionType extends Discord.Interaction,
|
|
30
|
-
TValueType = string | number
|
|
31
|
-
> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
32
|
-
value: TValueType;
|
|
33
|
-
interaction: TInteractionType;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type TDBICompleteCtx<
|
|
37
|
-
TNamespace extends NamespaceEnums,
|
|
38
|
-
TValueType = string | number
|
|
39
|
-
> = IDBIValuedInteraction<
|
|
40
|
-
TNamespace,
|
|
41
|
-
Discord.AutocompleteInteraction,
|
|
42
|
-
TValueType
|
|
43
|
-
>;
|
|
44
|
-
|
|
45
|
-
export type TDBIValidateCtx<
|
|
46
|
-
TNamespace extends NamespaceEnums,
|
|
47
|
-
TValueType = string | number
|
|
48
|
-
> = IDBIValuedInteraction<TNamespace, Discord.Interaction, TValueType>;
|
|
49
|
-
|
|
50
|
-
export type TDBICompleter<
|
|
51
|
-
TNamespace extends NamespaceEnums,
|
|
52
|
-
TValueType extends number | string
|
|
53
|
-
> = {
|
|
54
|
-
onComplete(
|
|
55
|
-
ctx: TDBICompleteCtx<TNamespace, string>
|
|
56
|
-
): Promise<TDBIValueName<TValueType>[]> | TDBIValueName<TValueType>[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
|
|
60
|
-
dbi: DBI<TNamespace>;
|
|
61
|
-
constructor(dbi: DBI<TNamespace>) {
|
|
62
|
-
this.dbi = dbi;
|
|
63
|
-
}
|
|
64
|
-
stringAutocomplete(
|
|
65
|
-
cfg: TDBIBaseOption &
|
|
66
|
-
TDBIMinMaxLength & {
|
|
67
|
-
messageCommands?: { rest?: boolean };
|
|
68
|
-
} & TDBIValidator<
|
|
69
|
-
TDBIValidateCtx<TNamespace, string>,
|
|
70
|
-
string,
|
|
71
|
-
"Autocomplete" | "Result",
|
|
72
|
-
boolean | TDBIValueName<string>
|
|
73
|
-
> &
|
|
74
|
-
TDBICompleter<TNamespace, string>
|
|
75
|
-
) {
|
|
76
|
-
return {
|
|
77
|
-
type: Discord.ApplicationCommandOptionType.String,
|
|
78
|
-
name: cfg.name,
|
|
79
|
-
autocomplete: true,
|
|
80
|
-
onComplete: cfg.onComplete,
|
|
81
|
-
description: cfg.description,
|
|
82
|
-
maxLength: cfg.maxLength,
|
|
83
|
-
max_length: cfg.maxLength,
|
|
84
|
-
minLength: cfg.minLength,
|
|
85
|
-
min_length: cfg.minLength,
|
|
86
|
-
required: cfg.required,
|
|
87
|
-
validate: cfg.validate,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
stringChoices(
|
|
91
|
-
cfg: TDBIBaseOption &
|
|
92
|
-
TDBIMinMaxLength & {
|
|
93
|
-
choices: TDBIValueName<string>[];
|
|
94
|
-
messageCommands?: { rest?: boolean };
|
|
95
|
-
} & TDBIValidator<
|
|
96
|
-
TDBIValidateCtx<TNamespace, string>,
|
|
97
|
-
string,
|
|
98
|
-
"Result",
|
|
99
|
-
boolean
|
|
100
|
-
>
|
|
101
|
-
) {
|
|
102
|
-
return {
|
|
103
|
-
type: Discord.ApplicationCommandOptionType.String,
|
|
104
|
-
name: cfg.name,
|
|
105
|
-
choices: cfg.choices,
|
|
106
|
-
description: cfg.description,
|
|
107
|
-
maxLength: cfg.maxLength,
|
|
108
|
-
max_length: cfg.maxLength,
|
|
109
|
-
minLength: cfg.minLength,
|
|
110
|
-
min_length: cfg.minLength,
|
|
111
|
-
required: cfg.required,
|
|
112
|
-
validate: cfg.validate,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
string(
|
|
117
|
-
cfg: TDBIBaseOption &
|
|
118
|
-
TDBIMinMaxLength & {
|
|
119
|
-
messageCommands?: { rest?: boolean };
|
|
120
|
-
} & TDBIValidator<
|
|
121
|
-
TDBIValidateCtx<TNamespace, string>,
|
|
122
|
-
string,
|
|
123
|
-
"Result",
|
|
124
|
-
boolean
|
|
125
|
-
>
|
|
126
|
-
) {
|
|
127
|
-
return {
|
|
128
|
-
type: Discord.ApplicationCommandOptionType.String,
|
|
129
|
-
name: cfg.name,
|
|
130
|
-
description: cfg.description,
|
|
131
|
-
maxLength: cfg.maxLength,
|
|
132
|
-
max_length: cfg.maxLength,
|
|
133
|
-
minLength: cfg.minLength,
|
|
134
|
-
min_length: cfg.minLength,
|
|
135
|
-
required: cfg.required,
|
|
136
|
-
messageCommands: cfg.messageCommands,
|
|
137
|
-
validate: cfg.validate,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
numberAutocomplete(
|
|
142
|
-
cfg: TDBIBaseOption &
|
|
143
|
-
TDBIMinMaxValue &
|
|
144
|
-
TDBIValidator<
|
|
145
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
146
|
-
number,
|
|
147
|
-
"Autocomplete" | "Result",
|
|
148
|
-
boolean | TDBIValueName<number>
|
|
149
|
-
> &
|
|
150
|
-
TDBICompleter<TNamespace, number>
|
|
151
|
-
) {
|
|
152
|
-
return {
|
|
153
|
-
type: Discord.ApplicationCommandOptionType.Number,
|
|
154
|
-
name: cfg.name,
|
|
155
|
-
autocomplete: true,
|
|
156
|
-
onComplete: cfg.onComplete,
|
|
157
|
-
description: cfg.description,
|
|
158
|
-
maxValue: cfg.maxValue,
|
|
159
|
-
max_value: cfg.maxValue,
|
|
160
|
-
minValue: cfg.minValue,
|
|
161
|
-
min_value: cfg.minValue,
|
|
162
|
-
required: cfg.required,
|
|
163
|
-
validate: cfg.validate,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
numberChoices(
|
|
168
|
-
cfg: TDBIBaseOption &
|
|
169
|
-
TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
|
|
170
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
171
|
-
number,
|
|
172
|
-
"Result",
|
|
173
|
-
boolean
|
|
174
|
-
>
|
|
175
|
-
) {
|
|
176
|
-
return {
|
|
177
|
-
type: Discord.ApplicationCommandOptionType.Number,
|
|
178
|
-
name: cfg.name,
|
|
179
|
-
choices: cfg.choices,
|
|
180
|
-
description: cfg.description,
|
|
181
|
-
maxValue: cfg.maxValue,
|
|
182
|
-
max_value: cfg.maxValue,
|
|
183
|
-
minValue: cfg.minValue,
|
|
184
|
-
min_value: cfg.minValue,
|
|
185
|
-
required: cfg.required,
|
|
186
|
-
validate: cfg.validate,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
number(
|
|
191
|
-
cfg: TDBIBaseOption &
|
|
192
|
-
TDBIMinMaxValue &
|
|
193
|
-
TDBIValidator<
|
|
194
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
195
|
-
number,
|
|
196
|
-
"Result",
|
|
197
|
-
boolean
|
|
198
|
-
>
|
|
199
|
-
) {
|
|
200
|
-
return {
|
|
201
|
-
type: Discord.ApplicationCommandOptionType.Number,
|
|
202
|
-
name: cfg.name,
|
|
203
|
-
description: cfg.description,
|
|
204
|
-
maxValue: cfg.maxValue,
|
|
205
|
-
max_value: cfg.maxValue,
|
|
206
|
-
minValue: cfg.minValue,
|
|
207
|
-
min_value: cfg.minValue,
|
|
208
|
-
required: cfg.required,
|
|
209
|
-
validate: cfg.validate,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
integerAutocomplete(
|
|
214
|
-
cfg: TDBIBaseOption &
|
|
215
|
-
TDBIMinMaxValue &
|
|
216
|
-
TDBIValidator<
|
|
217
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
218
|
-
number,
|
|
219
|
-
"Autocomplete" | "Result",
|
|
220
|
-
boolean | TDBIValueName<number>
|
|
221
|
-
> &
|
|
222
|
-
TDBICompleter<TNamespace, number>
|
|
223
|
-
) {
|
|
224
|
-
return {
|
|
225
|
-
type: Discord.ApplicationCommandOptionType.Integer,
|
|
226
|
-
name: cfg.name,
|
|
227
|
-
autocomplete: true,
|
|
228
|
-
onComplete: cfg.onComplete,
|
|
229
|
-
description: cfg.description,
|
|
230
|
-
maxValue: cfg.maxValue,
|
|
231
|
-
max_value: cfg.maxValue,
|
|
232
|
-
minValue: cfg.minValue,
|
|
233
|
-
min_value: cfg.minValue,
|
|
234
|
-
required: cfg.required,
|
|
235
|
-
validate: cfg.validate,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
integerChoices(
|
|
240
|
-
cfg: TDBIBaseOption &
|
|
241
|
-
TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
|
|
242
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
243
|
-
number,
|
|
244
|
-
"Result",
|
|
245
|
-
boolean
|
|
246
|
-
>
|
|
247
|
-
) {
|
|
248
|
-
return {
|
|
249
|
-
type: Discord.ApplicationCommandOptionType.Integer,
|
|
250
|
-
name: cfg.name,
|
|
251
|
-
choices: cfg.choices,
|
|
252
|
-
description: cfg.description,
|
|
253
|
-
maxValue: cfg.maxValue,
|
|
254
|
-
max_value: cfg.maxValue,
|
|
255
|
-
minValue: cfg.minValue,
|
|
256
|
-
min_value: cfg.minValue,
|
|
257
|
-
required: cfg.required,
|
|
258
|
-
validate: cfg.validate,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
integer(
|
|
263
|
-
cfg: TDBIBaseOption &
|
|
264
|
-
TDBIMinMaxValue &
|
|
265
|
-
TDBIValidator<
|
|
266
|
-
TDBIValidateCtx<TNamespace, number>,
|
|
267
|
-
number,
|
|
268
|
-
"Result",
|
|
269
|
-
boolean
|
|
270
|
-
>
|
|
271
|
-
) {
|
|
272
|
-
return {
|
|
273
|
-
type: Discord.ApplicationCommandOptionType.Integer,
|
|
274
|
-
name: cfg.name,
|
|
275
|
-
description: cfg.description,
|
|
276
|
-
maxValue: cfg.maxValue,
|
|
277
|
-
max_value: cfg.maxValue,
|
|
278
|
-
minValue: cfg.minValue,
|
|
279
|
-
min_value: cfg.minValue,
|
|
280
|
-
required: cfg.required,
|
|
281
|
-
validate: cfg.validate,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
boolean(cfg: TDBIBaseOption) {
|
|
286
|
-
return {
|
|
287
|
-
type: Discord.ApplicationCommandOptionType.Boolean,
|
|
288
|
-
name: cfg.name,
|
|
289
|
-
description: cfg.description,
|
|
290
|
-
required: cfg.required,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
attachment(
|
|
295
|
-
cfg: TDBIBaseOption &
|
|
296
|
-
TDBIValidator<
|
|
297
|
-
TDBIValidateCtx<TNamespace, Discord.Attachment>,
|
|
298
|
-
Discord.Attachment,
|
|
299
|
-
"Result",
|
|
300
|
-
boolean
|
|
301
|
-
>
|
|
302
|
-
) {
|
|
303
|
-
return {
|
|
304
|
-
type: Discord.ApplicationCommandOptionType.Attachment,
|
|
305
|
-
name: cfg.name,
|
|
306
|
-
description: cfg.description,
|
|
307
|
-
required: cfg.required,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
channel(
|
|
312
|
-
cfg: TDBIBaseOption & {
|
|
313
|
-
channelTypes: Discord.ChannelType[];
|
|
314
|
-
} & TDBIValidator<
|
|
315
|
-
TDBIValidateCtx<TNamespace, Discord.Channel>,
|
|
316
|
-
Discord.Channel,
|
|
317
|
-
"Result",
|
|
318
|
-
boolean
|
|
319
|
-
>
|
|
320
|
-
) {
|
|
321
|
-
return {
|
|
322
|
-
type: Discord.ApplicationCommandOptionType.Channel,
|
|
323
|
-
name: cfg.name,
|
|
324
|
-
description: cfg.description,
|
|
325
|
-
channelTypes: cfg.channelTypes,
|
|
326
|
-
channel_types: cfg.channelTypes,
|
|
327
|
-
required: cfg.required,
|
|
328
|
-
validate: cfg.validate,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
role(
|
|
333
|
-
cfg: TDBIBaseOption &
|
|
334
|
-
TDBIValidator<
|
|
335
|
-
TDBIValidateCtx<TNamespace, Discord.Role>,
|
|
336
|
-
Discord.Role,
|
|
337
|
-
"Result",
|
|
338
|
-
boolean
|
|
339
|
-
>
|
|
340
|
-
) {
|
|
341
|
-
return {
|
|
342
|
-
type: Discord.ApplicationCommandOptionType.Role,
|
|
343
|
-
name: cfg.name,
|
|
344
|
-
description: cfg.description,
|
|
345
|
-
required: cfg.required,
|
|
346
|
-
validate: cfg.validate,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
mentionable(
|
|
351
|
-
cfg: TDBIBaseOption &
|
|
352
|
-
TDBIValidator<
|
|
353
|
-
TDBIValidateCtx<
|
|
354
|
-
TNamespace,
|
|
355
|
-
Discord.Role | Discord.Channel | Discord.User
|
|
356
|
-
>,
|
|
357
|
-
Discord.Role | Discord.Channel | Discord.User,
|
|
358
|
-
"Result",
|
|
359
|
-
boolean
|
|
360
|
-
>
|
|
361
|
-
) {
|
|
362
|
-
return {
|
|
363
|
-
type: Discord.ApplicationCommandOptionType.Mentionable,
|
|
364
|
-
name: cfg.name,
|
|
365
|
-
description: cfg.description,
|
|
366
|
-
required: cfg.required,
|
|
367
|
-
validate: cfg.validate,
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
user(
|
|
372
|
-
cfg: TDBIBaseOption &
|
|
373
|
-
TDBIValidator<
|
|
374
|
-
TDBIValidateCtx<TNamespace, Discord.User>,
|
|
375
|
-
Discord.User,
|
|
376
|
-
"Result",
|
|
377
|
-
boolean
|
|
378
|
-
>
|
|
379
|
-
) {
|
|
380
|
-
return {
|
|
381
|
-
type: Discord.ApplicationCommandOptionType.User,
|
|
382
|
-
name: cfg.name,
|
|
383
|
-
description: cfg.description,
|
|
384
|
-
required: cfg.required,
|
|
385
|
-
validate: cfg.validate,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
}
|
|
1
|
+
import Discord from "discord.js";
|
|
2
|
+
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
3
|
+
import { DBI } from "../../DBI";
|
|
4
|
+
import { IDBIBaseExecuteCtx } from "../Interaction";
|
|
5
|
+
|
|
6
|
+
export type TDBIValueName<T> = { value: T; name: string };
|
|
7
|
+
export type TDBIBaseOption = {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type TDBIMinMaxLength = { maxLength?: number; minLength?: number };
|
|
14
|
+
export type TDBIMinMaxValue = { maxValue?: number; minValue?: number };
|
|
15
|
+
|
|
16
|
+
export type TDBIValidator<
|
|
17
|
+
TExtends,
|
|
18
|
+
TValue,
|
|
19
|
+
TStep extends string,
|
|
20
|
+
TExpectedResponse = boolean
|
|
21
|
+
> = {
|
|
22
|
+
validate?(
|
|
23
|
+
cfg: TExtends & { value: TValue; step: TStep }
|
|
24
|
+
): Promise<TExpectedResponse> | TExpectedResponse;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface IDBIValuedInteraction<
|
|
28
|
+
TNamespace extends NamespaceEnums,
|
|
29
|
+
TInteractionType extends Discord.Interaction,
|
|
30
|
+
TValueType = string | number
|
|
31
|
+
> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
32
|
+
value: TValueType;
|
|
33
|
+
interaction: TInteractionType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type TDBICompleteCtx<
|
|
37
|
+
TNamespace extends NamespaceEnums,
|
|
38
|
+
TValueType = string | number
|
|
39
|
+
> = IDBIValuedInteraction<
|
|
40
|
+
TNamespace,
|
|
41
|
+
Discord.AutocompleteInteraction,
|
|
42
|
+
TValueType
|
|
43
|
+
>;
|
|
44
|
+
|
|
45
|
+
export type TDBIValidateCtx<
|
|
46
|
+
TNamespace extends NamespaceEnums,
|
|
47
|
+
TValueType = string | number
|
|
48
|
+
> = IDBIValuedInteraction<TNamespace, Discord.Interaction, TValueType>;
|
|
49
|
+
|
|
50
|
+
export type TDBICompleter<
|
|
51
|
+
TNamespace extends NamespaceEnums,
|
|
52
|
+
TValueType extends number | string
|
|
53
|
+
> = {
|
|
54
|
+
onComplete(
|
|
55
|
+
ctx: TDBICompleteCtx<TNamespace, string>
|
|
56
|
+
): Promise<TDBIValueName<TValueType>[]> | TDBIValueName<TValueType>[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
|
|
60
|
+
dbi: DBI<TNamespace>;
|
|
61
|
+
constructor(dbi: DBI<TNamespace>) {
|
|
62
|
+
this.dbi = dbi;
|
|
63
|
+
}
|
|
64
|
+
stringAutocomplete(
|
|
65
|
+
cfg: TDBIBaseOption &
|
|
66
|
+
TDBIMinMaxLength & {
|
|
67
|
+
messageCommands?: { rest?: boolean };
|
|
68
|
+
} & TDBIValidator<
|
|
69
|
+
TDBIValidateCtx<TNamespace, string>,
|
|
70
|
+
string,
|
|
71
|
+
"Autocomplete" | "Result",
|
|
72
|
+
boolean | TDBIValueName<string>
|
|
73
|
+
> &
|
|
74
|
+
TDBICompleter<TNamespace, string>
|
|
75
|
+
) {
|
|
76
|
+
return {
|
|
77
|
+
type: Discord.ApplicationCommandOptionType.String,
|
|
78
|
+
name: cfg.name,
|
|
79
|
+
autocomplete: true,
|
|
80
|
+
onComplete: cfg.onComplete,
|
|
81
|
+
description: cfg.description,
|
|
82
|
+
maxLength: cfg.maxLength,
|
|
83
|
+
max_length: cfg.maxLength,
|
|
84
|
+
minLength: cfg.minLength,
|
|
85
|
+
min_length: cfg.minLength,
|
|
86
|
+
required: cfg.required,
|
|
87
|
+
validate: cfg.validate,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
stringChoices(
|
|
91
|
+
cfg: TDBIBaseOption &
|
|
92
|
+
TDBIMinMaxLength & {
|
|
93
|
+
choices: TDBIValueName<string>[];
|
|
94
|
+
messageCommands?: { rest?: boolean };
|
|
95
|
+
} & TDBIValidator<
|
|
96
|
+
TDBIValidateCtx<TNamespace, string>,
|
|
97
|
+
string,
|
|
98
|
+
"Result",
|
|
99
|
+
boolean
|
|
100
|
+
>
|
|
101
|
+
) {
|
|
102
|
+
return {
|
|
103
|
+
type: Discord.ApplicationCommandOptionType.String,
|
|
104
|
+
name: cfg.name,
|
|
105
|
+
choices: cfg.choices,
|
|
106
|
+
description: cfg.description,
|
|
107
|
+
maxLength: cfg.maxLength,
|
|
108
|
+
max_length: cfg.maxLength,
|
|
109
|
+
minLength: cfg.minLength,
|
|
110
|
+
min_length: cfg.minLength,
|
|
111
|
+
required: cfg.required,
|
|
112
|
+
validate: cfg.validate,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
string(
|
|
117
|
+
cfg: TDBIBaseOption &
|
|
118
|
+
TDBIMinMaxLength & {
|
|
119
|
+
messageCommands?: { rest?: boolean };
|
|
120
|
+
} & TDBIValidator<
|
|
121
|
+
TDBIValidateCtx<TNamespace, string>,
|
|
122
|
+
string,
|
|
123
|
+
"Result",
|
|
124
|
+
boolean
|
|
125
|
+
>
|
|
126
|
+
) {
|
|
127
|
+
return {
|
|
128
|
+
type: Discord.ApplicationCommandOptionType.String,
|
|
129
|
+
name: cfg.name,
|
|
130
|
+
description: cfg.description,
|
|
131
|
+
maxLength: cfg.maxLength,
|
|
132
|
+
max_length: cfg.maxLength,
|
|
133
|
+
minLength: cfg.minLength,
|
|
134
|
+
min_length: cfg.minLength,
|
|
135
|
+
required: cfg.required,
|
|
136
|
+
messageCommands: cfg.messageCommands,
|
|
137
|
+
validate: cfg.validate,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
numberAutocomplete(
|
|
142
|
+
cfg: TDBIBaseOption &
|
|
143
|
+
TDBIMinMaxValue &
|
|
144
|
+
TDBIValidator<
|
|
145
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
146
|
+
number,
|
|
147
|
+
"Autocomplete" | "Result",
|
|
148
|
+
boolean | TDBIValueName<number>
|
|
149
|
+
> &
|
|
150
|
+
TDBICompleter<TNamespace, number>
|
|
151
|
+
) {
|
|
152
|
+
return {
|
|
153
|
+
type: Discord.ApplicationCommandOptionType.Number,
|
|
154
|
+
name: cfg.name,
|
|
155
|
+
autocomplete: true,
|
|
156
|
+
onComplete: cfg.onComplete,
|
|
157
|
+
description: cfg.description,
|
|
158
|
+
maxValue: cfg.maxValue,
|
|
159
|
+
max_value: cfg.maxValue,
|
|
160
|
+
minValue: cfg.minValue,
|
|
161
|
+
min_value: cfg.minValue,
|
|
162
|
+
required: cfg.required,
|
|
163
|
+
validate: cfg.validate,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
numberChoices(
|
|
168
|
+
cfg: TDBIBaseOption &
|
|
169
|
+
TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
|
|
170
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
171
|
+
number,
|
|
172
|
+
"Result",
|
|
173
|
+
boolean
|
|
174
|
+
>
|
|
175
|
+
) {
|
|
176
|
+
return {
|
|
177
|
+
type: Discord.ApplicationCommandOptionType.Number,
|
|
178
|
+
name: cfg.name,
|
|
179
|
+
choices: cfg.choices,
|
|
180
|
+
description: cfg.description,
|
|
181
|
+
maxValue: cfg.maxValue,
|
|
182
|
+
max_value: cfg.maxValue,
|
|
183
|
+
minValue: cfg.minValue,
|
|
184
|
+
min_value: cfg.minValue,
|
|
185
|
+
required: cfg.required,
|
|
186
|
+
validate: cfg.validate,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
number(
|
|
191
|
+
cfg: TDBIBaseOption &
|
|
192
|
+
TDBIMinMaxValue &
|
|
193
|
+
TDBIValidator<
|
|
194
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
195
|
+
number,
|
|
196
|
+
"Result",
|
|
197
|
+
boolean
|
|
198
|
+
>
|
|
199
|
+
) {
|
|
200
|
+
return {
|
|
201
|
+
type: Discord.ApplicationCommandOptionType.Number,
|
|
202
|
+
name: cfg.name,
|
|
203
|
+
description: cfg.description,
|
|
204
|
+
maxValue: cfg.maxValue,
|
|
205
|
+
max_value: cfg.maxValue,
|
|
206
|
+
minValue: cfg.minValue,
|
|
207
|
+
min_value: cfg.minValue,
|
|
208
|
+
required: cfg.required,
|
|
209
|
+
validate: cfg.validate,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
integerAutocomplete(
|
|
214
|
+
cfg: TDBIBaseOption &
|
|
215
|
+
TDBIMinMaxValue &
|
|
216
|
+
TDBIValidator<
|
|
217
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
218
|
+
number,
|
|
219
|
+
"Autocomplete" | "Result",
|
|
220
|
+
boolean | TDBIValueName<number>
|
|
221
|
+
> &
|
|
222
|
+
TDBICompleter<TNamespace, number>
|
|
223
|
+
) {
|
|
224
|
+
return {
|
|
225
|
+
type: Discord.ApplicationCommandOptionType.Integer,
|
|
226
|
+
name: cfg.name,
|
|
227
|
+
autocomplete: true,
|
|
228
|
+
onComplete: cfg.onComplete,
|
|
229
|
+
description: cfg.description,
|
|
230
|
+
maxValue: cfg.maxValue,
|
|
231
|
+
max_value: cfg.maxValue,
|
|
232
|
+
minValue: cfg.minValue,
|
|
233
|
+
min_value: cfg.minValue,
|
|
234
|
+
required: cfg.required,
|
|
235
|
+
validate: cfg.validate,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
integerChoices(
|
|
240
|
+
cfg: TDBIBaseOption &
|
|
241
|
+
TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
|
|
242
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
243
|
+
number,
|
|
244
|
+
"Result",
|
|
245
|
+
boolean
|
|
246
|
+
>
|
|
247
|
+
) {
|
|
248
|
+
return {
|
|
249
|
+
type: Discord.ApplicationCommandOptionType.Integer,
|
|
250
|
+
name: cfg.name,
|
|
251
|
+
choices: cfg.choices,
|
|
252
|
+
description: cfg.description,
|
|
253
|
+
maxValue: cfg.maxValue,
|
|
254
|
+
max_value: cfg.maxValue,
|
|
255
|
+
minValue: cfg.minValue,
|
|
256
|
+
min_value: cfg.minValue,
|
|
257
|
+
required: cfg.required,
|
|
258
|
+
validate: cfg.validate,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
integer(
|
|
263
|
+
cfg: TDBIBaseOption &
|
|
264
|
+
TDBIMinMaxValue &
|
|
265
|
+
TDBIValidator<
|
|
266
|
+
TDBIValidateCtx<TNamespace, number>,
|
|
267
|
+
number,
|
|
268
|
+
"Result",
|
|
269
|
+
boolean
|
|
270
|
+
>
|
|
271
|
+
) {
|
|
272
|
+
return {
|
|
273
|
+
type: Discord.ApplicationCommandOptionType.Integer,
|
|
274
|
+
name: cfg.name,
|
|
275
|
+
description: cfg.description,
|
|
276
|
+
maxValue: cfg.maxValue,
|
|
277
|
+
max_value: cfg.maxValue,
|
|
278
|
+
minValue: cfg.minValue,
|
|
279
|
+
min_value: cfg.minValue,
|
|
280
|
+
required: cfg.required,
|
|
281
|
+
validate: cfg.validate,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
boolean(cfg: TDBIBaseOption) {
|
|
286
|
+
return {
|
|
287
|
+
type: Discord.ApplicationCommandOptionType.Boolean,
|
|
288
|
+
name: cfg.name,
|
|
289
|
+
description: cfg.description,
|
|
290
|
+
required: cfg.required,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
attachment(
|
|
295
|
+
cfg: TDBIBaseOption &
|
|
296
|
+
TDBIValidator<
|
|
297
|
+
TDBIValidateCtx<TNamespace, Discord.Attachment>,
|
|
298
|
+
Discord.Attachment,
|
|
299
|
+
"Result",
|
|
300
|
+
boolean
|
|
301
|
+
>
|
|
302
|
+
) {
|
|
303
|
+
return {
|
|
304
|
+
type: Discord.ApplicationCommandOptionType.Attachment,
|
|
305
|
+
name: cfg.name,
|
|
306
|
+
description: cfg.description,
|
|
307
|
+
required: cfg.required,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
channel(
|
|
312
|
+
cfg: TDBIBaseOption & {
|
|
313
|
+
channelTypes: Discord.ChannelType[];
|
|
314
|
+
} & TDBIValidator<
|
|
315
|
+
TDBIValidateCtx<TNamespace, Discord.Channel>,
|
|
316
|
+
Discord.Channel,
|
|
317
|
+
"Result",
|
|
318
|
+
boolean
|
|
319
|
+
>
|
|
320
|
+
) {
|
|
321
|
+
return {
|
|
322
|
+
type: Discord.ApplicationCommandOptionType.Channel,
|
|
323
|
+
name: cfg.name,
|
|
324
|
+
description: cfg.description,
|
|
325
|
+
channelTypes: cfg.channelTypes,
|
|
326
|
+
channel_types: cfg.channelTypes,
|
|
327
|
+
required: cfg.required,
|
|
328
|
+
validate: cfg.validate,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
role(
|
|
333
|
+
cfg: TDBIBaseOption &
|
|
334
|
+
TDBIValidator<
|
|
335
|
+
TDBIValidateCtx<TNamespace, Discord.Role>,
|
|
336
|
+
Discord.Role,
|
|
337
|
+
"Result",
|
|
338
|
+
boolean
|
|
339
|
+
>
|
|
340
|
+
) {
|
|
341
|
+
return {
|
|
342
|
+
type: Discord.ApplicationCommandOptionType.Role,
|
|
343
|
+
name: cfg.name,
|
|
344
|
+
description: cfg.description,
|
|
345
|
+
required: cfg.required,
|
|
346
|
+
validate: cfg.validate,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
mentionable(
|
|
351
|
+
cfg: TDBIBaseOption &
|
|
352
|
+
TDBIValidator<
|
|
353
|
+
TDBIValidateCtx<
|
|
354
|
+
TNamespace,
|
|
355
|
+
Discord.Role | Discord.Channel | Discord.User
|
|
356
|
+
>,
|
|
357
|
+
Discord.Role | Discord.Channel | Discord.User,
|
|
358
|
+
"Result",
|
|
359
|
+
boolean
|
|
360
|
+
>
|
|
361
|
+
) {
|
|
362
|
+
return {
|
|
363
|
+
type: Discord.ApplicationCommandOptionType.Mentionable,
|
|
364
|
+
name: cfg.name,
|
|
365
|
+
description: cfg.description,
|
|
366
|
+
required: cfg.required,
|
|
367
|
+
validate: cfg.validate,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
user(
|
|
372
|
+
cfg: TDBIBaseOption &
|
|
373
|
+
TDBIValidator<
|
|
374
|
+
TDBIValidateCtx<TNamespace, Discord.User>,
|
|
375
|
+
Discord.User,
|
|
376
|
+
"Result",
|
|
377
|
+
boolean
|
|
378
|
+
>
|
|
379
|
+
) {
|
|
380
|
+
return {
|
|
381
|
+
type: Discord.ApplicationCommandOptionType.User,
|
|
382
|
+
name: cfg.name,
|
|
383
|
+
description: cfg.description,
|
|
384
|
+
required: cfg.required,
|
|
385
|
+
validate: cfg.validate,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|