@mostfeatured/dbi 0.0.66 → 0.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,130 +1,130 @@
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.isStringSelectMenu() || 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.isStringSelectMenu() || 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, dbiInteraction: dbiInter })))
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
- // @ts-ignore
89
- dbi,
90
- // @ts-ignore
91
- interaction: inter,
92
- // @ts-ignore
93
- dbiInteraction: dbiInter,
94
- // @ts-ignore
95
- locale,
96
- // @ts-ignore
97
- setRateLimit,
98
- // @ts-ignore
99
- data,
100
- // @ts-ignore
101
- other
102
- };
103
- if (dbi.config.strict) {
104
- // @ts-ignore
105
- await dbiInter.onExecute(arg);
106
- }
107
- else {
108
- try {
109
- // @ts-ignore
110
- await dbiInter.onExecute(arg);
111
- }
112
- catch (error) {
113
- // @ts-ignore
114
- await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
115
- }
116
- }
117
- // @ts-ignore
118
- dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
119
- }
120
- dbi.data.clients.forEach(d => {
121
- d.client.on("interactionCreate", handle);
122
- });
123
- return () => {
124
- dbi.data.clients.forEach(d => {
125
- d.client.off("interactionCreate", handle);
126
- });
127
- };
128
- }
129
- 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.isStringSelectMenu() || 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.isStringSelectMenu() || 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, dbiInteraction: dbiInter })))
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
+ // @ts-ignore
89
+ dbi,
90
+ // @ts-ignore
91
+ interaction: inter,
92
+ // @ts-ignore
93
+ dbiInteraction: dbiInter,
94
+ // @ts-ignore
95
+ locale,
96
+ // @ts-ignore
97
+ setRateLimit,
98
+ // @ts-ignore
99
+ data,
100
+ // @ts-ignore
101
+ other
102
+ };
103
+ if (dbi.config.strict) {
104
+ // @ts-ignore
105
+ await dbiInter.onExecute(arg);
106
+ }
107
+ else {
108
+ try {
109
+ // @ts-ignore
110
+ await dbiInter.onExecute(arg);
111
+ }
112
+ catch (error) {
113
+ // @ts-ignore
114
+ await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
115
+ }
116
+ }
117
+ // @ts-ignore
118
+ dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
119
+ }
120
+ dbi.data.clients.forEach(d => {
121
+ d.client.on("interactionCreate", handle);
122
+ });
123
+ return () => {
124
+ dbi.data.clients.forEach(d => {
125
+ d.client.off("interactionCreate", handle);
126
+ });
127
+ };
128
+ }
129
+ exports.hookInteractionListeners = hookInteractionListeners;
130
130
  //# sourceMappingURL=hookInteractionListeners.js.map
@@ -1,9 +1,9 @@
1
- import Discord from "discord.js";
2
- import { DBIChatInput } from "../types/ChatInput/ChatInput";
3
- import { DBIClientData } from "../DBI";
4
- import { DBIInteractionLocale } from "../types/InteractionLocale";
5
- import { NamespaceEnums } from "../../generated/namespaceData";
6
- export declare function publishInteractions(clients: DBIClientData<NamespaceEnums>[], interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>, interactionsLocales: Discord.Collection<string, DBIInteractionLocale>, publishType: "Guild" | "Global", guildId?: string): Promise<void>;
7
- export declare function localeifyOptions(options: any[], localeData: any): any[];
8
- export declare function formatLocale(locale: DBIInteractionLocale): any;
1
+ import Discord from "discord.js";
2
+ import { DBIChatInput } from "../types/ChatInput/ChatInput";
3
+ import { DBIClientData } from "../DBI";
4
+ import { DBIInteractionLocale } from "../types/InteractionLocale";
5
+ import { NamespaceEnums } from "../../generated/namespaceData";
6
+ export declare function publishInteractions(clients: DBIClientData<NamespaceEnums>[], interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>, interactionsLocales: Discord.Collection<string, DBIInteractionLocale>, publishType: "Guild" | "Global", guildId?: string): Promise<void>;
7
+ export declare function localeifyOptions(options: any[], localeData: any): any[];
8
+ export declare function formatLocale(locale: DBIInteractionLocale): any;
9
9
  //# sourceMappingURL=publishInteractions.d.ts.map