@mostfeatured/dbi 0.1.32 → 0.1.34
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 +4 -0
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +15 -71
- package/dist/DBI.js.map +1 -1
- package/dist/methods/hookInteractionListeners.d.ts.map +1 -1
- package/dist/methods/hookInteractionListeners.js +62 -20
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/dist/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.d.ts +53 -0
- package/dist/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.d.ts.map +1 -0
- package/dist/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.js +60 -0
- package/dist/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.js.map +1 -0
- package/dist/types/Components/HTMLComponentsV2/index.d.ts +19 -0
- package/dist/types/Components/HTMLComponentsV2/index.d.ts.map +1 -0
- package/dist/types/Components/HTMLComponentsV2/index.js +28 -0
- package/dist/types/Components/HTMLComponentsV2/index.js.map +1 -0
- package/dist/types/Components/HTMLComponentsV2/parser.d.ts +4 -0
- package/dist/types/Components/HTMLComponentsV2/parser.d.ts.map +1 -0
- package/dist/types/Components/HTMLComponentsV2/parser.js +260 -0
- package/dist/types/Components/HTMLComponentsV2/parser.js.map +1 -0
- package/dist/types/Interaction.d.ts +6 -4
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js.map +1 -1
- package/dist/utils/customId.d.ts +2 -1
- package/dist/utils/customId.d.ts.map +1 -1
- package/dist/utils/customId.js +6 -2
- package/dist/utils/customId.js.map +1 -1
- package/package.json +7 -4
- package/src/DBI.ts +30 -113
- package/src/methods/hookInteractionListeners.ts +79 -34
- package/src/types/ChatInput/ChatInputOptions.ts +6 -6
- package/src/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.ts +78 -0
- package/src/types/Components/HTMLComponentsV2/index.ts +43 -0
- package/src/types/Components/HTMLComponentsV2/parser.ts +279 -0
- package/src/types/Interaction.ts +7 -4
- package/src/utils/customId.ts +6 -3
package/src/DBI.ts
CHANGED
|
@@ -61,6 +61,8 @@ import {
|
|
|
61
61
|
} from "./types/Components/RoleSelectMenu";
|
|
62
62
|
import { handleMessageCommands } from "./methods/handleMessageCommands";
|
|
63
63
|
import { FakeMessageInteraction } from "./types/other/FakeMessageInteraction";
|
|
64
|
+
import { DBIHTMLComponentsV2, TDBIHTMLComponentsV2Omitted } from "./types/Components/HTMLComponentsV2";
|
|
65
|
+
import { DBIHTMLComponentsV2Handlers } from "./types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers";
|
|
64
66
|
|
|
65
67
|
export interface DBIStore {
|
|
66
68
|
get(key: string, defaultValue?: any): Promise<any>;
|
|
@@ -203,6 +205,7 @@ export interface DBIConfigConstructor<TNamespace extends NamespaceEnums, OtherDa
|
|
|
203
205
|
export interface DBIRegisterAPI<TNamespace extends NamespaceEnums> {
|
|
204
206
|
ChatInput(cfg: TDBIChatInputOmitted<TNamespace>): DBIChatInput<TNamespace>;
|
|
205
207
|
ChatInputOptions: DBIChatInputOptions<TNamespace>;
|
|
208
|
+
|
|
206
209
|
Event(cfg: TDBIEventOmitted<TNamespace>): DBIEvent<TNamespace>;
|
|
207
210
|
Locale(cfg: TDBILocaleConstructor<TNamespace>): DBILocale<TNamespace>;
|
|
208
211
|
Button(cfg: TDBIButtonOmitted<TNamespace>): DBIButton<TNamespace>;
|
|
@@ -233,6 +236,9 @@ export interface DBIRegisterAPI<TNamespace extends NamespaceEnums> {
|
|
|
233
236
|
cfg: TDBICustomEventOmitted<TNamespace, T>
|
|
234
237
|
): DBICustomEvent<TNamespace, T>;
|
|
235
238
|
|
|
239
|
+
HTMLComponentsV2(cfg: TDBIHTMLComponentsV2Omitted<TNamespace>): DBIHTMLComponentsV2<TNamespace>;
|
|
240
|
+
HTMLComponentsV2Handlers: DBIHTMLComponentsV2Handlers<TNamespace>;
|
|
241
|
+
|
|
236
242
|
createInlineEvent(cfg: Omit<TDBIEventOmitted<TNamespace>, "id">): DBIEvent<TNamespace>;
|
|
237
243
|
createInlineButton(cfg: Omit<TDBIButtonOmitted<TNamespace>, "id" | "name">): DBIButton<TNamespace>;
|
|
238
244
|
createInlineStringSelectMenu(
|
|
@@ -529,6 +535,7 @@ export class DBI<
|
|
|
529
535
|
private async _registerAll(flags: string[] = []) {
|
|
530
536
|
const self = this;
|
|
531
537
|
const ChatInputOptions = new DBIChatInputOptions(self);
|
|
538
|
+
const HTMLComponentsV2Handlers = new DBIHTMLComponentsV2Handlers(self);
|
|
532
539
|
|
|
533
540
|
const randomInlineId = () => `inline:${Math.random().toString(36).slice(2)}`;
|
|
534
541
|
|
|
@@ -543,14 +550,6 @@ export class DBI<
|
|
|
543
550
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiChatInput.name, dbiChatInput);
|
|
544
551
|
return dbiChatInput;
|
|
545
552
|
};
|
|
546
|
-
ChatInput = Object.assign(
|
|
547
|
-
ChatInput,
|
|
548
|
-
class {
|
|
549
|
-
constructor(...args: any[]) {
|
|
550
|
-
return ChatInput.apply(this, args as any);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
);
|
|
554
553
|
|
|
555
554
|
let Event = function (cfg: TDBIEventOmitted<TNamespace>) {
|
|
556
555
|
let dbiEvent = new DBIEvent(self as any, cfg);
|
|
@@ -564,14 +563,6 @@ export class DBI<
|
|
|
564
563
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);
|
|
565
564
|
return dbiEvent;
|
|
566
565
|
};
|
|
567
|
-
Event = Object.assign(
|
|
568
|
-
Event,
|
|
569
|
-
class {
|
|
570
|
-
constructor(...args: any[]) {
|
|
571
|
-
return Event.apply(this, args as any);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
);
|
|
575
566
|
|
|
576
567
|
let createInlineEvent = function (cfg: Omit<TDBIEventOmitted<TNamespace>, "id">) {
|
|
577
568
|
return Event({ ...cfg, ttl: cfg?.ttl || self.config.inlineListeners.autoClear?.ttl, id: randomInlineId() } as any);
|
|
@@ -587,14 +578,6 @@ export class DBI<
|
|
|
587
578
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiButton.name, dbiButton as any);
|
|
588
579
|
return dbiButton;
|
|
589
580
|
};
|
|
590
|
-
Button = Object.assign(
|
|
591
|
-
Button,
|
|
592
|
-
class {
|
|
593
|
-
constructor(...args: any[]) {
|
|
594
|
-
return Button.apply(this, args as any);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
);
|
|
598
581
|
|
|
599
582
|
let createInlineButton = function (cfg: Omit<TDBIButtonOmitted<TNamespace>, "name" | "id">) {
|
|
600
583
|
let id = randomInlineId();
|
|
@@ -620,14 +603,6 @@ export class DBI<
|
|
|
620
603
|
);
|
|
621
604
|
return dbiStringSelectMenu;
|
|
622
605
|
};
|
|
623
|
-
StringSelectMenu = Object.assign(
|
|
624
|
-
StringSelectMenu,
|
|
625
|
-
class {
|
|
626
|
-
constructor(...args: any[]) {
|
|
627
|
-
return StringSelectMenu.apply(this, args as any);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
);
|
|
631
606
|
|
|
632
607
|
let createInlineStringSelectMenu = function (cfg: Omit<TDBIStringSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
633
608
|
let id = randomInlineId();
|
|
@@ -652,14 +627,6 @@ export class DBI<
|
|
|
652
627
|
);
|
|
653
628
|
return dbiUserSelectMenu;
|
|
654
629
|
};
|
|
655
|
-
UserSelectMenu = Object.assign(
|
|
656
|
-
UserSelectMenu,
|
|
657
|
-
class {
|
|
658
|
-
constructor(...args: any[]) {
|
|
659
|
-
return UserSelectMenu.apply(this, args as any);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
);
|
|
663
630
|
|
|
664
631
|
let createInlineUserSelectMenu = function (cfg: Omit<TDBIUserSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
665
632
|
let id = randomInlineId();
|
|
@@ -684,14 +651,6 @@ export class DBI<
|
|
|
684
651
|
);
|
|
685
652
|
return dbiRoleSelectMenu;
|
|
686
653
|
};
|
|
687
|
-
RoleSelectMenu = Object.assign(
|
|
688
|
-
RoleSelectMenu,
|
|
689
|
-
class {
|
|
690
|
-
constructor(...args: any[]) {
|
|
691
|
-
return RoleSelectMenu.apply(this, args as any);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
);
|
|
695
654
|
|
|
696
655
|
let createInlineRoleSelectMenu = function (cfg: Omit<TDBIRoleSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
697
656
|
let id = randomInlineId();
|
|
@@ -717,14 +676,6 @@ export class DBI<
|
|
|
717
676
|
);
|
|
718
677
|
return dbiChannelSelectMenu;
|
|
719
678
|
};
|
|
720
|
-
ChannelSelectMenu = Object.assign(
|
|
721
|
-
ChannelSelectMenu,
|
|
722
|
-
class {
|
|
723
|
-
constructor(...args: any[]) {
|
|
724
|
-
return ChannelSelectMenu.apply(this, args as any);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
);
|
|
728
679
|
|
|
729
680
|
let createInlineChannelSelectMenu = function (cfg: Omit<TDBIChannelSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
730
681
|
let id = randomInlineId();
|
|
@@ -753,14 +704,6 @@ export class DBI<
|
|
|
753
704
|
);
|
|
754
705
|
return dbiMentionableSelectMenu;
|
|
755
706
|
};
|
|
756
|
-
MentionableSelectMenu = Object.assign(
|
|
757
|
-
MentionableSelectMenu,
|
|
758
|
-
class {
|
|
759
|
-
constructor(...args: any[]) {
|
|
760
|
-
return MentionableSelectMenu.apply(this, args as any);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
);
|
|
764
707
|
|
|
765
708
|
let createInlineMentionableSelectMenu = function (cfg: Omit<TDBIMentionableSelectMenuOmitted<TNamespace>, "id" | "name">) {
|
|
766
709
|
let id = randomInlineId();
|
|
@@ -786,14 +729,6 @@ export class DBI<
|
|
|
786
729
|
);
|
|
787
730
|
return dbiMessageContextMenu;
|
|
788
731
|
};
|
|
789
|
-
MessageContextMenu = Object.assign(
|
|
790
|
-
MessageContextMenu,
|
|
791
|
-
class {
|
|
792
|
-
constructor(...args: any[]) {
|
|
793
|
-
return MessageContextMenu.apply(this, args as any);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
);
|
|
797
732
|
|
|
798
733
|
let UserContextMenu = function (
|
|
799
734
|
cfg: TDBIUserContextMenuOmitted<TNamespace>
|
|
@@ -814,14 +749,6 @@ export class DBI<
|
|
|
814
749
|
);
|
|
815
750
|
return dbiUserContextMenu;
|
|
816
751
|
};
|
|
817
|
-
UserContextMenu = Object.assign(
|
|
818
|
-
UserContextMenu,
|
|
819
|
-
class {
|
|
820
|
-
constructor(...args: any[]) {
|
|
821
|
-
return UserContextMenu.apply(this, args as any);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
);
|
|
825
752
|
|
|
826
753
|
let Modal = function (cfg: TDBIModalOmitted<TNamespace>) {
|
|
827
754
|
let dbiModal = new DBIModal(self as any, cfg);
|
|
@@ -833,14 +760,6 @@ export class DBI<
|
|
|
833
760
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiModal.name, dbiModal as any);
|
|
834
761
|
return dbiModal;
|
|
835
762
|
};
|
|
836
|
-
Modal = Object.assign(
|
|
837
|
-
Modal,
|
|
838
|
-
class {
|
|
839
|
-
constructor(...args: any[]) {
|
|
840
|
-
return Modal.apply(this, args as any);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
);
|
|
844
763
|
|
|
845
764
|
let createInlineModal = function (cfg: Omit<TDBIModalOmitted<TNamespace>, "name" | "id">) {
|
|
846
765
|
let id = randomInlineId();
|
|
@@ -859,14 +778,6 @@ export class DBI<
|
|
|
859
778
|
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.locales.set(dbiLocale.name, dbiLocale);
|
|
860
779
|
return dbiLocale;
|
|
861
780
|
};
|
|
862
|
-
Locale = Object.assign(
|
|
863
|
-
Locale,
|
|
864
|
-
class {
|
|
865
|
-
constructor(...args: any[]) {
|
|
866
|
-
return Locale.apply(this, args as any);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
);
|
|
870
781
|
|
|
871
782
|
let CustomEvent = function (cfg: TDBICustomEventOmitted<TNamespace>) {
|
|
872
783
|
let dbiCustomEvent = new DBICustomEvent(self, cfg) as any;
|
|
@@ -878,20 +789,12 @@ export class DBI<
|
|
|
878
789
|
self.data.customEventNames.add(dbiCustomEvent.name);
|
|
879
790
|
return dbiCustomEvent;
|
|
880
791
|
};
|
|
881
|
-
CustomEvent = Object.assign(
|
|
882
|
-
CustomEvent,
|
|
883
|
-
class {
|
|
884
|
-
constructor(...args: any[]) {
|
|
885
|
-
return CustomEvent.apply(this, args as any);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
);
|
|
889
792
|
|
|
890
793
|
let InteractionLocale = function (cfg: TDBIInteractionLocaleOmitted) {
|
|
891
794
|
let dbiInteractionLocale = new DBIInteractionLocale(self, cfg);
|
|
892
795
|
if (
|
|
893
796
|
self.config.strict &&
|
|
894
|
-
self.data.
|
|
797
|
+
self.data.interactions.has(dbiInteractionLocale.name)
|
|
895
798
|
)
|
|
896
799
|
throw new Error(
|
|
897
800
|
`DBIInteractionLocale "${dbiInteractionLocale.name}" already loaded!`
|
|
@@ -902,14 +805,26 @@ export class DBI<
|
|
|
902
805
|
);
|
|
903
806
|
return dbiInteractionLocale;
|
|
904
807
|
};
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
808
|
+
|
|
809
|
+
let HTMLComponentsV2 = function (
|
|
810
|
+
cfg: TDBIHTMLComponentsV2Omitted<TNamespace>
|
|
811
|
+
) {
|
|
812
|
+
let dbiHTMLComponentsV2 = new DBIHTMLComponentsV2(self as any, cfg);
|
|
813
|
+
if (
|
|
814
|
+
self.config.strict &&
|
|
815
|
+
self.data.interactions.has(dbiHTMLComponentsV2.name)
|
|
816
|
+
)
|
|
817
|
+
throw new Error(
|
|
818
|
+
`DBIHTMLComponentsV2 "${dbiHTMLComponentsV2.name
|
|
819
|
+
}" already loaded as "${self.data.interactions.get(dbiHTMLComponentsV2.name)?.type
|
|
820
|
+
}"!`
|
|
821
|
+
);
|
|
822
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
823
|
+
dbiHTMLComponentsV2.name,
|
|
824
|
+
dbiHTMLComponentsV2 as any
|
|
825
|
+
);
|
|
826
|
+
return dbiHTMLComponentsV2;
|
|
827
|
+
};
|
|
913
828
|
|
|
914
829
|
await cb({
|
|
915
830
|
ChatInput,
|
|
@@ -926,6 +841,8 @@ export class DBI<
|
|
|
926
841
|
UserContextMenu,
|
|
927
842
|
CustomEvent,
|
|
928
843
|
Modal,
|
|
844
|
+
HTMLComponentsV2,
|
|
845
|
+
HTMLComponentsV2Handlers,
|
|
929
846
|
InteractionLocale,
|
|
930
847
|
createInlineButton,
|
|
931
848
|
createInlineEvent,
|
|
@@ -17,30 +17,34 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
17
17
|
async function handle(inter: Discord.Interaction<"cached">) {
|
|
18
18
|
const dbiInter =
|
|
19
19
|
(inter as any).dbiChatInput ??
|
|
20
|
-
dbi.data.interactions.find((
|
|
20
|
+
dbi.data.interactions.find((dbiInter) => {
|
|
21
21
|
let isUsesCustomId =
|
|
22
22
|
inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit();
|
|
23
23
|
let parsedId = isUsesCustomId
|
|
24
24
|
? parseCustomId(dbi, (inter as any).customId)
|
|
25
25
|
: null;
|
|
26
26
|
return (
|
|
27
|
-
(
|
|
27
|
+
(dbiInter.type == "ChatInput" &&
|
|
28
28
|
(inter.isChatInputCommand() || inter.isAutocomplete()) &&
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
dbiInter.name ==
|
|
30
|
+
[
|
|
31
|
+
inter.commandName,
|
|
32
|
+
inter.options.getSubcommandGroup(false),
|
|
33
|
+
inter.options.getSubcommand(false),
|
|
34
|
+
]
|
|
35
|
+
.filter((i) => !!i)
|
|
36
|
+
.join(" "))
|
|
37
|
+
||
|
|
38
|
+
((dbiInter.type == "MessageContextMenu" || dbiInter.type == "UserContextMenu") &&
|
|
38
39
|
(inter.isMessageContextMenuCommand() ||
|
|
39
40
|
inter.isUserContextMenuCommand()) &&
|
|
40
|
-
inter.commandName ==
|
|
41
|
-
|
|
41
|
+
inter.commandName == dbiInter.name)
|
|
42
|
+
||
|
|
43
|
+
(componentTypes.includes(dbiInter.type) &&
|
|
42
44
|
isUsesCustomId &&
|
|
43
|
-
parsedId?.name ==
|
|
45
|
+
parsedId?.name == dbiInter.name)
|
|
46
|
+
||
|
|
47
|
+
(parsedId.v2 && dbiInter.type == "HTMLComponentsV2" && parsedId.name == dbiInter.name)
|
|
44
48
|
);
|
|
45
49
|
});
|
|
46
50
|
|
|
@@ -65,10 +69,12 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
65
69
|
guild: guildLocale,
|
|
66
70
|
};
|
|
67
71
|
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
let parsedId = inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit()
|
|
73
|
+
? parseCustomId(dbi, inter.customId)
|
|
74
|
+
: undefined;
|
|
75
|
+
|
|
76
|
+
let data = parsedId?.data;
|
|
77
|
+
let v2 = parsedId?.v2 || false;
|
|
72
78
|
|
|
73
79
|
let other = {};
|
|
74
80
|
|
|
@@ -81,6 +87,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
81
87
|
data,
|
|
82
88
|
other,
|
|
83
89
|
dbiInteraction: dbiInter,
|
|
90
|
+
v2
|
|
84
91
|
}))
|
|
85
92
|
)
|
|
86
93
|
return;
|
|
@@ -100,6 +107,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
100
107
|
other,
|
|
101
108
|
locale,
|
|
102
109
|
step: "Autocomplete",
|
|
110
|
+
v2,
|
|
103
111
|
});
|
|
104
112
|
|
|
105
113
|
if (Array.isArray(res) && res.length > 0) {
|
|
@@ -119,6 +127,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
119
127
|
data,
|
|
120
128
|
other,
|
|
121
129
|
locale,
|
|
130
|
+
v2
|
|
122
131
|
});
|
|
123
132
|
await inter.respond(response);
|
|
124
133
|
}
|
|
@@ -153,6 +162,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
153
162
|
type: key,
|
|
154
163
|
...val,
|
|
155
164
|
},
|
|
165
|
+
v2
|
|
156
166
|
})) === true
|
|
157
167
|
)
|
|
158
168
|
return;
|
|
@@ -184,12 +194,12 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
184
194
|
? dcOption.attachment
|
|
185
195
|
: dbiOption.type ===
|
|
186
196
|
Discord.ApplicationCommandOptionType.Channel
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
? dcOption.channel
|
|
198
|
+
: dbiOption.type === Discord.ApplicationCommandOptionType.Role
|
|
199
|
+
? dcOption.role
|
|
200
|
+
: dbiOption.type === Discord.ApplicationCommandOptionType.User
|
|
201
|
+
? dcOption.user
|
|
202
|
+
: dcOption.value,
|
|
193
203
|
interaction: inter,
|
|
194
204
|
dbiInteraction: dbiInter,
|
|
195
205
|
dbi,
|
|
@@ -218,21 +228,55 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
218
228
|
data,
|
|
219
229
|
// @ts-ignore
|
|
220
230
|
other,
|
|
231
|
+
v2
|
|
221
232
|
};
|
|
222
233
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
|
|
235
|
+
if (dbiInter.type === "HTMLComponentsV2") {
|
|
236
|
+
if (dbi.config.strict) {
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
await dbiInter.onExecute?.(arg);
|
|
239
|
+
|
|
240
|
+
const elementName = data.shift();
|
|
241
|
+
dbiInter.handlers.forEach((handler) => {
|
|
242
|
+
if (handler.name === elementName) {
|
|
243
|
+
handler.onExecute(arg);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
try {
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
await dbiInter.onExecute?.(arg);
|
|
250
|
+
|
|
251
|
+
const elementName = data.shift();
|
|
252
|
+
dbiInter.handlers.forEach((handler) => {
|
|
253
|
+
if (handler.name === elementName) {
|
|
254
|
+
handler.onExecute(arg);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
} catch (error) {
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
await dbi.events.trigger(
|
|
260
|
+
"interactionError",
|
|
261
|
+
Object.assign(arg, { error })
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
226
265
|
} else {
|
|
227
|
-
|
|
266
|
+
if (dbi.config.strict) {
|
|
228
267
|
// @ts-ignore
|
|
229
268
|
await dbiInter.onExecute(arg);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
269
|
+
} else {
|
|
270
|
+
try {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
await dbiInter.onExecute(arg);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
// @ts-ignore
|
|
275
|
+
await dbi.events.trigger(
|
|
276
|
+
"interactionError",
|
|
277
|
+
Object.assign(arg, { error })
|
|
278
|
+
);
|
|
279
|
+
}
|
|
236
280
|
}
|
|
237
281
|
}
|
|
238
282
|
|
|
@@ -245,6 +289,7 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
245
289
|
setRateLimit,
|
|
246
290
|
data,
|
|
247
291
|
other,
|
|
292
|
+
v2
|
|
248
293
|
});
|
|
249
294
|
}
|
|
250
295
|
|
|
@@ -28,7 +28,7 @@ export interface IDBIValuedInteraction<
|
|
|
28
28
|
TNamespace extends NamespaceEnums,
|
|
29
29
|
TInteractionType extends Discord.Interaction,
|
|
30
30
|
TValueType = string | number
|
|
31
|
-
> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
31
|
+
> extends Omit<IDBIBaseExecuteCtx<TNamespace>, 'interaction'> {
|
|
32
32
|
value: TValueType;
|
|
33
33
|
interaction: TInteractionType;
|
|
34
34
|
}
|
|
@@ -312,11 +312,11 @@ export class DBIChatInputOptions<TNamespace extends NamespaceEnums> {
|
|
|
312
312
|
cfg: TDBIBaseOption & {
|
|
313
313
|
channelTypes: Discord.ChannelType[];
|
|
314
314
|
} & TDBIValidator<
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
TDBIValidateCtx<TNamespace, Discord.Channel>,
|
|
316
|
+
Discord.Channel,
|
|
317
|
+
"Result",
|
|
318
|
+
boolean
|
|
319
|
+
>
|
|
320
320
|
) {
|
|
321
321
|
return {
|
|
322
322
|
type: Discord.ApplicationCommandOptionType.Channel,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NamespaceEnums } from "../../../../generated/namespaceData";
|
|
2
|
+
import { DBI } from "../../../DBI";
|
|
3
|
+
import { IDBIButtonExecuteCtx } from "../Button";
|
|
4
|
+
import { IDBIChannelSelectMenuExecuteCtx } from "../ChannelSelectMenu";
|
|
5
|
+
import { IDBIMentionableSelectMenuExecuteCtx } from "../MentionableSelectMenu";
|
|
6
|
+
import { IDBIModalExecuteCtx } from "../Modal";
|
|
7
|
+
import { IDBIRoleSelectMenuExecuteCtx } from "../RoleSelectMenu";
|
|
8
|
+
import { IDBIStringSelectMenuExecuteCtx } from "../StringSelectMenu";
|
|
9
|
+
import { IDBIUserSelectMenuExecuteCtx } from "../UserSelectMenu";
|
|
10
|
+
|
|
11
|
+
export interface IDBIHanlder<TNamespace extends NamespaceEnums, TExecuteCtx> {
|
|
12
|
+
name: string;
|
|
13
|
+
onExecute?: (ctx: TExecuteCtx) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class DBIHTMLComponentsV2Handlers<TNamespace extends NamespaceEnums> {
|
|
17
|
+
dbi: DBI<TNamespace>;
|
|
18
|
+
|
|
19
|
+
constructor(dbi: DBI<TNamespace>) {
|
|
20
|
+
this.dbi = dbi;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
button(cfg: IDBIHanlder<TNamespace, IDBIButtonExecuteCtx<TNamespace>>) {
|
|
24
|
+
return {
|
|
25
|
+
name: cfg.name,
|
|
26
|
+
onExecute: cfg.onExecute,
|
|
27
|
+
type: "Button",
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
channelSelectMenu(cfg: IDBIHanlder<TNamespace, IDBIChannelSelectMenuExecuteCtx<TNamespace>>) {
|
|
32
|
+
return {
|
|
33
|
+
name: cfg.name,
|
|
34
|
+
onExecute: cfg.onExecute,
|
|
35
|
+
type: "ChannelSelectMenu",
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
mentionableSelectMenu(cfg: IDBIHanlder<TNamespace, IDBIMentionableSelectMenuExecuteCtx<TNamespace>>) {
|
|
40
|
+
return {
|
|
41
|
+
name: cfg.name,
|
|
42
|
+
onExecute: cfg.onExecute,
|
|
43
|
+
type: "MentionableSelectMenu",
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
modal(cfg: IDBIHanlder<TNamespace, IDBIModalExecuteCtx<TNamespace>>) {
|
|
48
|
+
return {
|
|
49
|
+
name: cfg.name,
|
|
50
|
+
onExecute: cfg.onExecute,
|
|
51
|
+
type: "Modal",
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
roleSelectMenu(cfg: IDBIHanlder<TNamespace, IDBIRoleSelectMenuExecuteCtx<TNamespace>>) {
|
|
56
|
+
return {
|
|
57
|
+
name: cfg.name,
|
|
58
|
+
onExecute: cfg.onExecute,
|
|
59
|
+
type: "RoleSelectMenu",
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
stringSelectMenu(cfg: IDBIHanlder<TNamespace, IDBIStringSelectMenuExecuteCtx<TNamespace>>) {
|
|
64
|
+
return {
|
|
65
|
+
name: cfg.name,
|
|
66
|
+
onExecute: cfg.onExecute,
|
|
67
|
+
type: "StringSelectMenu",
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
userSelectMenu(cfg: IDBIHanlder<TNamespace, IDBIUserSelectMenuExecuteCtx<TNamespace>>) {
|
|
72
|
+
return {
|
|
73
|
+
name: cfg.name,
|
|
74
|
+
onExecute: cfg.onExecute,
|
|
75
|
+
type: "UserSelectMenu",
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NamespaceEnums } from "../../../../generated/namespaceData";
|
|
2
|
+
import { DBI } from "../../../DBI";
|
|
3
|
+
import { DBIBaseInteraction, DBIRateLimit, IDBIBaseExecuteCtx, TDBIReferencedData } from "../../Interaction";
|
|
4
|
+
import { parseHTMLComponentsV2 } from "./parser";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
|
|
7
|
+
export type TDBIHTMLComponentsV2Omitted<TNamespace extends NamespaceEnums> = Omit<DBIHTMLComponentsV2<TNamespace>, "type" | "dbi" | "toJSON">;
|
|
8
|
+
|
|
9
|
+
export type TDBIHTMLComponentsV2ToJSONArgs = {
|
|
10
|
+
data?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IDBIHTMLComponentsV2ExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
14
|
+
data: TDBIReferencedData[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class DBIHTMLComponentsV2<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
18
|
+
template?: string;
|
|
19
|
+
file?: string;
|
|
20
|
+
|
|
21
|
+
constructor(dbi: DBI<TNamespace>, args: TDBIHTMLComponentsV2Omitted<TNamespace>) {
|
|
22
|
+
super(dbi, {
|
|
23
|
+
...(args as any),
|
|
24
|
+
type: "HTMLComponentsV2",
|
|
25
|
+
});
|
|
26
|
+
this.template = args.template || fs.readFileSync(args.file || "", "utf-8");
|
|
27
|
+
this.name = args.name;
|
|
28
|
+
this.handlers = args.handlers || [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override toJSON(arg: TDBIHTMLComponentsV2ToJSONArgs = {}): any {
|
|
32
|
+
return parseHTMLComponentsV2(
|
|
33
|
+
this.dbi as any,
|
|
34
|
+
this.template,
|
|
35
|
+
this.name,
|
|
36
|
+
{ data: arg.data }
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override onExecute?(ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) { };
|
|
41
|
+
|
|
42
|
+
handlers?: any[] = [];
|
|
43
|
+
}
|