@mostfeatured/dbi 0.0.63 โ 0.0.65
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 +20 -5
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +48 -17
- package/dist/DBI.js.map +1 -1
- package/dist/index.d.ts +16 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -16
- package/dist/index.js.map +1 -1
- package/dist/methods/hookEventListeners.d.ts.map +1 -1
- package/dist/methods/hookEventListeners.js +97 -87
- package/dist/methods/hookEventListeners.js.map +1 -1
- package/dist/methods/hookInteractionListeners.d.ts.map +1 -1
- package/dist/methods/hookInteractionListeners.js +129 -125
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/methods/publishInteractions.d.ts +8 -7
- package/dist/methods/publishInteractions.d.ts.map +1 -1
- package/dist/methods/publishInteractions.js +26 -21
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/Button.js +1 -1
- package/dist/types/Button.js.map +1 -1
- package/dist/types/CustomEvent.js +19 -19
- package/dist/types/CustomEvent.js.map +1 -1
- package/dist/types/Event.d.ts +265 -263
- package/dist/types/Event.d.ts.map +1 -1
- package/dist/types/Event.js +24 -22
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +49 -47
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js +26 -24
- package/dist/types/Interaction.js.map +1 -1
- package/dist/types/Modal.js +1 -1
- package/dist/types/Modal.js.map +1 -1
- package/dist/types/SelectMenu.js +1 -1
- package/dist/types/SelectMenu.js.map +1 -1
- package/dist/utils/customId.d.ts +1 -1
- package/dist/utils/customId.d.ts.map +1 -1
- package/dist/utils/customId.js +8 -4
- package/dist/utils/customId.js.map +1 -1
- package/dist/utils/recursiveImport.d.ts +5 -4
- package/dist/utils/recursiveImport.d.ts.map +1 -1
- package/dist/utils/recursiveImport.js +27 -26
- package/dist/utils/recursiveImport.js.map +1 -1
- package/generated/namespaceData.d.ts +2 -1
- package/package.json +2 -1
- package/src/DBI.ts +75 -23
- package/src/index.ts +18 -2
- package/src/methods/hookEventListeners.ts +21 -7
- package/src/methods/hookInteractionListeners.ts +6 -2
- package/src/methods/publishInteractions.ts +30 -25
- package/src/types/Button.ts +2 -2
- package/src/types/CustomEvent.ts +1 -1
- package/src/types/Event.ts +4 -2
- package/src/types/Interaction.ts +5 -2
- package/src/types/Modal.ts +2 -2
- package/src/types/SelectMenu.ts +2 -2
- package/src/utils/customId.ts +4 -2
- package/src/utils/recursiveImport.ts +4 -3
package/src/index.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { NamespaceEnums } from "../generated/namespaceData";
|
|
2
2
|
import { DBI, DBIConfigConstructor } from "./DBI";
|
|
3
|
-
|
|
3
|
+
import { recursiveImport as _recursiveImport } from "./utils/recursiveImport";
|
|
4
4
|
export { MemoryStore } from "./utils/MemoryStore";
|
|
5
5
|
|
|
6
6
|
import path from "path";
|
|
7
|
+
import { parseCustomId, buildCustomId } from "./utils/customId";
|
|
8
|
+
|
|
7
9
|
export const generatedPath = path.resolve(__dirname, "../generated");
|
|
8
10
|
|
|
9
11
|
export function createDBI<TNamespace extends NamespaceEnums, TOtherType = Record<string, any>>(namespace: TNamespace, cfg: DBIConfigConstructor): DBI<TNamespace, TOtherType> {
|
|
10
12
|
return new DBI<TNamespace, TOtherType>(namespace, cfg);
|
|
11
|
-
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Utils = {
|
|
16
|
+
parseCustomId,
|
|
17
|
+
buildCustomId,
|
|
18
|
+
recursiveImport: _recursiveImport
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
export async function recursiveImport(...args: any[]) {
|
|
25
|
+
console.log("[DEPRECTED] recursiveImport is a deprected api. Please use Utils.recursiveImport instead.", Error().stack);
|
|
26
|
+
return await _recursiveImport.call(this, ...args);
|
|
27
|
+
}
|
|
@@ -3,6 +3,17 @@ import { NamespaceEnums } from "../../generated/namespaceData";
|
|
|
3
3
|
import { DBI } from "../DBI";
|
|
4
4
|
|
|
5
5
|
export function hookEventListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
6
|
+
|
|
7
|
+
function getClientByEvent(value) {
|
|
8
|
+
return value.triggerType == "OneByOne"
|
|
9
|
+
? dbi.data.clients.next(`Event:${value.id}`)
|
|
10
|
+
: value.triggerType == "OneByOneGlobal"
|
|
11
|
+
? dbi.data.clients.next("Event")
|
|
12
|
+
: value.triggerType == "Random"
|
|
13
|
+
? dbi.data.clients.random()
|
|
14
|
+
: dbi.data.clients.first();
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
async function handle(eventName: string, ...args: any[]) {
|
|
7
18
|
if (!dbi.data.eventMap[eventName]) return;
|
|
8
19
|
|
|
@@ -47,11 +58,12 @@ export function hookEventListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
47
58
|
|
|
48
59
|
for (let i = 0; i < unOrdered.length; i++) {
|
|
49
60
|
const value = unOrdered[i];
|
|
61
|
+
|
|
50
62
|
if (dbi.config.strict) {
|
|
51
|
-
value.onExecute(arg);
|
|
63
|
+
value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
52
64
|
} else {
|
|
53
65
|
try {
|
|
54
|
-
value.onExecute(arg)?.catch(error => {
|
|
66
|
+
value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
55
67
|
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
56
68
|
});
|
|
57
69
|
} catch (error) {
|
|
@@ -62,11 +74,12 @@ export function hookEventListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
62
74
|
|
|
63
75
|
for (let i = 0; i < ordered.length; i++) {
|
|
64
76
|
const value = ordered[i];
|
|
77
|
+
|
|
65
78
|
if (dbi.config.strict) {
|
|
66
|
-
await value.onExecute(arg);
|
|
79
|
+
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
67
80
|
} else {
|
|
68
81
|
try {
|
|
69
|
-
await value.onExecute(arg)?.catch(error => {
|
|
82
|
+
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
70
83
|
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
71
84
|
});
|
|
72
85
|
} catch (error) {
|
|
@@ -78,14 +91,15 @@ export function hookEventListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
78
91
|
dbi.events.trigger("afterEvent", arg)
|
|
79
92
|
}
|
|
80
93
|
|
|
81
|
-
let
|
|
94
|
+
let firstClient = dbi.data.clients.first().client;
|
|
95
|
+
let originalEmit = firstClient.emit;
|
|
82
96
|
|
|
83
|
-
|
|
97
|
+
firstClient.emit = function(eventName, ...args) {
|
|
84
98
|
handle(eventName, ...args);
|
|
85
99
|
return originalEmit.call(this, eventName, ...args);
|
|
86
100
|
}
|
|
87
101
|
|
|
88
102
|
return () => {
|
|
89
|
-
|
|
103
|
+
firstClient.emit = originalEmit;
|
|
90
104
|
}
|
|
91
105
|
}
|
|
@@ -139,9 +139,13 @@ export function hookInteractionListeners(dbi: DBI<NamespaceEnums>): () => any {
|
|
|
139
139
|
dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
dbi.
|
|
142
|
+
dbi.data.clients.forEach(d=>{
|
|
143
|
+
d.client.on("interactionCreate", handle);
|
|
144
|
+
});
|
|
143
145
|
|
|
144
146
|
return () => {
|
|
145
|
-
dbi.
|
|
147
|
+
dbi.data.clients.forEach(d=>{
|
|
148
|
+
d.client.off("interactionCreate", handle);
|
|
149
|
+
});
|
|
146
150
|
};
|
|
147
151
|
}
|
|
@@ -4,7 +4,7 @@ import { REST } from "@discordjs/rest";
|
|
|
4
4
|
import { Routes, RESTGetAPIUserResult, RESTPutAPIApplicationCommandsJSONBody, ApplicationCommandType, ApplicationCommandOptionType } from "discord-api-types/v9";
|
|
5
5
|
import { reducePermissions } from "../utils/permissions";
|
|
6
6
|
import snakecaseKeys from "snakecase-keys";
|
|
7
|
-
import { DBI } from "../DBI";
|
|
7
|
+
import { DBI, DBIClientData } from "../DBI";
|
|
8
8
|
import { DBIInteractionLocale } from "../types/InteractionLocale";
|
|
9
9
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
10
10
|
|
|
@@ -12,29 +12,25 @@ const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"]
|
|
|
12
12
|
const ORIGINAL_LOCALES = ["da", "de", "en-GB", "en-US", "es-ES", "fr", "hr", "it", "lt", "hu", "nl", "no", "pl", "pt-BR", "ro", "fi", "sv-SE", "vi", "tr", "cs", "el", "bg", "ru", "uk", "hi", "th", "zh-CN", "ja", "zh-TW", "ko"];
|
|
13
13
|
|
|
14
14
|
export async function publishInteractions(
|
|
15
|
-
|
|
15
|
+
clients: DBIClientData<NamespaceEnums>[],
|
|
16
16
|
interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>,
|
|
17
17
|
interactionsLocales: Discord.Collection<string, DBIInteractionLocale>,
|
|
18
18
|
publishType: "Guild" | "Global",
|
|
19
19
|
guildId?: string
|
|
20
20
|
) {
|
|
21
21
|
interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));
|
|
22
|
-
|
|
23
|
-
const rest = new REST({ version: "10" });
|
|
24
|
-
rest.setToken(clientToken);
|
|
25
|
-
|
|
26
|
-
const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;
|
|
27
22
|
interactions = interactions.sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
|
|
28
23
|
|
|
29
|
-
let body: RESTPutAPIApplicationCommandsJSONBody =
|
|
24
|
+
let body: {[k: string]: RESTPutAPIApplicationCommandsJSONBody} =
|
|
30
25
|
interactions.reduce((all, current) => {
|
|
26
|
+
if (current.publish && !all[current.publish]) all[current.publish] = [];
|
|
31
27
|
switch (current.type) {
|
|
32
28
|
case "ChatInput": {
|
|
33
29
|
let nameSplitted = current.name.split(" ");
|
|
34
30
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
35
31
|
switch (nameSplitted.length) {
|
|
36
32
|
case 1: {
|
|
37
|
-
all.push({
|
|
33
|
+
all[current.publish].push({
|
|
38
34
|
type: ApplicationCommandType.ChatInput,
|
|
39
35
|
description: current.description,
|
|
40
36
|
name: nameSplitted[0],
|
|
@@ -47,7 +43,7 @@ export async function publishInteractions(
|
|
|
47
43
|
break;
|
|
48
44
|
}
|
|
49
45
|
case 2: {
|
|
50
|
-
let baseItem = all.find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
46
|
+
let baseItem = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
51
47
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
52
48
|
let option = {
|
|
53
49
|
type: ApplicationCommandOptionType.Subcommand,
|
|
@@ -59,7 +55,7 @@ export async function publishInteractions(
|
|
|
59
55
|
description_localizations: localeData.descriptionLocales,
|
|
60
56
|
};
|
|
61
57
|
if (!baseItem) {
|
|
62
|
-
all.push({
|
|
58
|
+
all[current.publish].push({
|
|
63
59
|
type: ApplicationCommandType.ChatInput,
|
|
64
60
|
name: nameSplitted[0],
|
|
65
61
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
@@ -75,10 +71,10 @@ export async function publishInteractions(
|
|
|
75
71
|
break;
|
|
76
72
|
}
|
|
77
73
|
case 3: {
|
|
78
|
-
let level1Item = all.find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
74
|
+
let level1Item = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
79
75
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
80
76
|
if (!level1Item) {
|
|
81
|
-
all.push({
|
|
77
|
+
all[current.publish].push({
|
|
82
78
|
type: ApplicationCommandType.ChatInput,
|
|
83
79
|
name: nameSplitted[0],
|
|
84
80
|
name_localizations: localeData.nameLocales(0),
|
|
@@ -143,7 +139,7 @@ export async function publishInteractions(
|
|
|
143
139
|
}
|
|
144
140
|
case "MessageContextMenu": {
|
|
145
141
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
146
|
-
all.push({
|
|
142
|
+
all[current.publish].push({
|
|
147
143
|
type: ApplicationCommandType.Message,
|
|
148
144
|
name: current.name,
|
|
149
145
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
@@ -155,29 +151,38 @@ export async function publishInteractions(
|
|
|
155
151
|
}
|
|
156
152
|
case "UserContextMenu": {
|
|
157
153
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
158
|
-
all.push({
|
|
154
|
+
all[current.publish].push({
|
|
159
155
|
type: ApplicationCommandType.User,
|
|
160
156
|
name: current.name,
|
|
161
157
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
162
158
|
dm_permission: current.directMessages,
|
|
163
159
|
name_localizations: localeData.allNameLocales,
|
|
164
|
-
description_localizations: localeData.descriptionLocales
|
|
160
|
+
description_localizations: localeData.descriptionLocales,
|
|
165
161
|
});
|
|
166
162
|
break;
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
165
|
|
|
170
166
|
return all;
|
|
171
|
-
}, []);
|
|
167
|
+
}, {} as {[k: string]: any});
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
for (let i = 0; i < clients.length; i++) {
|
|
171
|
+
const client = clients[i];
|
|
172
|
+
const rest = new REST({ version: "10" });
|
|
173
|
+
rest.setToken(client.token);
|
|
172
174
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;
|
|
176
|
+
|
|
177
|
+
switch (publishType) {
|
|
178
|
+
case "Guild": {
|
|
179
|
+
await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] });
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "Global": {
|
|
183
|
+
await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] });
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
181
186
|
}
|
|
182
187
|
}
|
|
183
188
|
|
package/src/types/Button.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Discord from "discord.js";
|
|
2
2
|
import { DBI } from "../DBI";
|
|
3
3
|
import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
|
|
4
|
-
import {
|
|
4
|
+
import { buildCustomId } from "../utils/customId";
|
|
5
5
|
import { IDBIToJSONArgs } from "../utils/UtilTypes";
|
|
6
6
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
7
7
|
import stuffs from "stuffs";
|
|
@@ -28,7 +28,7 @@ export class DBIButton<TNamespace extends NamespaceEnums> extends DBIBaseInterac
|
|
|
28
28
|
toJSON(arg: IDBIToJSONArgs<DBIButtonOverrides> = {}): Discord.ButtonComponentData {
|
|
29
29
|
return {
|
|
30
30
|
...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
|
|
31
|
-
customId:
|
|
31
|
+
customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
|
|
32
32
|
type: Discord.ComponentType.Button,
|
|
33
33
|
} as any;
|
|
34
34
|
};
|
package/src/types/CustomEvent.ts
CHANGED
|
@@ -8,7 +8,7 @@ export class DBICustomEvent<TNamespace extends NamespaceEnums, CEventName extend
|
|
|
8
8
|
map: {[key: string]: string};
|
|
9
9
|
type: string;
|
|
10
10
|
trigger(args: NamespaceData[TNamespace]["customEvents"][CEventName]) {
|
|
11
|
-
return this.dbi.client.emit(this.name as string, { ...args, _DIRECT_: true});
|
|
11
|
+
return this.dbi.data.clients.first().client.emit(this.name as string, { ...args, _DIRECT_: true});
|
|
12
12
|
}
|
|
13
13
|
constructor(dbi: DBI<TNamespace>, cfg: TDBICustomEventOmitted<TNamespace, CEventName>) {
|
|
14
14
|
this.dbi = dbi;
|
package/src/types/Event.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Discord from "discord.js";
|
|
2
2
|
import { NamespaceEnums, NamespaceData } from "../../generated/namespaceData";
|
|
3
|
-
import { DBI } from "../DBI";
|
|
3
|
+
import { DBI, DBIClientData } from "../DBI";
|
|
4
4
|
import { DBILocale } from "./Locale";
|
|
5
5
|
|
|
6
6
|
export interface ClientEvents {
|
|
@@ -93,7 +93,7 @@ export interface ClientEvents {
|
|
|
93
93
|
export type DBIEventCombinations<TNamespace extends NamespaceEnums> = {
|
|
94
94
|
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
|
|
95
95
|
name: K,
|
|
96
|
-
onExecute: (ctx: (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K] & { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: string }) => Promise<any> | any
|
|
96
|
+
onExecute: (ctx: (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K] & { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: string, nextClient: DBIClientData<TNamespace> }) => Promise<any> | any
|
|
97
97
|
}
|
|
98
98
|
}[keyof (ClientEvents) | keyof NamespaceData[TNamespace]["customEvents"]];
|
|
99
99
|
|
|
@@ -102,6 +102,7 @@ export type TDBIEventOmitted<TNamespace extends NamespaceEnums> = Omit<DBIEvent<
|
|
|
102
102
|
export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
103
103
|
readonly type: "Event";
|
|
104
104
|
other?: Record<string, any>;
|
|
105
|
+
triggerType?: "OneByOne" | "OneByOneGlobal" | "Random" | "First";
|
|
105
106
|
id?: string;
|
|
106
107
|
name: string;
|
|
107
108
|
onExecute: (...args: any[]) => any;
|
|
@@ -115,5 +116,6 @@ export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
|
115
116
|
this.name = cfg.name as any;
|
|
116
117
|
this.onExecute = cfg.onExecute;
|
|
117
118
|
this.ordered = cfg.ordered ?? false;
|
|
119
|
+
this.triggerType = cfg.triggerType ?? "OneByOneGlobal";
|
|
118
120
|
}
|
|
119
121
|
}
|
package/src/types/Interaction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Discord from "discord.js";
|
|
2
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
2
|
+
import { NamespaceEnums, NamespaceData } from "../../generated/namespaceData";
|
|
3
3
|
import { DBI } from "../DBI";
|
|
4
4
|
import { DBIButton } from "./Button";
|
|
5
5
|
import { DBIChatInput } from "./ChatInput/ChatInput";
|
|
@@ -28,6 +28,7 @@ export interface IDBIBaseExecuteCtx<TNamespace extends NamespaceEnums> {
|
|
|
28
28
|
dbiInteraction: TDBIInteractions<TNamespace>;
|
|
29
29
|
setRateLimit(type: TDBIRateLimitTypes, duration: number): Promise<any>;
|
|
30
30
|
other: Record<string, any>;
|
|
31
|
+
clientNamespace: NamespaceData[TNamespace]["clientNamespaces"];
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export type TDBIReferencedData = ({ [key: string]: any, $ref: string, $unRef(): boolean } | string | number);
|
|
@@ -66,8 +67,10 @@ export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
|
66
67
|
this.type = cfg.type;
|
|
67
68
|
this.options = cfg.options;
|
|
68
69
|
this.other = cfg.other;
|
|
70
|
+
this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
|
|
73
|
+
publish?: NamespaceData[TNamespace]["clientNamespaces"];
|
|
71
74
|
dbi: DBI<TNamespace>;
|
|
72
75
|
name: string;
|
|
73
76
|
description: string;
|
package/src/types/Modal.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DBI } from "../DBI";
|
|
2
2
|
import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
|
|
3
3
|
import Discord from "discord.js";
|
|
4
|
-
import {
|
|
4
|
+
import { buildCustomId } from "../utils/customId";
|
|
5
5
|
import { IDBIToJSONArgs } from "../utils/UtilTypes";
|
|
6
6
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
7
7
|
import stuffs from "stuffs";
|
|
@@ -36,7 +36,7 @@ export class DBIModal<TNamespace extends NamespaceEnums> extends DBIBaseInteract
|
|
|
36
36
|
toJSON(arg: IDBIToJSONArgs<DBIModalOverrides> = {}): Discord.ModalComponentData {
|
|
37
37
|
return {
|
|
38
38
|
...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
|
|
39
|
-
customId:
|
|
39
|
+
customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl)
|
|
40
40
|
} as any;
|
|
41
41
|
};
|
|
42
42
|
|
package/src/types/SelectMenu.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Discord from "discord.js";
|
|
2
2
|
import { DBI } from "../DBI";
|
|
3
3
|
import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
|
|
4
|
-
import {
|
|
4
|
+
import { buildCustomId } from "../utils/customId";
|
|
5
5
|
import { IDBIToJSONArgs } from "../utils/UtilTypes";
|
|
6
6
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
7
7
|
import stuffs from "stuffs";
|
|
@@ -30,7 +30,7 @@ export class DBISelectMenu<TNamespace extends NamespaceEnums> extends DBIBaseInt
|
|
|
30
30
|
toJSON(arg: IDBIToJSONArgs<DBISelectMenuOverrides> = {}): Discord.BaseSelectMenuComponentData {
|
|
31
31
|
return {
|
|
32
32
|
...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
|
|
33
|
-
customId:
|
|
33
|
+
customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
|
|
34
34
|
type: Discord.ComponentType.SelectMenu,
|
|
35
35
|
} as any;
|
|
36
36
|
};
|
package/src/utils/customId.ts
CHANGED
|
@@ -2,12 +2,13 @@ import { DBI } from "../DBI";
|
|
|
2
2
|
import * as stuffs from "stuffs";
|
|
3
3
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
4
4
|
|
|
5
|
-
export function
|
|
5
|
+
export function buildCustomId(dbi: DBI<NamespaceEnums>, name: string, data: any[], ttl?:number): string {
|
|
6
6
|
let customId = [
|
|
7
7
|
name,
|
|
8
|
-
...
|
|
8
|
+
...data.map(value => {
|
|
9
9
|
if (typeof value == "string") return value;
|
|
10
10
|
if (typeof value == "number") return `ฯ${value}`;
|
|
11
|
+
if (typeof value == "boolean") return `๐ซ${value ? 1 : 0}`;
|
|
11
12
|
let id = stuffs.randomString(8);
|
|
12
13
|
Object.assign(value, {
|
|
13
14
|
$ref: id,
|
|
@@ -27,6 +28,7 @@ export function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): {name
|
|
|
27
28
|
let name = splitted.shift();
|
|
28
29
|
let data = splitted.map(value => {
|
|
29
30
|
if (value.startsWith("ฯ")) return Number(value.slice(1));
|
|
31
|
+
if (value.startsWith("๐ซ")) return !!Number(value.slice(1));
|
|
30
32
|
if (value.startsWith("ยค")) return dbi.data.refs.get(value.slice(1))?.value;
|
|
31
33
|
return value;
|
|
32
34
|
});
|
|
@@ -2,9 +2,10 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* @example
|
|
6
|
+
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
6
7
|
*/
|
|
7
|
-
export async function recursiveImport(folderPath: string, exts: string[] = [".js", ".ts"]): Promise<any> {
|
|
8
|
+
export async function recursiveImport(folderPath: string, exts: string[] = [".js"], ignore: string[] = [".d.ts",".js.map",".d.ts.map"]): Promise<any> {
|
|
8
9
|
let files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
|
9
10
|
let dirName = __dirname;
|
|
10
11
|
|
|
@@ -14,7 +15,7 @@ export async function recursiveImport(folderPath: string, exts: string[] = [".js
|
|
|
14
15
|
if (!relative.includes(`${path.sep}-`)) {
|
|
15
16
|
if (file.isDirectory()) {
|
|
16
17
|
await recursiveImport(filePath, exts)
|
|
17
|
-
} else if (exts.some(i => file.name.endsWith(i))) {
|
|
18
|
+
} else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
18
19
|
await import(filePath)
|
|
19
20
|
}
|
|
20
21
|
}
|