@mostfeatured/dbi 0.1.1 → 0.1.3

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.
@@ -1,59 +1,115 @@
1
1
  import { DBI } from "../DBI";
2
- import Discord from "discord.js";
2
+ import Discord, { CommandInteractionOption } from "discord.js";
3
3
  import { parseCustomId } from "../utils/customId";
4
4
  import { NamespaceEnums } from "../../generated/namespaceData";
5
5
 
6
- const componentTypes = ["Button", "StringSelectMenu", "UserSelectMenu", "RoleSelectMenu", "ChannelSelectMenu", "MentionableSelectMenu", "Modal"]
6
+ const componentTypes = [
7
+ "Button",
8
+ "StringSelectMenu",
9
+ "UserSelectMenu",
10
+ "RoleSelectMenu",
11
+ "ChannelSelectMenu",
12
+ "MentionableSelectMenu",
13
+ "Modal",
14
+ ];
7
15
 
8
16
  export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
9
17
  async function handle(inter: Discord.Interaction<"cached">) {
10
18
  const dbiInter =
11
- (inter as any).dbiChatInput ?? dbi.data.interactions.find(i => {
12
- let isUsesCustomId = (inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit());
13
- let parsedId = isUsesCustomId ? parseCustomId(dbi, (inter as any).customId) : null;
19
+ (inter as any).dbiChatInput ??
20
+ dbi.data.interactions.find((i) => {
21
+ let isUsesCustomId =
22
+ inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit();
23
+ let parsedId = isUsesCustomId
24
+ ? parseCustomId(dbi, (inter as any).customId)
25
+ : null;
14
26
  return (
15
- (
16
- i.type == "ChatInput"
17
- && (inter.isChatInputCommand() || inter.isAutocomplete())
18
- && i.name == [inter.commandName, inter.options.getSubcommandGroup(false), inter.options.getSubcommand(false)].filter(i => !!i).join(" ")
19
- )
20
- ||
21
- (
22
- (i.type == "MessageContextMenu" || i.type == "UserContextMenu")
23
- && (inter.isMessageContextMenuCommand() || inter.isUserContextMenuCommand())
24
- && inter.commandName == i.name
25
- )
26
- ||
27
- (
28
- componentTypes.includes(i.type)
29
- && isUsesCustomId
30
- && parsedId?.name == i.name
31
- )
32
- )
27
+ (i.type == "ChatInput" &&
28
+ (inter.isChatInputCommand() || inter.isAutocomplete()) &&
29
+ i.name ==
30
+ [
31
+ inter.commandName,
32
+ inter.options.getSubcommandGroup(false),
33
+ inter.options.getSubcommand(false),
34
+ ]
35
+ .filter((i) => !!i)
36
+ .join(" ")) ||
37
+ ((i.type == "MessageContextMenu" || i.type == "UserContextMenu") &&
38
+ (inter.isMessageContextMenuCommand() ||
39
+ inter.isUserContextMenuCommand()) &&
40
+ inter.commandName == i.name) ||
41
+ (componentTypes.includes(i.type) &&
42
+ isUsesCustomId &&
43
+ parsedId?.name == i.name)
44
+ );
33
45
  });
34
-
46
+
35
47
  if (!dbiInter) return;
36
48
 
37
49
  let userLocaleName = inter.locale.split("-")[0];
38
- let userLocale = dbi.data.locales.has(userLocaleName) ? dbi.data.locales.get(userLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale);
39
-
40
- let guildLocaleName = inter.guild ? inter.guild.preferredLocale.split("-")[0] : null;
41
- let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
50
+ let userLocale = dbi.data.locales.has(userLocaleName)
51
+ ? dbi.data.locales.get(userLocaleName)
52
+ : dbi.data.locales.get(dbi.config.defaults.locale);
53
+
54
+ let guildLocaleName = inter.guild
55
+ ? inter.guild.preferredLocale.split("-")[0]
56
+ : null;
57
+ let guildLocale = guildLocaleName
58
+ ? dbi.data.locales.has(guildLocaleName)
59
+ ? dbi.data.locales.get(guildLocaleName)
60
+ : dbi.data.locales.get(dbi.config.defaults.locale)
61
+ : null;
42
62
 
43
63
  let locale = {
44
64
  user: userLocale,
45
- guild: guildLocale
65
+ guild: guildLocale,
46
66
  };
47
67
 
48
- let data = (inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit()) ? parseCustomId(dbi, inter.customId).data : undefined;
68
+ let data =
69
+ inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit()
70
+ ? parseCustomId(dbi, inter.customId).data
71
+ : undefined;
49
72
 
50
73
  let other = {};
51
74
 
52
- if (!(await dbi.events.trigger("beforeInteraction", { dbi, interaction: inter, locale, setRateLimit, data, other, dbiInteraction: dbiInter }))) return;
53
-
75
+ if (
76
+ !(await dbi.events.trigger("beforeInteraction", {
77
+ dbi,
78
+ interaction: inter,
79
+ locale,
80
+ setRateLimit,
81
+ data,
82
+ other,
83
+ dbiInteraction: dbiInter,
84
+ }))
85
+ )
86
+ return;
87
+
54
88
  if (inter.isAutocomplete()) {
55
89
  let focussed = inter.options.getFocused(true);
56
- let option = (dbiInter.options as any[]).find(i => i.name == focussed.name);
90
+ let option = (dbiInter.options as any[]).find(
91
+ (i) => i.name == focussed.name
92
+ );
93
+ if (option?.validate) {
94
+ const res = await option.validate({
95
+ value: focussed.value,
96
+ interaction: inter,
97
+ dbiInteraction: dbiInter,
98
+ dbi,
99
+ data,
100
+ other,
101
+ locale,
102
+ step: "Autocomplete",
103
+ });
104
+
105
+ if (Array.isArray(res) && res.length > 0) {
106
+ await inter.respond(res);
107
+ return;
108
+ }
109
+
110
+ if (res !== true) return;
111
+ }
112
+
57
113
  if (option?.onComplete) {
58
114
  let response = await option.onComplete({
59
115
  value: focussed.value,
@@ -62,7 +118,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
62
118
  dbi,
63
119
  data,
64
120
  other,
65
- locale
121
+ locale,
66
122
  });
67
123
  await inter.respond(response);
68
124
  }
@@ -70,12 +126,12 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
70
126
  }
71
127
 
72
128
  let rateLimitKeyMap = {
73
- "User": `${dbiInter.name}_${inter.user.id}`,
74
- "Channel": `${dbiInter.name}_${inter.channelId || "Channel"}`,
75
- "Guild": `${dbiInter.name}_${inter.guildId || "Guild"}`,
76
- "Member": `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
77
- "Message": `${dbiInter.name}_${(inter as any)?.message?.id}`
78
- }
129
+ User: `${dbiInter.name}_${inter.user.id}`,
130
+ Channel: `${dbiInter.name}_${inter.channelId || "Channel"}`,
131
+ Guild: `${dbiInter.name}_${inter.guildId || "Guild"}`,
132
+ Member: `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
133
+ Message: `${dbiInter.name}_${(inter as any)?.message?.id}`,
134
+ };
79
135
 
80
136
  for (const type in rateLimitKeyMap) {
81
137
  // @ts-ignore
@@ -86,29 +142,57 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
86
142
  val = null;
87
143
  }
88
144
  if (val) {
89
- if ((await dbi.events.trigger("interactionRateLimit", {
90
- dbi,
91
- interaction: inter,
92
- dbiInteraction: dbiInter,
93
- locale,
94
- data,
95
- rateLimit: {
96
- type: key,
97
- ...val
98
- }
99
- })) === true) return;
145
+ if (
146
+ (await dbi.events.trigger("interactionRateLimit", {
147
+ dbi,
148
+ interaction: inter,
149
+ dbiInteraction: dbiInter,
150
+ locale,
151
+ data,
152
+ rateLimit: {
153
+ type: key,
154
+ ...val,
155
+ },
156
+ })) === true
157
+ )
158
+ return;
100
159
  }
101
160
  }
102
161
 
103
162
  async function setRateLimit(type: string, duration: number) {
104
163
  // @ts-ignore
105
- await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, { at: Date.now(), duration });
164
+ await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, {
165
+ at: Date.now(),
166
+ duration,
167
+ });
106
168
  }
107
169
 
108
170
  for (const rateLimit of dbiInter.rateLimits) {
109
171
  await setRateLimit(rateLimit.type, rateLimit.duration);
110
172
  }
111
173
 
174
+ if (inter.isChatInputCommand()) {
175
+ let dcOptions = (inter.options as any)
176
+ ._hoistedOptions as CommandInteractionOption[];
177
+ let dbiOptions = dbiInter.options as any[];
178
+ for (const dcOption of dcOptions) {
179
+ const dbiOption = dbiOptions.find((i) => i.name == dcOption.name);
180
+ if (dbiOption?.validate) {
181
+ const res = await dbiOption.validate({
182
+ value: dcOption.value,
183
+ interaction: inter,
184
+ dbiInteraction: dbiInter,
185
+ dbi,
186
+ data,
187
+ other,
188
+ locale,
189
+ step: "Result",
190
+ });
191
+ if (res !== true) return;
192
+ }
193
+ }
194
+ }
195
+
112
196
  let arg = {
113
197
  // @ts-ignore
114
198
  dbi,
@@ -123,7 +207,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
123
207
  // @ts-ignore
124
208
  data,
125
209
  // @ts-ignore
126
- other
210
+ other,
127
211
  };
128
212
 
129
213
  if (dbi.config.strict) {
@@ -135,21 +219,32 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
135
219
  await dbiInter.onExecute(arg);
136
220
  } catch (error) {
137
221
  // @ts-ignore
138
- await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
222
+ await dbi.events.trigger(
223
+ "interactionError",
224
+ Object.assign(arg, { error })
225
+ );
139
226
  }
140
227
  }
141
-
228
+
142
229
  // @ts-ignore
143
- dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
230
+ dbi.events.trigger("afterInteraction", {
231
+ dbi,
232
+ interaction: inter,
233
+ dbiInteraction: dbiInter,
234
+ locale,
235
+ setRateLimit,
236
+ data,
237
+ other,
238
+ });
144
239
  }
145
240
 
146
- dbi.data.clients.forEach(d=>{
241
+ dbi.data.clients.forEach((d) => {
147
242
  d.client.on("interactionCreate", handle);
148
243
  });
149
244
 
150
- return () => {
151
- dbi.data.clients.forEach(d=>{
245
+ return () => {
246
+ dbi.data.clients.forEach((d) => {
152
247
  d.client.off("interactionCreate", handle);
153
248
  });
154
249
  };
155
- }
250
+ }
@@ -3,23 +3,76 @@ import { NamespaceEnums } from "../../../generated/namespaceData";
3
3
  import { DBI } from "../../DBI";
4
4
  import { IDBIBaseExecuteCtx } from "../Interaction";
5
5
 
6
- export type TDBIValueName<T> = { value: T, name: string };
7
- export type TDBIBaseOption = { name: string, description: string, required?: boolean };
6
+ export type TDBIValueName<T> = { value: T; name: string };
7
+ export type TDBIBaseOption = {
8
+ name: string;
9
+ description: string;
10
+ required?: boolean;
11
+ };
8
12
 
9
- export type TDBIMinMaxLength = { maxLength?: number, minLength?: number };
10
- export type TDBIMinMaxValue = { maxValue?: number, minValue?: number };
13
+ export type TDBIMinMaxLength = { maxLength?: number; minLength?: number };
14
+ export type TDBIMinMaxValue = { maxValue?: number; minValue?: number };
11
15
 
12
- export interface IDBICompleteCtx<TNamespace extends NamespaceEnums, TValueType = string | number> extends IDBIBaseExecuteCtx<TNamespace> {
13
- interaction: Discord.AutocompleteInteraction;
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> {
14
32
  value: TValueType;
33
+ interaction: TInteractionType;
15
34
  }
16
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
+
17
59
  export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
18
60
  dbi: DBI<TNamespace>;
19
61
  constructor(dbi: DBI<TNamespace>) {
20
62
  this.dbi = dbi;
21
63
  }
22
- stringAutocomplete(cfg: TDBIBaseOption & TDBIMinMaxLength & { onComplete(ctx: IDBICompleteCtx<TNamespace, string>): Promise<TDBIValueName<string>[]> | TDBIValueName<string>[], messageCommands?: { rest?: boolean } }) {
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
+ ) {
23
76
  return {
24
77
  type: Discord.ApplicationCommandOptionType.String,
25
78
  name: cfg.name,
@@ -30,10 +83,22 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
30
83
  max_length: cfg.maxLength,
31
84
  minLength: cfg.minLength,
32
85
  min_length: cfg.minLength,
33
- required: cfg.required
86
+ required: cfg.required,
87
+ validate: cfg.validate,
34
88
  };
35
89
  }
36
- stringChoices(cfg: TDBIBaseOption & TDBIMinMaxLength & { choices: TDBIValueName<string>[], messageCommands?: { rest?: boolean } }) {
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
+ ) {
37
102
  return {
38
103
  type: Discord.ApplicationCommandOptionType.String,
39
104
  name: cfg.name,
@@ -43,11 +108,22 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
43
108
  max_length: cfg.maxLength,
44
109
  minLength: cfg.minLength,
45
110
  min_length: cfg.minLength,
46
- required: cfg.required
111
+ required: cfg.required,
112
+ validate: cfg.validate,
47
113
  };
48
114
  }
49
115
 
50
- string(cfg: TDBIBaseOption & TDBIMinMaxLength & { messageCommands?: { rest?: boolean } }) {
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
+ ) {
51
127
  return {
52
128
  type: Discord.ApplicationCommandOptionType.String,
53
129
  name: cfg.name,
@@ -57,11 +133,22 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
57
133
  minLength: cfg.minLength,
58
134
  min_length: cfg.minLength,
59
135
  required: cfg.required,
60
- messageCommands: cfg.messageCommands
136
+ messageCommands: cfg.messageCommands,
137
+ validate: cfg.validate,
61
138
  };
62
139
  }
63
140
 
64
- numberAutocomplete(cfg: TDBIBaseOption & TDBIMinMaxValue & { onComplete(ctx: IDBICompleteCtx<TNamespace, string>): Promise<TDBIValueName<number>[]> | TDBIValueName<number>[] }) {
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
+ ) {
65
152
  return {
66
153
  type: Discord.ApplicationCommandOptionType.Number,
67
154
  name: cfg.name,
@@ -72,11 +159,20 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
72
159
  max_value: cfg.maxValue,
73
160
  minValue: cfg.minValue,
74
161
  min_value: cfg.minValue,
75
- required: cfg.required
162
+ required: cfg.required,
163
+ validate: cfg.validate,
76
164
  };
77
165
  }
78
166
 
79
- numberChoices(cfg: TDBIBaseOption & TDBIMinMaxValue & { choices: TDBIValueName<number>[] }) {
167
+ numberChoices(
168
+ cfg: TDBIBaseOption &
169
+ TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
170
+ TDBIValidateCtx<TNamespace, number>,
171
+ number,
172
+ "Result",
173
+ boolean
174
+ >
175
+ ) {
80
176
  return {
81
177
  type: Discord.ApplicationCommandOptionType.Number,
82
178
  name: cfg.name,
@@ -86,11 +182,21 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
86
182
  max_value: cfg.maxValue,
87
183
  minValue: cfg.minValue,
88
184
  min_value: cfg.minValue,
89
- required: cfg.required
185
+ required: cfg.required,
186
+ validate: cfg.validate,
90
187
  };
91
188
  }
92
189
 
93
- number(cfg: TDBIBaseOption & TDBIMinMaxValue) {
190
+ number(
191
+ cfg: TDBIBaseOption &
192
+ TDBIMinMaxValue &
193
+ TDBIValidator<
194
+ TDBIValidateCtx<TNamespace, number>,
195
+ number,
196
+ "Result",
197
+ boolean
198
+ >
199
+ ) {
94
200
  return {
95
201
  type: Discord.ApplicationCommandOptionType.Number,
96
202
  name: cfg.name,
@@ -99,11 +205,22 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
99
205
  max_value: cfg.maxValue,
100
206
  minValue: cfg.minValue,
101
207
  min_value: cfg.minValue,
102
- required: cfg.required
208
+ required: cfg.required,
209
+ validate: cfg.validate,
103
210
  };
104
211
  }
105
212
 
106
- integerAutocomplete(cfg: TDBIBaseOption & TDBIMinMaxValue & { onComplete(ctx: IDBICompleteCtx<TNamespace, string>): Promise<TDBIValueName<number>[]> | TDBIValueName<number>[] }) {
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
+ ) {
107
224
  return {
108
225
  type: Discord.ApplicationCommandOptionType.Integer,
109
226
  name: cfg.name,
@@ -114,11 +231,20 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
114
231
  max_value: cfg.maxValue,
115
232
  minValue: cfg.minValue,
116
233
  min_value: cfg.minValue,
117
- required: cfg.required
234
+ required: cfg.required,
235
+ validate: cfg.validate,
118
236
  };
119
237
  }
120
238
 
121
- integerChoices(cfg: TDBIBaseOption & TDBIMinMaxValue & { choices: TDBIValueName<number>[] }) {
239
+ integerChoices(
240
+ cfg: TDBIBaseOption &
241
+ TDBIMinMaxValue & { choices: TDBIValueName<number>[] } & TDBIValidator<
242
+ TDBIValidateCtx<TNamespace, number>,
243
+ number,
244
+ "Result",
245
+ boolean
246
+ >
247
+ ) {
122
248
  return {
123
249
  type: Discord.ApplicationCommandOptionType.Integer,
124
250
  name: cfg.name,
@@ -128,11 +254,21 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
128
254
  max_value: cfg.maxValue,
129
255
  minValue: cfg.minValue,
130
256
  min_value: cfg.minValue,
131
- required: cfg.required
257
+ required: cfg.required,
258
+ validate: cfg.validate,
132
259
  };
133
260
  }
134
261
 
135
- integer(cfg: TDBIBaseOption & TDBIMinMaxValue) {
262
+ integer(
263
+ cfg: TDBIBaseOption &
264
+ TDBIMinMaxValue &
265
+ TDBIValidator<
266
+ TDBIValidateCtx<TNamespace, number>,
267
+ number,
268
+ "Result",
269
+ boolean
270
+ >
271
+ ) {
136
272
  return {
137
273
  type: Discord.ApplicationCommandOptionType.Integer,
138
274
  name: cfg.name,
@@ -141,7 +277,8 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
141
277
  max_value: cfg.maxValue,
142
278
  minValue: cfg.minValue,
143
279
  min_value: cfg.minValue,
144
- required: cfg.required
280
+ required: cfg.required,
281
+ validate: cfg.validate,
145
282
  };
146
283
  }
147
284
 
@@ -150,7 +287,7 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
150
287
  type: Discord.ApplicationCommandOptionType.Boolean,
151
288
  name: cfg.name,
152
289
  description: cfg.description,
153
- required: cfg.required
290
+ required: cfg.required,
154
291
  };
155
292
  }
156
293
 
@@ -159,45 +296,85 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
159
296
  type: Discord.ApplicationCommandOptionType.Attachment,
160
297
  name: cfg.name,
161
298
  description: cfg.description,
162
- required: cfg.required
299
+ required: cfg.required,
163
300
  };
164
301
  }
165
302
 
166
- channel(cfg: TDBIBaseOption & { channelTypes: Discord.ChannelType[] }) {
303
+ channel(
304
+ cfg: TDBIBaseOption & {
305
+ channelTypes: Discord.ChannelType[];
306
+ } & TDBIValidator<
307
+ TDBIValidateCtx<TNamespace, Discord.Channel>,
308
+ Discord.Channel,
309
+ "Result",
310
+ boolean
311
+ >
312
+ ) {
167
313
  return {
168
314
  type: Discord.ApplicationCommandOptionType.Channel,
169
315
  name: cfg.name,
170
316
  description: cfg.description,
171
317
  channelTypes: cfg.channelTypes,
172
318
  channel_types: cfg.channelTypes,
173
- required: cfg.required
319
+ required: cfg.required,
320
+ validate: cfg.validate,
174
321
  };
175
322
  }
176
323
 
177
- role(cfg: TDBIBaseOption) {
324
+ role(
325
+ cfg: TDBIBaseOption &
326
+ TDBIValidator<
327
+ TDBIValidateCtx<TNamespace, Discord.Role>,
328
+ Discord.Role,
329
+ "Result",
330
+ boolean
331
+ >
332
+ ) {
178
333
  return {
179
334
  type: Discord.ApplicationCommandOptionType.Role,
180
335
  name: cfg.name,
181
336
  description: cfg.description,
182
- required: cfg.required
183
- }
337
+ required: cfg.required,
338
+ validate: cfg.validate,
339
+ };
184
340
  }
185
341
 
186
- mentionable(cfg: TDBIBaseOption) {
342
+ mentionable(
343
+ cfg: TDBIBaseOption &
344
+ TDBIValidator<
345
+ TDBIValidateCtx<
346
+ TNamespace,
347
+ Discord.Role | Discord.Channel | Discord.User
348
+ >,
349
+ Discord.Role | Discord.Channel | Discord.User,
350
+ "Result",
351
+ boolean
352
+ >
353
+ ) {
187
354
  return {
188
355
  type: Discord.ApplicationCommandOptionType.Mentionable,
189
356
  name: cfg.name,
190
357
  description: cfg.description,
191
- required: cfg.required
358
+ required: cfg.required,
359
+ validate: cfg.validate,
192
360
  };
193
361
  }
194
362
 
195
- user(cfg: TDBIBaseOption) {
363
+ user(
364
+ cfg: TDBIBaseOption &
365
+ TDBIValidator<
366
+ TDBIValidateCtx<TNamespace, Discord.User>,
367
+ Discord.User,
368
+ "Result",
369
+ boolean
370
+ >
371
+ ) {
196
372
  return {
197
373
  type: Discord.ApplicationCommandOptionType.User,
198
374
  name: cfg.name,
199
375
  description: cfg.description,
200
- required: cfg.required
376
+ required: cfg.required,
377
+ validate: cfg.validate,
201
378
  };
202
379
  }
203
- }
380
+ }