@mostfeatured/dbi 0.1.12 → 0.1.13-dev.2
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/dist/DBI.d.ts +27 -1
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +87 -4
- package/dist/DBI.js.map +1 -1
- package/dist/methods/handleMessageCommands.d.ts.map +1 -1
- package/dist/methods/handleMessageCommands.js +4 -0
- package/dist/methods/handleMessageCommands.js.map +1 -1
- package/dist/types/ChatInput/ChatInput.d.ts +1 -1
- package/dist/types/ChatInput/ChatInput.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInput.js.map +1 -1
- package/dist/types/Components/Button.d.ts +1 -1
- package/dist/types/Components/Button.d.ts.map +1 -1
- package/dist/types/Components/Button.js.map +1 -1
- package/dist/types/Components/ChannelSelectMenu.d.ts +1 -1
- package/dist/types/Components/ChannelSelectMenu.d.ts.map +1 -1
- package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
- package/dist/types/Components/MentionableSelectMenu.d.ts +1 -1
- package/dist/types/Components/MentionableSelectMenu.d.ts.map +1 -1
- package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
- package/dist/types/Components/Modal.d.ts +1 -1
- package/dist/types/Components/Modal.d.ts.map +1 -1
- package/dist/types/Components/Modal.js.map +1 -1
- package/dist/types/Components/RoleSelectMenu.d.ts +1 -1
- package/dist/types/Components/RoleSelectMenu.d.ts.map +1 -1
- package/dist/types/Components/RoleSelectMenu.js.map +1 -1
- package/dist/types/Components/StringSelectMenu.d.ts +1 -1
- package/dist/types/Components/StringSelectMenu.d.ts.map +1 -1
- package/dist/types/Components/StringSelectMenu.js.map +1 -1
- package/dist/types/Components/UserSelectMenu.d.ts +1 -1
- package/dist/types/Components/UserSelectMenu.d.ts.map +1 -1
- package/dist/types/Components/UserSelectMenu.js.map +1 -1
- package/dist/types/Event.d.ts +3 -1
- package/dist/types/Event.d.ts.map +1 -1
- package/dist/types/Event.js +4 -0
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +3 -1
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js +4 -0
- package/dist/types/Interaction.js.map +1 -1
- package/dist/types/other/FakeMessageInteraction.js +1 -1
- package/dist/types/other/FakeMessageInteraction.js.map +1 -1
- package/package.json +1 -1
- package/src/DBI.ts +184 -55
- package/src/methods/handleMessageCommands.ts +4 -0
- package/src/types/ChatInput/ChatInput.ts +1 -1
- package/src/types/Components/Button.ts +1 -1
- package/src/types/Components/ChannelSelectMenu.ts +1 -1
- package/src/types/Components/MentionableSelectMenu.ts +1 -1
- package/src/types/Components/Modal.ts +1 -1
- package/src/types/Components/RoleSelectMenu.ts +1 -1
- package/src/types/Components/StringSelectMenu.ts +1 -1
- package/src/types/Components/UserSelectMenu.ts +1 -1
- package/src/types/Event.ts +5 -1
- package/src/types/Interaction.ts +5 -1
- package/src/types/other/FakeMessageInteraction.ts +1 -1
package/src/DBI.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
TDBIRoleSelectMenuOmitted,
|
|
61
61
|
} from "./types/Components/RoleSelectMenu";
|
|
62
62
|
import { handleMessageCommands } from "./methods/handleMessageCommands";
|
|
63
|
+
import { FakeMessageInteraction } from "./types/other/FakeMessageInteraction";
|
|
63
64
|
|
|
64
65
|
export interface DBIStore {
|
|
65
66
|
get(key: string, defaultValue?: any): Promise<any>;
|
|
@@ -85,6 +86,9 @@ export interface DBIConfig {
|
|
|
85
86
|
locale: TDBILocaleString;
|
|
86
87
|
directMessages: boolean;
|
|
87
88
|
defaultMemberPermissions: Discord.PermissionsString[];
|
|
89
|
+
messageCommands: {
|
|
90
|
+
deferReplyContent(interaction: FakeMessageInteraction): MessagePayload | string | Promise<MessagePayload | string>;
|
|
91
|
+
};
|
|
88
92
|
};
|
|
89
93
|
|
|
90
94
|
sharding: "hybrid" | "default" | "off";
|
|
@@ -100,6 +104,13 @@ export interface DBIConfig {
|
|
|
100
104
|
};
|
|
101
105
|
};
|
|
102
106
|
|
|
107
|
+
inlineListeners: {
|
|
108
|
+
autoClear?: {
|
|
109
|
+
check: number;
|
|
110
|
+
ttl: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
103
114
|
strict: boolean;
|
|
104
115
|
messageCommands?: {
|
|
105
116
|
prefixes: string[];
|
|
@@ -111,22 +122,22 @@ export interface DBIConfig {
|
|
|
111
122
|
|
|
112
123
|
export interface DBIConfigConstructor {
|
|
113
124
|
discord:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
| {
|
|
126
|
+
token: string;
|
|
127
|
+
options: Discord.ClientOptions;
|
|
128
|
+
}
|
|
129
|
+
| {
|
|
130
|
+
namespace: string;
|
|
131
|
+
token: string;
|
|
132
|
+
options: Discord.ClientOptions;
|
|
133
|
+
}[];
|
|
123
134
|
|
|
124
135
|
defaults?: {
|
|
125
136
|
locale?: TDBILocaleString;
|
|
126
137
|
directMessages?: boolean;
|
|
127
138
|
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
128
139
|
messageCommands?: {
|
|
129
|
-
deferReplyContent?: MessagePayload | string;
|
|
140
|
+
deferReplyContent?: MessagePayload | string | ((interaction: FakeMessageInteraction) => MessagePayload | string | Promise<MessagePayload | string>);
|
|
130
141
|
};
|
|
131
142
|
};
|
|
132
143
|
|
|
@@ -143,6 +154,13 @@ export interface DBIConfigConstructor {
|
|
|
143
154
|
};
|
|
144
155
|
};
|
|
145
156
|
|
|
157
|
+
inlineListeners?: {
|
|
158
|
+
autoClear?: {
|
|
159
|
+
check: number;
|
|
160
|
+
ttl: number;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
146
164
|
data?: {
|
|
147
165
|
other?: Record<string, any>;
|
|
148
166
|
refs?: Map<string, { at: number; value: any; ttl?: number }>;
|
|
@@ -193,6 +211,32 @@ export interface DBIRegisterAPI<TNamespace extends NamespaceEnums> {
|
|
|
193
211
|
CustomEvent<T extends keyof NamespaceData[TNamespace]["customEvents"]>(
|
|
194
212
|
cfg: TDBICustomEventOmitted<TNamespace, T>
|
|
195
213
|
): DBICustomEvent<TNamespace, T>;
|
|
214
|
+
|
|
215
|
+
createInlineEvent(cfg: TDBIEventOmitted<TNamespace>): DBIEvent<TNamespace>;
|
|
216
|
+
createInlineButton(cfg: TDBIButtonOmitted<TNamespace>): DBIButton<TNamespace>;
|
|
217
|
+
createInlineStringSelectMenu(
|
|
218
|
+
cfg: TDBIStringSelectMenuOmitted<TNamespace>
|
|
219
|
+
): DBIStringSelectMenu<TNamespace>;
|
|
220
|
+
createInlineUserSelectMenu(
|
|
221
|
+
cfg: TDBIUserSelectMenuOmitted<TNamespace>
|
|
222
|
+
): DBIUserSelectMenu<TNamespace>;
|
|
223
|
+
createInlineRoleSelectMenu(
|
|
224
|
+
cfg: TDBIRoleSelectMenuOmitted<TNamespace>
|
|
225
|
+
): DBIRoleSelectMenu<TNamespace>;
|
|
226
|
+
createInlineChannelSelectMenu(
|
|
227
|
+
cfg: TDBIChannelSelectMenuOmitted<TNamespace>
|
|
228
|
+
): DBIChannelSelectMenu<TNamespace>;
|
|
229
|
+
createInlineMentionableSelectMenu(
|
|
230
|
+
cfg: TDBIMentionableSelectMenuOmitted<TNamespace>
|
|
231
|
+
): DBIMentionableSelectMenu<TNamespace>;
|
|
232
|
+
createInlineMessageContextMenu(
|
|
233
|
+
cfg: TDBIMessageContextMenuOmitted<TNamespace>
|
|
234
|
+
): DBIMessageContextMenu<TNamespace>;
|
|
235
|
+
createInlineUserContextMenu(
|
|
236
|
+
cfg: TDBIUserContextMenuOmitted<TNamespace>
|
|
237
|
+
): DBIUserContextMenu<TNamespace>;
|
|
238
|
+
createInlineModal(cfg: TDBIModalOmitted<TNamespace>): DBIModal<TNamespace>;
|
|
239
|
+
|
|
196
240
|
onUnload(cb: () => Promise<any> | any): any;
|
|
197
241
|
}
|
|
198
242
|
|
|
@@ -239,10 +283,13 @@ export class DBI<
|
|
|
239
283
|
defaultMemberPermissions: [],
|
|
240
284
|
directMessages: false,
|
|
241
285
|
...(config.defaults || {}),
|
|
242
|
-
messageCommands: {
|
|
243
|
-
deferReplyContent
|
|
244
|
-
|
|
245
|
-
|
|
286
|
+
messageCommands: (() => {
|
|
287
|
+
let deferReplyContent = config.defaults?.messageCommands?.deferReplyContent
|
|
288
|
+
return {
|
|
289
|
+
...(config.defaults?.messageCommands || {}),
|
|
290
|
+
deferReplyContent: (typeof deferReplyContent === "function" ? deferReplyContent : () => deferReplyContent || "Loading...") as any
|
|
291
|
+
}
|
|
292
|
+
})(),
|
|
246
293
|
};
|
|
247
294
|
config.sharding = config.sharding ?? "off";
|
|
248
295
|
config.strict = config.strict ?? true;
|
|
@@ -250,6 +297,13 @@ export class DBI<
|
|
|
250
297
|
autoClear: undefined,
|
|
251
298
|
...(config.references || {}),
|
|
252
299
|
};
|
|
300
|
+
config.inlineListeners = {
|
|
301
|
+
autoClear: {
|
|
302
|
+
check: 60000,
|
|
303
|
+
ttl: 900000,
|
|
304
|
+
},
|
|
305
|
+
...(config.inlineListeners || {}),
|
|
306
|
+
};
|
|
253
307
|
|
|
254
308
|
if (config.messageCommands) {
|
|
255
309
|
if (config.strict && !config.messageCommands?.prefixes?.length)
|
|
@@ -313,12 +367,12 @@ export class DBI<
|
|
|
313
367
|
config.discord = Array.isArray(config.discord)
|
|
314
368
|
? config.discord
|
|
315
369
|
: [
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
370
|
+
{
|
|
371
|
+
token: config.discord.token,
|
|
372
|
+
options: config.discord.options,
|
|
373
|
+
namespace: "default",
|
|
374
|
+
},
|
|
375
|
+
];
|
|
322
376
|
|
|
323
377
|
this.data.clients.push(...(config.discord as any));
|
|
324
378
|
for (let clientContext of this.data.clients) {
|
|
@@ -326,9 +380,9 @@ export class DBI<
|
|
|
326
380
|
...((clientContext.options || {}) as any),
|
|
327
381
|
...(config.sharding == "hybrid"
|
|
328
382
|
? {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
383
|
+
shards: Sharding.getInfo().SHARD_LIST,
|
|
384
|
+
shardCount: Sharding.getInfo().TOTAL_SHARDS,
|
|
385
|
+
}
|
|
332
386
|
: {}),
|
|
333
387
|
});
|
|
334
388
|
clientContext.client = client as Discord.Client<true>;
|
|
@@ -374,6 +428,35 @@ export class DBI<
|
|
|
374
428
|
})()
|
|
375
429
|
);
|
|
376
430
|
}
|
|
431
|
+
if (typeof this.config.inlineListeners.autoClear !== "undefined") {
|
|
432
|
+
this.data.unloaders.add(
|
|
433
|
+
(() => {
|
|
434
|
+
let interval = setInterval(() => {
|
|
435
|
+
this.data.interactions.forEach((i, key) => {
|
|
436
|
+
if (
|
|
437
|
+
i.ttl &&
|
|
438
|
+
(Date.now() >
|
|
439
|
+
i.at + (i.ttl || this.config.inlineListeners.autoClear.ttl))
|
|
440
|
+
) {
|
|
441
|
+
this.data.interactions.delete(key);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
this.data.events.forEach((i, key) => {
|
|
445
|
+
if (
|
|
446
|
+
i.ttl &&
|
|
447
|
+
(Date.now() >
|
|
448
|
+
i.at + (i.ttl || this.config.inlineListeners.autoClear.ttl))
|
|
449
|
+
) {
|
|
450
|
+
this.data.events.delete(key);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}, this.config.inlineListeners.autoClear.check);
|
|
454
|
+
return () => {
|
|
455
|
+
clearInterval(interval);
|
|
456
|
+
};
|
|
457
|
+
})()
|
|
458
|
+
);
|
|
459
|
+
}
|
|
377
460
|
if (typeof this.config.messageCommands !== "undefined") {
|
|
378
461
|
this.data.unloaders.add(
|
|
379
462
|
(() => {
|
|
@@ -422,13 +505,14 @@ export class DBI<
|
|
|
422
505
|
const self = this;
|
|
423
506
|
const ChatInputOptions = new DBIChatInputOptions(self);
|
|
424
507
|
|
|
508
|
+
const randomInlineId = () => `inline:${Math.random().toString(36).slice(2)}`;
|
|
509
|
+
|
|
425
510
|
for await (const cb of this.data.registers) {
|
|
426
511
|
let ChatInput = function (cfg: DBIChatInput<TNamespace>) {
|
|
427
512
|
let dbiChatInput = new DBIChatInput(self, cfg);
|
|
428
513
|
if (self.data.interactions.has(dbiChatInput.name))
|
|
429
514
|
throw new Error(
|
|
430
|
-
`DBIChatInput "${dbiChatInput.name}" already loaded as "${
|
|
431
|
-
self.data.interactions.get(dbiChatInput.name)?.type
|
|
515
|
+
`DBIChatInput "${dbiChatInput.name}" already loaded as "${self.data.interactions.get(dbiChatInput.name)?.type
|
|
432
516
|
}"!`
|
|
433
517
|
);
|
|
434
518
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiChatInput.name, dbiChatInput);
|
|
@@ -452,7 +536,7 @@ export class DBI<
|
|
|
452
536
|
throw new Error(
|
|
453
537
|
`DBIEvent "${dbiEvent.id || dbiEvent.name}" already loaded!`
|
|
454
538
|
);
|
|
455
|
-
|
|
539
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);
|
|
456
540
|
return dbiEvent;
|
|
457
541
|
};
|
|
458
542
|
Event = Object.assign(
|
|
@@ -464,15 +548,18 @@ export class DBI<
|
|
|
464
548
|
}
|
|
465
549
|
);
|
|
466
550
|
|
|
551
|
+
let createInlineEvent = function (cfg: Omit<TDBIEventOmitted<TNamespace>, "id">) {
|
|
552
|
+
return Event({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id: randomInlineId() } as any);
|
|
553
|
+
}
|
|
554
|
+
|
|
467
555
|
let Button = function (cfg: TDBIButtonOmitted<TNamespace>) {
|
|
468
556
|
let dbiButton = new DBIButton(self as any, cfg);
|
|
469
557
|
if (self.config.strict && self.data.interactions.has(dbiButton.name))
|
|
470
558
|
throw new Error(
|
|
471
|
-
`DBIButton "${dbiButton.name}" already loaded as "${
|
|
472
|
-
self.data.interactions.get(dbiButton.name)?.type
|
|
559
|
+
`DBIButton "${dbiButton.name}" already loaded as "${self.data.interactions.get(dbiButton.name)?.type
|
|
473
560
|
}"!`
|
|
474
561
|
);
|
|
475
|
-
|
|
562
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiButton.name, dbiButton as any);
|
|
476
563
|
return dbiButton;
|
|
477
564
|
};
|
|
478
565
|
Button = Object.assign(
|
|
@@ -484,6 +571,11 @@ export class DBI<
|
|
|
484
571
|
}
|
|
485
572
|
);
|
|
486
573
|
|
|
574
|
+
let createInlineButton = function (cfg: Omit<TDBIButtonOmitted<TNamespace>, "name" | "id">) {
|
|
575
|
+
let id = randomInlineId();
|
|
576
|
+
return Button({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
577
|
+
}
|
|
578
|
+
|
|
487
579
|
let StringSelectMenu = function (
|
|
488
580
|
cfg: TDBIStringSelectMenuOmitted<TNamespace>
|
|
489
581
|
) {
|
|
@@ -493,10 +585,8 @@ export class DBI<
|
|
|
493
585
|
self.data.interactions.has(dbiStringSelectMenu.name)
|
|
494
586
|
)
|
|
495
587
|
throw new Error(
|
|
496
|
-
`DBIStringSelectMenu "${
|
|
497
|
-
|
|
498
|
-
}" already loaded as "${
|
|
499
|
-
self.data.interactions.get(dbiStringSelectMenu.name)?.type
|
|
588
|
+
`DBIStringSelectMenu "${dbiStringSelectMenu.name
|
|
589
|
+
}" already loaded as "${self.data.interactions.get(dbiStringSelectMenu.name)?.type
|
|
500
590
|
}"!`
|
|
501
591
|
);
|
|
502
592
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -514,6 +604,11 @@ export class DBI<
|
|
|
514
604
|
}
|
|
515
605
|
);
|
|
516
606
|
|
|
607
|
+
let createInlineStringSelectMenu = function (cfg: Omit<TDBIStringSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
608
|
+
let id = randomInlineId();
|
|
609
|
+
return StringSelectMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
610
|
+
}
|
|
611
|
+
|
|
517
612
|
let UserSelectMenu = function (
|
|
518
613
|
cfg: TDBIUserSelectMenuOmitted<TNamespace>
|
|
519
614
|
) {
|
|
@@ -523,8 +618,7 @@ export class DBI<
|
|
|
523
618
|
self.data.interactions.has(dbiUserSelectMenu.name)
|
|
524
619
|
)
|
|
525
620
|
throw new Error(
|
|
526
|
-
`DBIUserSelectMenu "${dbiUserSelectMenu.name}" already loaded as "${
|
|
527
|
-
self.data.interactions.get(dbiUserSelectMenu.name)?.type
|
|
621
|
+
`DBIUserSelectMenu "${dbiUserSelectMenu.name}" already loaded as "${self.data.interactions.get(dbiUserSelectMenu.name)?.type
|
|
528
622
|
}"!`
|
|
529
623
|
);
|
|
530
624
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -542,6 +636,11 @@ export class DBI<
|
|
|
542
636
|
}
|
|
543
637
|
);
|
|
544
638
|
|
|
639
|
+
let createInlineUserSelectMenu = function (cfg: Omit<TDBIUserSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
640
|
+
let id = randomInlineId();
|
|
641
|
+
return UserSelectMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
642
|
+
}
|
|
643
|
+
|
|
545
644
|
let RoleSelectMenu = function (
|
|
546
645
|
cfg: TDBIRoleSelectMenuOmitted<TNamespace>
|
|
547
646
|
) {
|
|
@@ -551,8 +650,7 @@ export class DBI<
|
|
|
551
650
|
self.data.interactions.has(dbiRoleSelectMenu.name)
|
|
552
651
|
)
|
|
553
652
|
throw new Error(
|
|
554
|
-
`DBIRoleSelectMenu "${dbiRoleSelectMenu.name}" already loaded as "${
|
|
555
|
-
self.data.interactions.get(dbiRoleSelectMenu.name)?.type
|
|
653
|
+
`DBIRoleSelectMenu "${dbiRoleSelectMenu.name}" already loaded as "${self.data.interactions.get(dbiRoleSelectMenu.name)?.type
|
|
556
654
|
}"!`
|
|
557
655
|
);
|
|
558
656
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -570,6 +668,11 @@ export class DBI<
|
|
|
570
668
|
}
|
|
571
669
|
);
|
|
572
670
|
|
|
671
|
+
let createInlineRoleSelectMenu = function (cfg: Omit<TDBIRoleSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
672
|
+
let id = randomInlineId();
|
|
673
|
+
return RoleSelectMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
674
|
+
}
|
|
675
|
+
|
|
573
676
|
let ChannelSelectMenu = function (
|
|
574
677
|
cfg: TDBIChannelSelectMenuOmitted<TNamespace>
|
|
575
678
|
) {
|
|
@@ -579,10 +682,8 @@ export class DBI<
|
|
|
579
682
|
self.data.interactions.has(dbiChannelSelectMenu.name)
|
|
580
683
|
)
|
|
581
684
|
throw new Error(
|
|
582
|
-
`DBIChannelSelectMenu "${
|
|
583
|
-
|
|
584
|
-
}" already loaded as "${
|
|
585
|
-
self.data.interactions.get(dbiChannelSelectMenu.name)?.type
|
|
685
|
+
`DBIChannelSelectMenu "${dbiChannelSelectMenu.name
|
|
686
|
+
}" already loaded as "${self.data.interactions.get(dbiChannelSelectMenu.name)?.type
|
|
586
687
|
}"!`
|
|
587
688
|
);
|
|
588
689
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -600,6 +701,11 @@ export class DBI<
|
|
|
600
701
|
}
|
|
601
702
|
);
|
|
602
703
|
|
|
704
|
+
let createInlineChannelSelectMenu = function (cfg: Omit<TDBIChannelSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
705
|
+
let id = randomInlineId();
|
|
706
|
+
return ChannelSelectMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
707
|
+
}
|
|
708
|
+
|
|
603
709
|
let MentionableSelectMenu = function (
|
|
604
710
|
cfg: TDBIMentionableSelectMenuOmitted<TNamespace>
|
|
605
711
|
) {
|
|
@@ -612,10 +718,8 @@ export class DBI<
|
|
|
612
718
|
self.data.interactions.has(dbiMentionableSelectMenu.name)
|
|
613
719
|
)
|
|
614
720
|
throw new Error(
|
|
615
|
-
`DBIMentionableSelectMenu "${
|
|
616
|
-
|
|
617
|
-
}" already loaded as "${
|
|
618
|
-
self.data.interactions.get(dbiMentionableSelectMenu.name)?.type
|
|
721
|
+
`DBIMentionableSelectMenu "${dbiMentionableSelectMenu.name
|
|
722
|
+
}" already loaded as "${self.data.interactions.get(dbiMentionableSelectMenu.name)?.type
|
|
619
723
|
}"!`
|
|
620
724
|
);
|
|
621
725
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -633,6 +737,11 @@ export class DBI<
|
|
|
633
737
|
}
|
|
634
738
|
);
|
|
635
739
|
|
|
740
|
+
let createInlineMentionableSelectMenu = function (cfg: Omit<TDBIMentionableSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
741
|
+
let id = randomInlineId();
|
|
742
|
+
return MentionableSelectMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
743
|
+
}
|
|
744
|
+
|
|
636
745
|
let MessageContextMenu = function (
|
|
637
746
|
cfg: TDBIMessageContextMenuOmitted<TNamespace>
|
|
638
747
|
) {
|
|
@@ -642,10 +751,8 @@ export class DBI<
|
|
|
642
751
|
self.data.interactions.has(dbiMessageContextMenu.name)
|
|
643
752
|
)
|
|
644
753
|
throw new Error(
|
|
645
|
-
`DBIMessageContextMenu "${
|
|
646
|
-
|
|
647
|
-
}" already loaded as "${
|
|
648
|
-
self.data.interactions.get(dbiMessageContextMenu.name)?.type
|
|
754
|
+
`DBIMessageContextMenu "${dbiMessageContextMenu.name
|
|
755
|
+
}" already loaded as "${self.data.interactions.get(dbiMessageContextMenu.name)?.type
|
|
649
756
|
}"!`
|
|
650
757
|
);
|
|
651
758
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -663,6 +770,11 @@ export class DBI<
|
|
|
663
770
|
}
|
|
664
771
|
);
|
|
665
772
|
|
|
773
|
+
let createInlineMessageContextMenu = function (cfg: Omit<TDBIMessageContextMenuOmitted<TNamespace>, "id" | "name">) {
|
|
774
|
+
let id = randomInlineId();
|
|
775
|
+
return MessageContextMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
776
|
+
}
|
|
777
|
+
|
|
666
778
|
let UserContextMenu = function (
|
|
667
779
|
cfg: TDBIUserContextMenuOmitted<TNamespace>
|
|
668
780
|
) {
|
|
@@ -672,10 +784,8 @@ export class DBI<
|
|
|
672
784
|
self.data.interactions.has(dbiUserContextMenu.name)
|
|
673
785
|
)
|
|
674
786
|
throw new Error(
|
|
675
|
-
`DBIUserContextMenu "${
|
|
676
|
-
|
|
677
|
-
}" already loaded as "${
|
|
678
|
-
self.data.interactions.get(dbiUserContextMenu.name)?.type
|
|
787
|
+
`DBIUserContextMenu "${dbiUserContextMenu.name
|
|
788
|
+
}" already loaded as "${self.data.interactions.get(dbiUserContextMenu.name)?.type
|
|
679
789
|
}"!`
|
|
680
790
|
);
|
|
681
791
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
@@ -693,12 +803,16 @@ export class DBI<
|
|
|
693
803
|
}
|
|
694
804
|
);
|
|
695
805
|
|
|
806
|
+
let createInlineUserContextMenu = function (cfg: Omit<TDBIUserContextMenuOmitted<TNamespace>, "id" | "name">) {
|
|
807
|
+
let id = randomInlineId();
|
|
808
|
+
return UserContextMenu({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
809
|
+
}
|
|
810
|
+
|
|
696
811
|
let Modal = function (cfg: TDBIModalOmitted<TNamespace>) {
|
|
697
812
|
let dbiModal = new DBIModal(self as any, cfg);
|
|
698
813
|
if (self.config.strict && self.data.interactions.has(dbiModal.name))
|
|
699
814
|
throw new Error(
|
|
700
|
-
`DBIModal "${dbiModal.name}" already loaded as "${
|
|
701
|
-
self.data.interactions.get(dbiModal.name)?.type
|
|
815
|
+
`DBIModal "${dbiModal.name}" already loaded as "${self.data.interactions.get(dbiModal.name)?.type
|
|
702
816
|
}"!`
|
|
703
817
|
);
|
|
704
818
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiModal.name, dbiModal as any);
|
|
@@ -713,6 +827,11 @@ export class DBI<
|
|
|
713
827
|
}
|
|
714
828
|
);
|
|
715
829
|
|
|
830
|
+
let createInlineModal = function (cfg: Omit<TDBIModalOmitted<TNamespace>, "name" | "id">) {
|
|
831
|
+
let id = randomInlineId();
|
|
832
|
+
return Modal({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id, name: id } as any);
|
|
833
|
+
}
|
|
834
|
+
|
|
716
835
|
let Locale = function (cfg: TDBILocaleConstructor<TNamespace>) {
|
|
717
836
|
let dbiLocale = new DBILocale(self as any, cfg);
|
|
718
837
|
if (
|
|
@@ -793,6 +912,16 @@ export class DBI<
|
|
|
793
912
|
CustomEvent,
|
|
794
913
|
Modal,
|
|
795
914
|
InteractionLocale,
|
|
915
|
+
createInlineButton,
|
|
916
|
+
createInlineEvent,
|
|
917
|
+
createInlineStringSelectMenu,
|
|
918
|
+
createInlineUserSelectMenu,
|
|
919
|
+
createInlineRoleSelectMenu,
|
|
920
|
+
createInlineChannelSelectMenu,
|
|
921
|
+
createInlineMentionableSelectMenu,
|
|
922
|
+
createInlineMessageContextMenu,
|
|
923
|
+
createInlineUserContextMenu,
|
|
924
|
+
createInlineModal,
|
|
796
925
|
onUnload(cb: () => Promise<any> | any) {
|
|
797
926
|
self.data.registerUnloaders.add(cb);
|
|
798
927
|
},
|
|
@@ -165,6 +165,10 @@ export async function handleMessageCommands(
|
|
|
165
165
|
break;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
if (option.required && !value) {
|
|
169
|
+
errorType = "MissingRequiredOption";
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
168
172
|
if (option.minLength && value?.length < option.minLength) {
|
|
169
173
|
errorType = "MinLength";
|
|
170
174
|
break;
|
|
@@ -7,7 +7,7 @@ export interface IDBIChatInputExecuteCtx<TNamespace extends NamespaceEnums> exte
|
|
|
7
7
|
interaction: Discord.ChatInputCommandInteraction<"cached">;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type TDBIChatInputOmitted<TNamespace extends NamespaceEnums> = Omit<DBIChatInput<TNamespace>, "type" | "dbi" | "toJSON">;
|
|
10
|
+
export type TDBIChatInputOmitted<TNamespace extends NamespaceEnums> = Omit<DBIChatInput<TNamespace>, "type" | "dbi" | "ttl" | "at" | "toJSON">;
|
|
11
11
|
|
|
12
12
|
export class DBIChatInput<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
13
13
|
constructor(dbi: DBI<TNamespace, {}>, cfg: TDBIChatInputOmitted<TNamespace>) {
|
|
@@ -12,7 +12,7 @@ export interface IDBIButtonExecuteCtx<TNamespace extends NamespaceEnums> extends
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIButtonOmitted<TNamespace extends NamespaceEnums> = Omit<DBIButton<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIButtonOmitted<TNamespace extends NamespaceEnums> = Omit<DBIButton<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export class DBIButton<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
18
18
|
constructor(dbi: DBI<TNamespace>, args: TDBIButtonOmitted<TNamespace>) {
|
|
@@ -12,7 +12,7 @@ export interface IDBIChannelSelectMenuExecuteCtx<TNamespace extends NamespaceEnu
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIChannelSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIChannelSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIChannelSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIChannelSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export type SelectMenuDefaultOptions = Omit<Discord.ChannelSelectMenuComponentData, "customId" | "type" | "options">;
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@ export interface IDBIMentionableSelectMenuExecuteCtx<TNamespace extends Namespac
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIMentionableSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIMentionableSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIMentionableSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIMentionableSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export type SelectMenuDefaultOptions = Omit<Discord.MentionableSelectMenuComponentData, "customId" | "type" | "options">;
|
|
18
18
|
|
|
@@ -18,7 +18,7 @@ export interface ModalComponentData {
|
|
|
18
18
|
components: (Discord.ActionRowData<Discord.ModalActionRowComponentData>)[];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type TDBIModalOmitted<TNamespace extends NamespaceEnums> = Omit<DBIModal<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
21
|
+
export type TDBIModalOmitted<TNamespace extends NamespaceEnums> = Omit<DBIModal<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
22
22
|
|
|
23
23
|
export class DBIModal<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
24
24
|
constructor(dbi: DBI<TNamespace>, args: TDBIModalOmitted<TNamespace>) {
|
|
@@ -12,7 +12,7 @@ export interface IDBIRoleSelectMenuExecuteCtx<TNamespace extends NamespaceEnums>
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIRoleSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIRoleSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIRoleSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIRoleSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export type SelectMenuDefaultOptions = Omit<Discord.RoleSelectMenuComponentData, "customId" | "type" | "options">;
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@ export interface IDBIStringSelectMenuExecuteCtx<TNamespace extends NamespaceEnum
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIStringSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIStringSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIStringSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIStringSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export type SelectMenuDefaultOptions = Required<Pick<Discord.StringSelectMenuComponentData, "options">> & Omit<Discord.StringSelectMenuComponentData, "customId" | "type" | "options">;
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@ export interface IDBIUserSelectMenuExecuteCtx<TNamespace extends NamespaceEnums>
|
|
|
12
12
|
data: TDBIReferencedData[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type TDBIUserSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIUserSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder">;
|
|
15
|
+
export type TDBIUserSelectMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIUserSelectMenu<TNamespace>, "type" | "description" | "dbi" | "toJSON" | "createBuilder" | "at">;
|
|
16
16
|
|
|
17
17
|
export type SelectMenuDefaultOptions = Omit<Discord.UserSelectMenuComponentData, "customId" | "type" | "options">;
|
|
18
18
|
|
package/src/types/Event.ts
CHANGED
|
@@ -100,7 +100,7 @@ export type DBIEventCombinations<TNamespace extends NamespaceEnums> = {
|
|
|
100
100
|
}
|
|
101
101
|
}[keyof (ClientEvents) | keyof NamespaceData[TNamespace]["customEvents"]];
|
|
102
102
|
|
|
103
|
-
export type TDBIEventOmitted<TNamespace extends NamespaceEnums> = Omit<DBIEvent<TNamespace>, "type" | "name" | "onExecute" | "client" | "dbi" | "toggle" | "disabled"> & { disabled?: boolean } &
|
|
103
|
+
export type TDBIEventOmitted<TNamespace extends NamespaceEnums> = Omit<DBIEvent<TNamespace>, "type" | "name" | "onExecute" | "client" | "dbi" | "toggle" | "disabled" | "at"> & { disabled?: boolean } & DBIEventCombinations<TNamespace>;
|
|
104
104
|
|
|
105
105
|
export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
106
106
|
readonly type: "Event";
|
|
@@ -113,6 +113,8 @@ export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
|
113
113
|
dbi: DBI<TNamespace>;
|
|
114
114
|
disabled: boolean = false;
|
|
115
115
|
flag?: string;
|
|
116
|
+
at?: number;
|
|
117
|
+
ttl?: number;
|
|
116
118
|
constructor(dbi: DBI<TNamespace>, cfg: TDBIEventOmitted<TNamespace>) {
|
|
117
119
|
this.dbi = dbi;
|
|
118
120
|
this.type = "Event";
|
|
@@ -124,6 +126,8 @@ export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
|
124
126
|
this.triggerType = cfg.triggerType ?? "OneByOneGlobal";
|
|
125
127
|
this.disabled ??= cfg.disabled;
|
|
126
128
|
this.flag = cfg.flag;
|
|
129
|
+
this.at = Date.now();
|
|
130
|
+
this.ttl = cfg.ttl;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
toggle(disabled?: boolean) {
|
package/src/types/Interaction.ts
CHANGED
|
@@ -63,7 +63,7 @@ export type DBIRateLimit = {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
66
|
-
constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, "dbi">) {
|
|
66
|
+
constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, "dbi" | "at">) {
|
|
67
67
|
this.dbi = dbi;
|
|
68
68
|
this.name = cfg.name;
|
|
69
69
|
this.description = cfg.description;
|
|
@@ -74,6 +74,8 @@ export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
|
74
74
|
this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;
|
|
75
75
|
this.rateLimits = cfg.rateLimits ?? [];
|
|
76
76
|
this.flag = cfg.flag;
|
|
77
|
+
this.at = Date.now();
|
|
78
|
+
this.ttl = cfg.ttl;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
publish?: NamespaceData[TNamespace]["clientNamespaces"];
|
|
@@ -85,6 +87,8 @@ export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
|
85
87
|
other?: Record<string, any> & { messageCommand?: { aliases?: string[] } };
|
|
86
88
|
rateLimits?: DBIRateLimit[];
|
|
87
89
|
flag?: string;
|
|
90
|
+
ttl?: number;
|
|
91
|
+
at?: number;
|
|
88
92
|
toJSON(overrides: any): any { }
|
|
89
93
|
|
|
90
94
|
onExecute(ctx: IDBIBaseExecuteCtx<TNamespace>): Promise<void> | void {
|
|
@@ -319,7 +319,7 @@ export class FakeMessageInteraction /* implements ChatInputCommandInteraction */
|
|
|
319
319
|
|
|
320
320
|
async deferReply(options: any): Promise<any> {
|
|
321
321
|
if (this.repliedMessage) throw new Error("Already deferred reply.");
|
|
322
|
-
this.repliedMessage = await this.message.reply(options?.content ??
|
|
322
|
+
this.repliedMessage = await this.message.reply(options?.content ?? (await this.dbi.config.defaults.messageCommands.deferReplyContent(this)));
|
|
323
323
|
this.deferred = true;
|
|
324
324
|
this._lastAction = "deferReply";
|
|
325
325
|
return this.repliedMessage;
|