@mostfeatured/dbi 0.1.28 → 0.1.29
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.d.ts +4 -4
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js.map +1 -1
- package/dist/Events.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +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.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 +2 -2
- 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,260 +1,260 @@
|
|
|
1
|
-
import { DBI } from "../DBI";
|
|
2
|
-
import Discord, { CommandInteractionOption } from "discord.js";
|
|
3
|
-
import { parseCustomId } from "../utils/customId";
|
|
4
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
5
|
-
|
|
6
|
-
const componentTypes = [
|
|
7
|
-
"Button",
|
|
8
|
-
"StringSelectMenu",
|
|
9
|
-
"UserSelectMenu",
|
|
10
|
-
"RoleSelectMenu",
|
|
11
|
-
"ChannelSelectMenu",
|
|
12
|
-
"MentionableSelectMenu",
|
|
13
|
-
"Modal",
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
17
|
-
async function handle(inter: Discord.Interaction<"cached">) {
|
|
18
|
-
const dbiInter =
|
|
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;
|
|
26
|
-
return (
|
|
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
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!dbiInter) return;
|
|
48
|
-
|
|
49
|
-
let userLocaleName = inter.locale.split("-")[0];
|
|
50
|
-
let userLocale = dbi.data.locales.has(userLocaleName)
|
|
51
|
-
? dbi.data.locales.get(userLocaleName)
|
|
52
|
-
: dbi.data.locales.get(dbi.config.defaults.locale.name);
|
|
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.name)
|
|
61
|
-
: null;
|
|
62
|
-
|
|
63
|
-
let locale = {
|
|
64
|
-
user: userLocale,
|
|
65
|
-
guild: guildLocale,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
let data =
|
|
69
|
-
inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit()
|
|
70
|
-
? parseCustomId(dbi, inter.customId).data
|
|
71
|
-
: undefined;
|
|
72
|
-
|
|
73
|
-
let other = {};
|
|
74
|
-
|
|
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
|
-
|
|
88
|
-
if (inter.isAutocomplete()) {
|
|
89
|
-
let focussed = inter.options.getFocused(true);
|
|
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
|
-
|
|
113
|
-
if (option?.onComplete) {
|
|
114
|
-
let response = await option.onComplete({
|
|
115
|
-
value: focussed.value,
|
|
116
|
-
interaction: inter,
|
|
117
|
-
dbiInteraction: dbiInter,
|
|
118
|
-
dbi,
|
|
119
|
-
data,
|
|
120
|
-
other,
|
|
121
|
-
locale,
|
|
122
|
-
});
|
|
123
|
-
await inter.respond(response);
|
|
124
|
-
}
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let rateLimitKeyMap = {
|
|
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
|
-
};
|
|
135
|
-
|
|
136
|
-
for (const type in rateLimitKeyMap) {
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
139
|
-
let val = await dbi.config.store.get(key);
|
|
140
|
-
if (val && Date.now() > val.at + val.duration) {
|
|
141
|
-
await dbi.config.store.delete(key);
|
|
142
|
-
val = null;
|
|
143
|
-
}
|
|
144
|
-
if (val) {
|
|
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;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async function setRateLimit(type: string, duration: number) {
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, {
|
|
165
|
-
at: Date.now(),
|
|
166
|
-
duration,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
for (const rateLimit of dbiInter.rateLimits) {
|
|
171
|
-
await setRateLimit(rateLimit.type, rateLimit.duration);
|
|
172
|
-
}
|
|
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:
|
|
183
|
-
dbiOption.type === Discord.ApplicationCommandOptionType.Attachment
|
|
184
|
-
? dcOption.attachment
|
|
185
|
-
: dbiOption.type ===
|
|
186
|
-
Discord.ApplicationCommandOptionType.Channel
|
|
187
|
-
? dcOption.channel
|
|
188
|
-
: dbiOption.type === Discord.ApplicationCommandOptionType.Role
|
|
189
|
-
? dcOption.role
|
|
190
|
-
: dbiOption.type === Discord.ApplicationCommandOptionType.User
|
|
191
|
-
? dcOption.user
|
|
192
|
-
: dcOption.value,
|
|
193
|
-
interaction: inter,
|
|
194
|
-
dbiInteraction: dbiInter,
|
|
195
|
-
dbi,
|
|
196
|
-
data,
|
|
197
|
-
other,
|
|
198
|
-
locale,
|
|
199
|
-
step: "Result",
|
|
200
|
-
});
|
|
201
|
-
if (res !== true) return;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let arg = {
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
dbi,
|
|
209
|
-
// @ts-ignore
|
|
210
|
-
interaction: inter as any,
|
|
211
|
-
// @ts-ignore
|
|
212
|
-
dbiInteraction: dbiInter,
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
locale,
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
setRateLimit,
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
data,
|
|
219
|
-
// @ts-ignore
|
|
220
|
-
other,
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
if (dbi.config.strict) {
|
|
224
|
-
// @ts-ignore
|
|
225
|
-
await dbiInter.onExecute(arg);
|
|
226
|
-
} else {
|
|
227
|
-
try {
|
|
228
|
-
// @ts-ignore
|
|
229
|
-
await dbiInter.onExecute(arg);
|
|
230
|
-
} catch (error) {
|
|
231
|
-
// @ts-ignore
|
|
232
|
-
await dbi.events.trigger(
|
|
233
|
-
"interactionError",
|
|
234
|
-
Object.assign(arg, { error })
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// @ts-ignore
|
|
240
|
-
dbi.events.trigger("afterInteraction", {
|
|
241
|
-
dbi,
|
|
242
|
-
interaction: inter,
|
|
243
|
-
dbiInteraction: dbiInter,
|
|
244
|
-
locale,
|
|
245
|
-
setRateLimit,
|
|
246
|
-
data,
|
|
247
|
-
other,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
dbi.data.clients.forEach((d) => {
|
|
252
|
-
d.client.on("interactionCreate", handle);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
return () => {
|
|
256
|
-
dbi.data.clients.forEach((d) => {
|
|
257
|
-
d.client.off("interactionCreate", handle);
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
|
-
}
|
|
1
|
+
import { DBI } from "../DBI";
|
|
2
|
+
import Discord, { CommandInteractionOption } from "discord.js";
|
|
3
|
+
import { parseCustomId } from "../utils/customId";
|
|
4
|
+
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
5
|
+
|
|
6
|
+
const componentTypes = [
|
|
7
|
+
"Button",
|
|
8
|
+
"StringSelectMenu",
|
|
9
|
+
"UserSelectMenu",
|
|
10
|
+
"RoleSelectMenu",
|
|
11
|
+
"ChannelSelectMenu",
|
|
12
|
+
"MentionableSelectMenu",
|
|
13
|
+
"Modal",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
17
|
+
async function handle(inter: Discord.Interaction<"cached">) {
|
|
18
|
+
const dbiInter =
|
|
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;
|
|
26
|
+
return (
|
|
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
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!dbiInter) return;
|
|
48
|
+
|
|
49
|
+
let userLocaleName = inter.locale.split("-")[0];
|
|
50
|
+
let userLocale = dbi.data.locales.has(userLocaleName)
|
|
51
|
+
? dbi.data.locales.get(userLocaleName)
|
|
52
|
+
: dbi.data.locales.get(dbi.config.defaults.locale.name);
|
|
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.name)
|
|
61
|
+
: null;
|
|
62
|
+
|
|
63
|
+
let locale = {
|
|
64
|
+
user: userLocale,
|
|
65
|
+
guild: guildLocale,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let data =
|
|
69
|
+
inter.isButton() || inter.isAnySelectMenu() || inter.isModalSubmit()
|
|
70
|
+
? parseCustomId(dbi, inter.customId).data
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
73
|
+
let other = {};
|
|
74
|
+
|
|
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
|
+
|
|
88
|
+
if (inter.isAutocomplete()) {
|
|
89
|
+
let focussed = inter.options.getFocused(true);
|
|
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
|
+
|
|
113
|
+
if (option?.onComplete) {
|
|
114
|
+
let response = await option.onComplete({
|
|
115
|
+
value: focussed.value,
|
|
116
|
+
interaction: inter,
|
|
117
|
+
dbiInteraction: dbiInter,
|
|
118
|
+
dbi,
|
|
119
|
+
data,
|
|
120
|
+
other,
|
|
121
|
+
locale,
|
|
122
|
+
});
|
|
123
|
+
await inter.respond(response);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let rateLimitKeyMap = {
|
|
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
|
+
};
|
|
135
|
+
|
|
136
|
+
for (const type in rateLimitKeyMap) {
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
139
|
+
let val = await dbi.config.store.get(key);
|
|
140
|
+
if (val && Date.now() > val.at + val.duration) {
|
|
141
|
+
await dbi.config.store.delete(key);
|
|
142
|
+
val = null;
|
|
143
|
+
}
|
|
144
|
+
if (val) {
|
|
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;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function setRateLimit(type: string, duration: number) {
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, {
|
|
165
|
+
at: Date.now(),
|
|
166
|
+
duration,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const rateLimit of dbiInter.rateLimits) {
|
|
171
|
+
await setRateLimit(rateLimit.type, rateLimit.duration);
|
|
172
|
+
}
|
|
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:
|
|
183
|
+
dbiOption.type === Discord.ApplicationCommandOptionType.Attachment
|
|
184
|
+
? dcOption.attachment
|
|
185
|
+
: dbiOption.type ===
|
|
186
|
+
Discord.ApplicationCommandOptionType.Channel
|
|
187
|
+
? dcOption.channel
|
|
188
|
+
: dbiOption.type === Discord.ApplicationCommandOptionType.Role
|
|
189
|
+
? dcOption.role
|
|
190
|
+
: dbiOption.type === Discord.ApplicationCommandOptionType.User
|
|
191
|
+
? dcOption.user
|
|
192
|
+
: dcOption.value,
|
|
193
|
+
interaction: inter,
|
|
194
|
+
dbiInteraction: dbiInter,
|
|
195
|
+
dbi,
|
|
196
|
+
data,
|
|
197
|
+
other,
|
|
198
|
+
locale,
|
|
199
|
+
step: "Result",
|
|
200
|
+
});
|
|
201
|
+
if (res !== true) return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let arg = {
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
dbi,
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
interaction: inter as any,
|
|
211
|
+
// @ts-ignore
|
|
212
|
+
dbiInteraction: dbiInter,
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
locale,
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
setRateLimit,
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
data,
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
other,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (dbi.config.strict) {
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
await dbiInter.onExecute(arg);
|
|
226
|
+
} else {
|
|
227
|
+
try {
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
await dbiInter.onExecute(arg);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
await dbi.events.trigger(
|
|
233
|
+
"interactionError",
|
|
234
|
+
Object.assign(arg, { error })
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
dbi.events.trigger("afterInteraction", {
|
|
241
|
+
dbi,
|
|
242
|
+
interaction: inter,
|
|
243
|
+
dbiInteraction: dbiInter,
|
|
244
|
+
locale,
|
|
245
|
+
setRateLimit,
|
|
246
|
+
data,
|
|
247
|
+
other,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
dbi.data.clients.forEach((d) => {
|
|
252
|
+
d.client.on("interactionCreate", handle);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return () => {
|
|
256
|
+
dbi.data.clients.forEach((d) => {
|
|
257
|
+
d.client.off("interactionCreate", handle);
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
}
|