@mostfeatured/dbi 0.0.53 → 0.0.55
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 +156 -156
- package/dist/DBI.js +332 -332
- package/dist/Events.d.ts +53 -53
- package/dist/Events.js +58 -58
- package/dist/data/eventMap.json +234 -234
- package/dist/index.d.ts +6 -6
- package/dist/index.js +16 -16
- package/dist/methods/hookEventListeners.d.ts +3 -3
- package/dist/methods/hookEventListeners.js +87 -87
- package/dist/methods/hookInteractionListeners.d.ts +3 -3
- package/dist/methods/hookInteractionListeners.js +118 -118
- package/dist/methods/publishInteractions.d.ts +7 -7
- package/dist/methods/publishInteractions.js +238 -238
- package/dist/types/Button.d.ts +18 -16
- package/dist/types/Button.d.ts.map +1 -1
- package/dist/types/Button.js +31 -27
- package/dist/types/Button.js.map +1 -1
- package/dist/types/ButtonBuilder.d.ts +30 -0
- package/dist/types/ButtonBuilder.d.ts.map +1 -0
- package/dist/types/ButtonBuilder.js +43 -0
- package/dist/types/ButtonBuilder.js.map +1 -0
- package/dist/types/ChatInput/ChatInput.d.ts +15 -15
- package/dist/types/ChatInput/ChatInput.js +20 -20
- package/dist/types/ChatInput/ChatInputOptions.d.ts +162 -161
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js +161 -160
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/dist/types/CustomEvent.d.ts +13 -13
- package/dist/types/CustomEvent.js +19 -19
- package/dist/types/Event.d.ts +263 -263
- package/dist/types/Event.js +22 -22
- package/dist/types/Interaction.d.ts +47 -47
- package/dist/types/Interaction.js +24 -24
- package/dist/types/InteractionLocale.d.ts +25 -25
- package/dist/types/InteractionLocale.js +14 -14
- package/dist/types/Locale.d.ts +21 -21
- package/dist/types/Locale.js +38 -38
- package/dist/types/MessageContextMenu.d.ts +14 -14
- package/dist/types/MessageContextMenu.js +18 -18
- package/dist/types/Modal.d.ts +22 -20
- package/dist/types/Modal.d.ts.map +1 -1
- package/dist/types/Modal.js +29 -25
- package/dist/types/Modal.js.map +1 -1
- package/dist/types/ModalBuilder.d.ts +31 -0
- package/dist/types/ModalBuilder.d.ts.map +1 -0
- package/dist/types/ModalBuilder.js +43 -0
- package/dist/types/ModalBuilder.js.map +1 -0
- package/dist/types/SelectMenu.d.ts +18 -16
- package/dist/types/SelectMenu.d.ts.map +1 -1
- package/dist/types/SelectMenu.js +31 -27
- package/dist/types/SelectMenu.js.map +1 -1
- package/dist/types/SelectMenuBuilder.d.ts +28 -0
- package/dist/types/SelectMenuBuilder.d.ts.map +1 -0
- package/dist/types/SelectMenuBuilder.js +43 -0
- package/dist/types/SelectMenuBuilder.js.map +1 -0
- package/dist/types/UserContextMenu.d.ts +14 -14
- package/dist/types/UserContextMenu.js +18 -18
- package/dist/utils/MemoryStore.d.ts +8 -8
- package/dist/utils/MemoryStore.js +29 -29
- package/dist/utils/UtilTypes.d.ts +7 -7
- package/dist/utils/UtilTypes.d.ts.map +1 -1
- package/dist/utils/UtilTypes.js +2 -2
- package/dist/utils/UtilTypes.js.map +1 -1
- package/dist/utils/customId.d.ts +7 -7
- package/dist/utils/customId.js +45 -45
- package/dist/utils/permissions.d.ts +2 -2
- package/dist/utils/permissions.js +8 -8
- package/dist/utils/recursiveImport.d.ts +4 -4
- package/dist/utils/recursiveImport.js +26 -26
- package/package.json +2 -2
- package/src/types/Button.ts +7 -2
- package/src/types/ButtonBuilder.ts +52 -0
- package/src/types/ChatInput/ChatInputOptions.ts +1 -0
- package/src/types/Modal.ts +8 -2
- package/src/types/ModalBuilder.ts +52 -0
- package/src/types/SelectMenu.ts +8 -2
- package/src/types/SelectMenuBuilder.ts +52 -0
- package/src/utils/UtilTypes.ts +1 -1
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookEventListeners = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
function hookEventListeners(dbi) {
|
|
6
|
-
async function handle(eventName, ...args) {
|
|
7
|
-
if (!dbi.data.eventMap[eventName])
|
|
8
|
-
return;
|
|
9
|
-
let isDirect = args?.[0]?._DIRECT_ ?? false;
|
|
10
|
-
if (isDirect)
|
|
11
|
-
delete args[0]._DIRECT_;
|
|
12
|
-
let ctxArgs = isDirect
|
|
13
|
-
? args[0]
|
|
14
|
-
: dbi.data.eventMap[eventName].reduce((all, current, index) => {
|
|
15
|
-
all[current] = args[index];
|
|
16
|
-
return all;
|
|
17
|
-
}, {});
|
|
18
|
-
let other = {};
|
|
19
|
-
let guildLocaleName = args.reduce((all, current) => {
|
|
20
|
-
if (current?.guild?.id)
|
|
21
|
-
return current?.guild?.preferredLocale?.split?.("-")?.[0];
|
|
22
|
-
if (current instanceof discord_js_1.Guild)
|
|
23
|
-
return current?.preferredLocale?.split?.("-")?.[0];
|
|
24
|
-
return all;
|
|
25
|
-
}, null);
|
|
26
|
-
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
27
|
-
let locale = guildLocale ? { guild: guildLocale } : null;
|
|
28
|
-
if (!await dbi.events.trigger("beforeEvent", { eventName, ...ctxArgs, other, locale }))
|
|
29
|
-
return;
|
|
30
|
-
let ordered = [];
|
|
31
|
-
let unOrdered = [];
|
|
32
|
-
for (let i = 0; i < dbi.data.events.size; i++) {
|
|
33
|
-
const value = dbi.data.events.at(i);
|
|
34
|
-
if (value.name == eventName) {
|
|
35
|
-
if (value.ordered) {
|
|
36
|
-
ordered.push(value);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
unOrdered.push(value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let arg = { eventName, ...ctxArgs, other, locale };
|
|
44
|
-
for (let i = 0; i < unOrdered.length; i++) {
|
|
45
|
-
const value = unOrdered[i];
|
|
46
|
-
if (dbi.config.strict) {
|
|
47
|
-
value.onExecute(arg);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
try {
|
|
51
|
-
value.onExecute(arg)?.catch(error => {
|
|
52
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
for (let i = 0; i < ordered.length; i++) {
|
|
61
|
-
const value = ordered[i];
|
|
62
|
-
if (dbi.config.strict) {
|
|
63
|
-
await value.onExecute(arg);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
try {
|
|
67
|
-
await value.onExecute(arg)?.catch(error => {
|
|
68
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
await dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
dbi.events.trigger("afterEvent", arg);
|
|
77
|
-
}
|
|
78
|
-
let originalEmit = dbi.client.emit;
|
|
79
|
-
dbi.client.emit = function (eventName, ...args) {
|
|
80
|
-
handle(eventName, ...args);
|
|
81
|
-
return originalEmit.call(this, eventName, ...args);
|
|
82
|
-
};
|
|
83
|
-
return () => {
|
|
84
|
-
dbi.client.emit = originalEmit;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
exports.hookEventListeners = hookEventListeners;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookEventListeners = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
function hookEventListeners(dbi) {
|
|
6
|
+
async function handle(eventName, ...args) {
|
|
7
|
+
if (!dbi.data.eventMap[eventName])
|
|
8
|
+
return;
|
|
9
|
+
let isDirect = args?.[0]?._DIRECT_ ?? false;
|
|
10
|
+
if (isDirect)
|
|
11
|
+
delete args[0]._DIRECT_;
|
|
12
|
+
let ctxArgs = isDirect
|
|
13
|
+
? args[0]
|
|
14
|
+
: dbi.data.eventMap[eventName].reduce((all, current, index) => {
|
|
15
|
+
all[current] = args[index];
|
|
16
|
+
return all;
|
|
17
|
+
}, {});
|
|
18
|
+
let other = {};
|
|
19
|
+
let guildLocaleName = args.reduce((all, current) => {
|
|
20
|
+
if (current?.guild?.id)
|
|
21
|
+
return current?.guild?.preferredLocale?.split?.("-")?.[0];
|
|
22
|
+
if (current instanceof discord_js_1.Guild)
|
|
23
|
+
return current?.preferredLocale?.split?.("-")?.[0];
|
|
24
|
+
return all;
|
|
25
|
+
}, null);
|
|
26
|
+
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
27
|
+
let locale = guildLocale ? { guild: guildLocale } : null;
|
|
28
|
+
if (!await dbi.events.trigger("beforeEvent", { eventName, ...ctxArgs, other, locale }))
|
|
29
|
+
return;
|
|
30
|
+
let ordered = [];
|
|
31
|
+
let unOrdered = [];
|
|
32
|
+
for (let i = 0; i < dbi.data.events.size; i++) {
|
|
33
|
+
const value = dbi.data.events.at(i);
|
|
34
|
+
if (value.name == eventName) {
|
|
35
|
+
if (value.ordered) {
|
|
36
|
+
ordered.push(value);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
unOrdered.push(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let arg = { eventName, ...ctxArgs, other, locale };
|
|
44
|
+
for (let i = 0; i < unOrdered.length; i++) {
|
|
45
|
+
const value = unOrdered[i];
|
|
46
|
+
if (dbi.config.strict) {
|
|
47
|
+
value.onExecute(arg);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
try {
|
|
51
|
+
value.onExecute(arg)?.catch(error => {
|
|
52
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
61
|
+
const value = ordered[i];
|
|
62
|
+
if (dbi.config.strict) {
|
|
63
|
+
await value.onExecute(arg);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
try {
|
|
67
|
+
await value.onExecute(arg)?.catch(error => {
|
|
68
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
await dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
dbi.events.trigger("afterEvent", arg);
|
|
77
|
+
}
|
|
78
|
+
let originalEmit = dbi.client.emit;
|
|
79
|
+
dbi.client.emit = function (eventName, ...args) {
|
|
80
|
+
handle(eventName, ...args);
|
|
81
|
+
return originalEmit.call(this, eventName, ...args);
|
|
82
|
+
};
|
|
83
|
+
return () => {
|
|
84
|
+
dbi.client.emit = originalEmit;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.hookEventListeners = hookEventListeners;
|
|
88
88
|
//# sourceMappingURL=hookEventListeners.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBI } from "../DBI";
|
|
2
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
3
|
-
export declare function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any;
|
|
1
|
+
import { DBI } from "../DBI";
|
|
2
|
+
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
3
|
+
export declare function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any;
|
|
4
4
|
//# sourceMappingURL=hookInteractionListeners.d.ts.map
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookInteractionListeners = void 0;
|
|
4
|
-
const customId_1 = require("../utils/customId");
|
|
5
|
-
function hookInteractionListeners(dbi) {
|
|
6
|
-
async function handle(inter) {
|
|
7
|
-
const dbiInter = dbi.data.interactions.find(i => {
|
|
8
|
-
let isUsesCustomId = (inter.isButton() || inter.isSelectMenu() || inter.isModalSubmit());
|
|
9
|
-
let parsedId = isUsesCustomId ? (0, customId_1.parseCustomId)(dbi, inter.customId) : null;
|
|
10
|
-
return ((i.type == "ChatInput"
|
|
11
|
-
&& (inter.isChatInputCommand() || inter.isAutocomplete())
|
|
12
|
-
&& i.name == [inter.commandName, inter.options.getSubcommandGroup(false), inter.options.getSubcommand(false)].filter(i => !!i).join(" "))
|
|
13
|
-
||
|
|
14
|
-
((i.type == "MessageContextMenu" || i.type == "UserContextMenu")
|
|
15
|
-
&& (inter.isMessageContextMenuCommand() || inter.isUserContextMenuCommand())
|
|
16
|
-
&& inter.commandName == i.name)
|
|
17
|
-
||
|
|
18
|
-
((i.type == "Button" || i.type == "SelectMenu" || i.type == "Modal")
|
|
19
|
-
&& isUsesCustomId
|
|
20
|
-
&& parsedId?.name == i.name));
|
|
21
|
-
});
|
|
22
|
-
if (!dbiInter)
|
|
23
|
-
return;
|
|
24
|
-
let userLocaleName = inter.locale.split("-")[0];
|
|
25
|
-
let userLocale = dbi.data.locales.has(userLocaleName) ? dbi.data.locales.get(userLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale);
|
|
26
|
-
let guildLocaleName = inter.guild ? inter.guild.preferredLocale.split("-")[0] : null;
|
|
27
|
-
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
28
|
-
let locale = {
|
|
29
|
-
user: userLocale,
|
|
30
|
-
guild: guildLocale
|
|
31
|
-
};
|
|
32
|
-
let data = (inter.isButton() || inter.isSelectMenu() || inter.isModalSubmit()) ? (0, customId_1.parseCustomId)(dbi, inter.customId).data : undefined;
|
|
33
|
-
let other = {};
|
|
34
|
-
if (!(await dbi.events.trigger("beforeInteraction", { dbi, interaction: inter, locale, setRateLimit, data, other })))
|
|
35
|
-
return;
|
|
36
|
-
if (inter.isAutocomplete()) {
|
|
37
|
-
let focussed = inter.options.getFocused(true);
|
|
38
|
-
let option = dbiInter.options.find(i => i.name == focussed.name);
|
|
39
|
-
if (option?.onComplete) {
|
|
40
|
-
let response = await option.onComplete({
|
|
41
|
-
value: focussed.value,
|
|
42
|
-
interaction: inter,
|
|
43
|
-
dbiInteraction: dbiInter,
|
|
44
|
-
dbi,
|
|
45
|
-
data,
|
|
46
|
-
other,
|
|
47
|
-
locale
|
|
48
|
-
});
|
|
49
|
-
await inter.respond(response);
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
let rateLimitKeyMap = {
|
|
54
|
-
"User": `${dbiInter.name}_${inter.user.id}`,
|
|
55
|
-
"Channel": `${dbiInter.name}_${inter.channelId || "Channel"}`,
|
|
56
|
-
"Guild": `${dbiInter.name}_${inter.guildId || "Guild"}`,
|
|
57
|
-
"Member": `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
|
|
58
|
-
"Message": `${dbiInter.name}_${inter?.message?.id}`
|
|
59
|
-
};
|
|
60
|
-
for (const type in rateLimitKeyMap) {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
63
|
-
let val = await dbi.config.store.get(key);
|
|
64
|
-
if (val && Date.now() > val.at + val.duration) {
|
|
65
|
-
await dbi.config.store.delete(key);
|
|
66
|
-
val = null;
|
|
67
|
-
}
|
|
68
|
-
if (val) {
|
|
69
|
-
dbi.events.trigger("interactionRateLimit", {
|
|
70
|
-
dbi,
|
|
71
|
-
interaction: inter,
|
|
72
|
-
dbiInteraction: dbiInter,
|
|
73
|
-
locale,
|
|
74
|
-
data,
|
|
75
|
-
rateLimit: {
|
|
76
|
-
type: key,
|
|
77
|
-
...val
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function setRateLimit(type, duration) {
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, { at: Date.now(), duration });
|
|
86
|
-
}
|
|
87
|
-
let arg = {
|
|
88
|
-
dbi,
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
interaction: inter,
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
dbiInteraction: dbiInter,
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
locale,
|
|
95
|
-
setRateLimit,
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
data,
|
|
98
|
-
other
|
|
99
|
-
};
|
|
100
|
-
if (dbi.config.strict) {
|
|
101
|
-
await dbiInter.onExecute(arg);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
try {
|
|
105
|
-
await dbiInter.onExecute(arg);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
|
|
112
|
-
}
|
|
113
|
-
dbi.client.on("interactionCreate", handle);
|
|
114
|
-
return () => {
|
|
115
|
-
dbi.client.off("interactionCreate", handle);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
exports.hookInteractionListeners = hookInteractionListeners;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookInteractionListeners = void 0;
|
|
4
|
+
const customId_1 = require("../utils/customId");
|
|
5
|
+
function hookInteractionListeners(dbi) {
|
|
6
|
+
async function handle(inter) {
|
|
7
|
+
const dbiInter = dbi.data.interactions.find(i => {
|
|
8
|
+
let isUsesCustomId = (inter.isButton() || inter.isSelectMenu() || inter.isModalSubmit());
|
|
9
|
+
let parsedId = isUsesCustomId ? (0, customId_1.parseCustomId)(dbi, inter.customId) : null;
|
|
10
|
+
return ((i.type == "ChatInput"
|
|
11
|
+
&& (inter.isChatInputCommand() || inter.isAutocomplete())
|
|
12
|
+
&& i.name == [inter.commandName, inter.options.getSubcommandGroup(false), inter.options.getSubcommand(false)].filter(i => !!i).join(" "))
|
|
13
|
+
||
|
|
14
|
+
((i.type == "MessageContextMenu" || i.type == "UserContextMenu")
|
|
15
|
+
&& (inter.isMessageContextMenuCommand() || inter.isUserContextMenuCommand())
|
|
16
|
+
&& inter.commandName == i.name)
|
|
17
|
+
||
|
|
18
|
+
((i.type == "Button" || i.type == "SelectMenu" || i.type == "Modal")
|
|
19
|
+
&& isUsesCustomId
|
|
20
|
+
&& parsedId?.name == i.name));
|
|
21
|
+
});
|
|
22
|
+
if (!dbiInter)
|
|
23
|
+
return;
|
|
24
|
+
let userLocaleName = inter.locale.split("-")[0];
|
|
25
|
+
let userLocale = dbi.data.locales.has(userLocaleName) ? dbi.data.locales.get(userLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale);
|
|
26
|
+
let guildLocaleName = inter.guild ? inter.guild.preferredLocale.split("-")[0] : null;
|
|
27
|
+
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
28
|
+
let locale = {
|
|
29
|
+
user: userLocale,
|
|
30
|
+
guild: guildLocale
|
|
31
|
+
};
|
|
32
|
+
let data = (inter.isButton() || inter.isSelectMenu() || inter.isModalSubmit()) ? (0, customId_1.parseCustomId)(dbi, inter.customId).data : undefined;
|
|
33
|
+
let other = {};
|
|
34
|
+
if (!(await dbi.events.trigger("beforeInteraction", { dbi, interaction: inter, locale, setRateLimit, data, other })))
|
|
35
|
+
return;
|
|
36
|
+
if (inter.isAutocomplete()) {
|
|
37
|
+
let focussed = inter.options.getFocused(true);
|
|
38
|
+
let option = dbiInter.options.find(i => i.name == focussed.name);
|
|
39
|
+
if (option?.onComplete) {
|
|
40
|
+
let response = await option.onComplete({
|
|
41
|
+
value: focussed.value,
|
|
42
|
+
interaction: inter,
|
|
43
|
+
dbiInteraction: dbiInter,
|
|
44
|
+
dbi,
|
|
45
|
+
data,
|
|
46
|
+
other,
|
|
47
|
+
locale
|
|
48
|
+
});
|
|
49
|
+
await inter.respond(response);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let rateLimitKeyMap = {
|
|
54
|
+
"User": `${dbiInter.name}_${inter.user.id}`,
|
|
55
|
+
"Channel": `${dbiInter.name}_${inter.channelId || "Channel"}`,
|
|
56
|
+
"Guild": `${dbiInter.name}_${inter.guildId || "Guild"}`,
|
|
57
|
+
"Member": `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
|
|
58
|
+
"Message": `${dbiInter.name}_${inter?.message?.id}`
|
|
59
|
+
};
|
|
60
|
+
for (const type in rateLimitKeyMap) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
63
|
+
let val = await dbi.config.store.get(key);
|
|
64
|
+
if (val && Date.now() > val.at + val.duration) {
|
|
65
|
+
await dbi.config.store.delete(key);
|
|
66
|
+
val = null;
|
|
67
|
+
}
|
|
68
|
+
if (val) {
|
|
69
|
+
dbi.events.trigger("interactionRateLimit", {
|
|
70
|
+
dbi,
|
|
71
|
+
interaction: inter,
|
|
72
|
+
dbiInteraction: dbiInter,
|
|
73
|
+
locale,
|
|
74
|
+
data,
|
|
75
|
+
rateLimit: {
|
|
76
|
+
type: key,
|
|
77
|
+
...val
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function setRateLimit(type, duration) {
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, { at: Date.now(), duration });
|
|
86
|
+
}
|
|
87
|
+
let arg = {
|
|
88
|
+
dbi,
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
interaction: inter,
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
dbiInteraction: dbiInter,
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
locale,
|
|
95
|
+
setRateLimit,
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
data,
|
|
98
|
+
other
|
|
99
|
+
};
|
|
100
|
+
if (dbi.config.strict) {
|
|
101
|
+
await dbiInter.onExecute(arg);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
try {
|
|
105
|
+
await dbiInter.onExecute(arg);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
|
|
112
|
+
}
|
|
113
|
+
dbi.client.on("interactionCreate", handle);
|
|
114
|
+
return () => {
|
|
115
|
+
dbi.client.off("interactionCreate", handle);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
exports.hookInteractionListeners = hookInteractionListeners;
|
|
119
119
|
//# sourceMappingURL=hookInteractionListeners.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Discord from "discord.js";
|
|
2
|
-
import { DBIChatInput } from "../types/ChatInput/ChatInput";
|
|
3
|
-
import { DBIInteractionLocale } from "../types/InteractionLocale";
|
|
4
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
5
|
-
export declare function publishInteractions(clientToken: string, interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>, interactionsLocales: Discord.Collection<string, DBIInteractionLocale>, publishType: "Guild" | "Global", guildId?: string): Promise<void>;
|
|
6
|
-
export declare function localeifyOptions(options: any[], localeData: any): any[];
|
|
7
|
-
export declare function formatLocale(locale: DBIInteractionLocale): any;
|
|
1
|
+
import Discord from "discord.js";
|
|
2
|
+
import { DBIChatInput } from "../types/ChatInput/ChatInput";
|
|
3
|
+
import { DBIInteractionLocale } from "../types/InteractionLocale";
|
|
4
|
+
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
5
|
+
export declare function publishInteractions(clientToken: string, interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>, interactionsLocales: Discord.Collection<string, DBIInteractionLocale>, publishType: "Guild" | "Global", guildId?: string): Promise<void>;
|
|
6
|
+
export declare function localeifyOptions(options: any[], localeData: any): any[];
|
|
7
|
+
export declare function formatLocale(locale: DBIInteractionLocale): any;
|
|
8
8
|
//# sourceMappingURL=publishInteractions.d.ts.map
|