@mostfeatured/dbi 0.2.16 → 0.2.18
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/src/types/Components/HTMLComponentsV2/index.d.ts +4 -0
- package/dist/src/types/Components/HTMLComponentsV2/index.d.ts.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/index.js +40 -5
- package/dist/src/types/Components/HTMLComponentsV2/index.js.map +1 -1
- package/dist/src/types/Event.d.ts +21 -13
- package/dist/src/types/Event.d.ts.map +1 -1
- package/dist/src/types/Event.js.map +1 -1
- package/dist/test/index.js +1 -1
- package/dist/test/index.js.map +1 -1
- package/generated/namespaceData.d.ts +3 -1
- package/package.json +6 -2
- package/.gitattributes +0 -2
- package/.hintrc +0 -8
- package/.vscode/settings.json +0 -3
- package/docs/ADVANCED_FEATURES.md +0 -840
- package/docs/API_REFERENCE.md +0 -929
- package/docs/CHAT_INPUT.md +0 -811
- package/docs/COMPONENTS.md +0 -1039
- package/docs/EVENTS.md +0 -568
- package/docs/GETTING_STARTED.md +0 -398
- package/docs/LOCALIZATION.md +0 -777
- package/docs/README.md +0 -345
- package/docs/SVELTE_COMPONENTS.md +0 -1111
- package/docs/llm/ADVANCED_FEATURES.txt +0 -521
- package/docs/llm/API_REFERENCE.txt +0 -659
- package/docs/llm/CHAT_INPUT.txt +0 -514
- package/docs/llm/COMPONENTS.txt +0 -595
- package/docs/llm/EVENTS.txt +0 -449
- package/docs/llm/GETTING_STARTED.txt +0 -296
- package/docs/llm/LOCALIZATION.txt +0 -501
- package/docs/llm/README.txt +0 -193
- package/docs/llm/SVELTE_COMPONENTS.txt +0 -566
- package/src/DBI.ts +0 -1007
- package/src/Events.ts +0 -189
- package/src/data/eventMap.json +0 -248
- package/src/index.ts +0 -23
- package/src/methods/handleMessageCommands.ts +0 -482
- package/src/methods/hookEventListeners.ts +0 -119
- package/src/methods/hookInteractionListeners.ts +0 -314
- package/src/methods/publishInteractions.ts +0 -256
- package/src/types/ApplicationRoleConnectionMetadata.ts +0 -19
- package/src/types/Builders/ButtonBuilder.ts +0 -53
- package/src/types/Builders/ChannelSelectMenuBuilder.ts +0 -53
- package/src/types/Builders/MentionableSelectMenuBuilder.ts +0 -53
- package/src/types/Builders/ModalBuilder.ts +0 -53
- package/src/types/Builders/RoleSelectMenuBuilder.ts +0 -53
- package/src/types/Builders/StringSelectMenuBuilder.ts +0 -53
- package/src/types/Builders/UserSelectMenuBuilder.ts +0 -53
- package/src/types/ChatInput/ChatInput.ts +0 -28
- package/src/types/ChatInput/ChatInputOptions.ts +0 -388
- package/src/types/Components/Button.ts +0 -39
- package/src/types/Components/ChannelSelectMenu.ts +0 -43
- package/src/types/Components/HTMLComponentsV2/HTMLComponentsV2Handlers.ts +0 -78
- package/src/types/Components/HTMLComponentsV2/index.ts +0 -761
- package/src/types/Components/HTMLComponentsV2/parser.ts +0 -649
- package/src/types/Components/HTMLComponentsV2/svelteParser.ts +0 -1503
- package/src/types/Components/HTMLComponentsV2/svelteRenderer.ts +0 -416
- package/src/types/Components/MentionableSelectMenu.ts +0 -43
- package/src/types/Components/Modal.ts +0 -46
- package/src/types/Components/RoleSelectMenu.ts +0 -43
- package/src/types/Components/StringSelectMenu.ts +0 -43
- package/src/types/Components/UserSelectMenu.ts +0 -43
- package/src/types/Event.ts +0 -145
- package/src/types/Interaction.ts +0 -100
- package/src/types/other/CustomEvent.ts +0 -19
- package/src/types/other/FakeMessageInteraction.ts +0 -408
- package/src/types/other/InteractionLocale.ts +0 -34
- package/src/types/other/Locale.ts +0 -70
- package/src/types/other/MessageContextMenu.ts +0 -27
- package/src/types/other/UserContextMenu.ts +0 -25
- package/src/utils/MemoryStore.ts +0 -28
- package/src/utils/UtilTypes.ts +0 -11
- package/src/utils/customId.ts +0 -49
- package/src/utils/permissions.ts +0 -5
- package/src/utils/recursiveImport.ts +0 -35
- package/src/utils/recursiveUnload.ts +0 -25
- package/src/utils/unloadModule.ts +0 -7
- package/test/index.ts +0 -176
- package/test/product-showcase.svelte +0 -558
- package/test/test.ts +0 -3
- package/tsconfig.json +0 -51
|
@@ -1,314 +0,0 @@
|
|
|
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((dbiInter) => {
|
|
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
|
-
(dbiInter.type == "ChatInput" &&
|
|
28
|
-
(inter.isChatInputCommand() || inter.isAutocomplete()) &&
|
|
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") &&
|
|
39
|
-
(inter.isMessageContextMenuCommand() ||
|
|
40
|
-
inter.isUserContextMenuCommand()) &&
|
|
41
|
-
inter.commandName == dbiInter.name)
|
|
42
|
-
||
|
|
43
|
-
(componentTypes.includes(dbiInter.type) &&
|
|
44
|
-
isUsesCustomId &&
|
|
45
|
-
parsedId?.name == dbiInter.name)
|
|
46
|
-
||
|
|
47
|
-
(parsedId?.v2 && dbiInter.type == "HTMLComponentsV2" && parsedId?.name == dbiInter.name)
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!dbiInter) return;
|
|
52
|
-
|
|
53
|
-
let userLocaleName = inter.locale.split("-")[0];
|
|
54
|
-
let userLocale = dbi.data.locales.has(userLocaleName)
|
|
55
|
-
? dbi.data.locales.get(userLocaleName)
|
|
56
|
-
: dbi.data.locales.get(dbi.config.defaults.locale.name);
|
|
57
|
-
|
|
58
|
-
let guildLocaleName = inter.guild
|
|
59
|
-
? inter.guild.preferredLocale.split("-")[0]
|
|
60
|
-
: null;
|
|
61
|
-
let guildLocale = guildLocaleName
|
|
62
|
-
? dbi.data.locales.has(guildLocaleName)
|
|
63
|
-
? dbi.data.locales.get(guildLocaleName)
|
|
64
|
-
: dbi.data.locales.get(dbi.config.defaults.locale.name)
|
|
65
|
-
: null;
|
|
66
|
-
|
|
67
|
-
let locale = {
|
|
68
|
-
user: userLocale,
|
|
69
|
-
guild: guildLocale,
|
|
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;
|
|
78
|
-
|
|
79
|
-
let other = {};
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
!(await dbi.events.trigger("beforeInteraction", {
|
|
83
|
-
dbi,
|
|
84
|
-
interaction: inter,
|
|
85
|
-
locale,
|
|
86
|
-
setRateLimit,
|
|
87
|
-
data,
|
|
88
|
-
other,
|
|
89
|
-
dbiInteraction: dbiInter,
|
|
90
|
-
v2
|
|
91
|
-
}))
|
|
92
|
-
)
|
|
93
|
-
return;
|
|
94
|
-
|
|
95
|
-
if (inter.isAutocomplete()) {
|
|
96
|
-
let focussed = inter.options.getFocused(true);
|
|
97
|
-
let option = (dbiInter.options as any[]).find(
|
|
98
|
-
(i) => i.name == focussed.name
|
|
99
|
-
);
|
|
100
|
-
if (option?.validate) {
|
|
101
|
-
const res = await option.validate({
|
|
102
|
-
value: focussed.value,
|
|
103
|
-
interaction: inter,
|
|
104
|
-
dbiInteraction: dbiInter,
|
|
105
|
-
dbi,
|
|
106
|
-
data,
|
|
107
|
-
other,
|
|
108
|
-
locale,
|
|
109
|
-
step: "Autocomplete",
|
|
110
|
-
v2,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (Array.isArray(res) && res.length > 0) {
|
|
114
|
-
await inter.respond(res);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (res !== true) return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (option?.onComplete) {
|
|
122
|
-
let response = await option.onComplete({
|
|
123
|
-
value: focussed.value,
|
|
124
|
-
interaction: inter,
|
|
125
|
-
dbiInteraction: dbiInter,
|
|
126
|
-
dbi,
|
|
127
|
-
data,
|
|
128
|
-
other,
|
|
129
|
-
locale,
|
|
130
|
-
v2
|
|
131
|
-
});
|
|
132
|
-
await inter.respond(response);
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let rateLimitKeyMap = {
|
|
138
|
-
User: `${dbiInter.name}_${inter.user.id}`,
|
|
139
|
-
Channel: `${dbiInter.name}_${inter.channelId || "Channel"}`,
|
|
140
|
-
Guild: `${dbiInter.name}_${inter.guildId || "Guild"}`,
|
|
141
|
-
Member: `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
|
|
142
|
-
Message: `${dbiInter.name}_${(inter as any)?.message?.id}`,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
for (const type in rateLimitKeyMap) {
|
|
146
|
-
// @ts-ignore
|
|
147
|
-
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
148
|
-
let val = await dbi.config.store.get(key);
|
|
149
|
-
if (val && Date.now() > val.at + val.duration) {
|
|
150
|
-
await dbi.config.store.delete(key);
|
|
151
|
-
val = null;
|
|
152
|
-
}
|
|
153
|
-
if (val) {
|
|
154
|
-
if (
|
|
155
|
-
(await dbi.events.trigger("interactionRateLimit", {
|
|
156
|
-
dbi,
|
|
157
|
-
interaction: inter,
|
|
158
|
-
dbiInteraction: dbiInter,
|
|
159
|
-
locale,
|
|
160
|
-
data,
|
|
161
|
-
rateLimit: {
|
|
162
|
-
type: key,
|
|
163
|
-
...val,
|
|
164
|
-
},
|
|
165
|
-
v2
|
|
166
|
-
})) === true
|
|
167
|
-
)
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async function setRateLimit(type: string, duration: number) {
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, {
|
|
175
|
-
at: Date.now(),
|
|
176
|
-
duration,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
for (const rateLimit of dbiInter.rateLimits) {
|
|
181
|
-
await setRateLimit(rateLimit.type, rateLimit.duration);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (inter.isChatInputCommand()) {
|
|
185
|
-
let dcOptions = (inter.options as any)
|
|
186
|
-
._hoistedOptions as CommandInteractionOption[];
|
|
187
|
-
let dbiOptions = dbiInter.options as any[];
|
|
188
|
-
for (const dcOption of dcOptions) {
|
|
189
|
-
const dbiOption = dbiOptions.find((i) => i.name == dcOption.name);
|
|
190
|
-
if (dbiOption?.validate) {
|
|
191
|
-
const res = await dbiOption.validate({
|
|
192
|
-
value:
|
|
193
|
-
dbiOption.type === Discord.ApplicationCommandOptionType.Attachment
|
|
194
|
-
? dcOption.attachment
|
|
195
|
-
: dbiOption.type ===
|
|
196
|
-
Discord.ApplicationCommandOptionType.Channel
|
|
197
|
-
? dcOption.channel
|
|
198
|
-
: dbiOption.type === Discord.ApplicationCommandOptionType.Role
|
|
199
|
-
? dcOption.role
|
|
200
|
-
: dbiOption.type === Discord.ApplicationCommandOptionType.User
|
|
201
|
-
? dcOption.user
|
|
202
|
-
: dcOption.value,
|
|
203
|
-
interaction: inter,
|
|
204
|
-
dbiInteraction: dbiInter,
|
|
205
|
-
dbi,
|
|
206
|
-
data,
|
|
207
|
-
other,
|
|
208
|
-
locale,
|
|
209
|
-
step: "Result",
|
|
210
|
-
});
|
|
211
|
-
if (res !== true) return;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
let arg = {
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
dbi,
|
|
219
|
-
// @ts-ignore
|
|
220
|
-
interaction: inter as any,
|
|
221
|
-
// @ts-ignore
|
|
222
|
-
dbiInteraction: dbiInter,
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
locale,
|
|
225
|
-
// @ts-ignore
|
|
226
|
-
setRateLimit,
|
|
227
|
-
// @ts-ignore
|
|
228
|
-
data,
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
other,
|
|
231
|
-
v2
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (dbiInter.type === "HTMLComponentsV2") {
|
|
236
|
-
// For HTMLComponentsV2, first element of data is the element name (button name, etc.)
|
|
237
|
-
const elementName = data?.[0];
|
|
238
|
-
|
|
239
|
-
if (dbi.config.strict) {
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
await dbiInter.onExecute?.(arg);
|
|
242
|
-
|
|
243
|
-
// For traditional handlers (non-Svelte mode)
|
|
244
|
-
if (dbiInter.handlers?.length > 0) {
|
|
245
|
-
data.shift(); // Remove element name from data
|
|
246
|
-
dbiInter.handlers.forEach((handler) => {
|
|
247
|
-
if (handler.name === elementName) {
|
|
248
|
-
handler.onExecute(arg);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
try {
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
await dbiInter.onExecute?.(arg);
|
|
256
|
-
|
|
257
|
-
// For traditional handlers (non-Svelte mode)
|
|
258
|
-
if (dbiInter.handlers?.length > 0) {
|
|
259
|
-
data.shift(); // Remove element name from data
|
|
260
|
-
dbiInter.handlers.forEach((handler) => {
|
|
261
|
-
if (handler.name === elementName) {
|
|
262
|
-
handler.onExecute(arg);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
} catch (error) {
|
|
267
|
-
// @ts-ignore
|
|
268
|
-
await dbi.events.trigger(
|
|
269
|
-
"interactionError",
|
|
270
|
-
Object.assign(arg, { error })
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
} else {
|
|
275
|
-
if (dbi.config.strict) {
|
|
276
|
-
// @ts-ignore
|
|
277
|
-
await dbiInter.onExecute(arg);
|
|
278
|
-
} else {
|
|
279
|
-
try {
|
|
280
|
-
// @ts-ignore
|
|
281
|
-
await dbiInter.onExecute(arg);
|
|
282
|
-
} catch (error) {
|
|
283
|
-
// @ts-ignore
|
|
284
|
-
await dbi.events.trigger(
|
|
285
|
-
"interactionError",
|
|
286
|
-
Object.assign(arg, { error })
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// @ts-ignore
|
|
293
|
-
dbi.events.trigger("afterInteraction", {
|
|
294
|
-
dbi,
|
|
295
|
-
interaction: inter,
|
|
296
|
-
dbiInteraction: dbiInter,
|
|
297
|
-
locale,
|
|
298
|
-
setRateLimit,
|
|
299
|
-
data,
|
|
300
|
-
other,
|
|
301
|
-
v2
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
dbi.data.clients.forEach((d) => {
|
|
306
|
-
d.client.on("interactionCreate", handle);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
return () => {
|
|
310
|
-
dbi.data.clients.forEach((d) => {
|
|
311
|
-
d.client.off("interactionCreate", handle);
|
|
312
|
-
});
|
|
313
|
-
};
|
|
314
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import Discord from "discord.js";
|
|
2
|
-
import { DBIChatInput } from "../types/ChatInput/ChatInput";
|
|
3
|
-
import { REST } from "@discordjs/rest";
|
|
4
|
-
import { Routes, RESTGetAPIUserResult, RESTPutAPIApplicationCommandsJSONBody, ApplicationCommandType, ApplicationCommandOptionType } from "discord-api-types/v9";
|
|
5
|
-
import { reducePermissions } from "../utils/permissions";
|
|
6
|
-
import snakecaseKeys from "snakecase-keys";
|
|
7
|
-
import { DBI, TDBIClientData } from "../DBI";
|
|
8
|
-
import { DBIInteractionLocale } from "../types/other/InteractionLocale";
|
|
9
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
10
|
-
import { ApplicationRoleConnectionMetadataType, ApplicationRoleConnectionMetadata } from "../types/ApplicationRoleConnectionMetadata";
|
|
11
|
-
|
|
12
|
-
const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"];
|
|
13
|
-
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"];
|
|
14
|
-
|
|
15
|
-
export async function publishInteractions(
|
|
16
|
-
clients: TDBIClientData<NamespaceEnums>[],
|
|
17
|
-
interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>,
|
|
18
|
-
interactionsLocales: Discord.Collection<string, DBIInteractionLocale>,
|
|
19
|
-
publishType: "Guild" | "Global",
|
|
20
|
-
guildId?: string
|
|
21
|
-
) {
|
|
22
|
-
interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));
|
|
23
|
-
interactions = interactions.sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
|
|
24
|
-
|
|
25
|
-
let body: { [k: string]: RESTPutAPIApplicationCommandsJSONBody } =
|
|
26
|
-
interactions.reduce((all, current) => {
|
|
27
|
-
if (current.publish && !all[current.publish]) all[current.publish] = [];
|
|
28
|
-
switch (current.type) {
|
|
29
|
-
case "ChatInput": {
|
|
30
|
-
let nameSplitted = current.name.split(" ");
|
|
31
|
-
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
32
|
-
switch (nameSplitted.length) {
|
|
33
|
-
case 1: {
|
|
34
|
-
all[current.publish].push({
|
|
35
|
-
type: ApplicationCommandType.ChatInput,
|
|
36
|
-
description: current.description,
|
|
37
|
-
name: nameSplitted[0],
|
|
38
|
-
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
39
|
-
dm_permission: current.directMessages,
|
|
40
|
-
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
41
|
-
name_localizations: localeData.nameLocales(0),
|
|
42
|
-
description_localizations: localeData.descriptionLocales,
|
|
43
|
-
});
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
case 2: {
|
|
47
|
-
let baseItem = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
48
|
-
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
49
|
-
let option = {
|
|
50
|
-
type: ApplicationCommandOptionType.Subcommand,
|
|
51
|
-
name: nameSplitted[1],
|
|
52
|
-
description: current.description,
|
|
53
|
-
dm_permission: current.directMessages,
|
|
54
|
-
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
55
|
-
name_localizations: localeData.nameLocales(1),
|
|
56
|
-
description_localizations: localeData.descriptionLocales,
|
|
57
|
-
};
|
|
58
|
-
if (!baseItem) {
|
|
59
|
-
all[current.publish].push({
|
|
60
|
-
type: ApplicationCommandType.ChatInput,
|
|
61
|
-
name: nameSplitted[0],
|
|
62
|
-
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
63
|
-
name_localizations: localeData.nameLocales(0),
|
|
64
|
-
description: "...",
|
|
65
|
-
options: [
|
|
66
|
-
option
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
baseItem.options.push(option);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case 3: {
|
|
75
|
-
let level1Item = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
76
|
-
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
77
|
-
if (!level1Item) {
|
|
78
|
-
all[current.publish].push({
|
|
79
|
-
type: ApplicationCommandType.ChatInput,
|
|
80
|
-
name: nameSplitted[0],
|
|
81
|
-
name_localizations: localeData.nameLocales(0),
|
|
82
|
-
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
83
|
-
description: "...",
|
|
84
|
-
options: [
|
|
85
|
-
{
|
|
86
|
-
type: ApplicationCommandOptionType.SubcommandGroup,
|
|
87
|
-
name: nameSplitted[1],
|
|
88
|
-
name_localizations: localeData.nameLocales(1),
|
|
89
|
-
description: "...",
|
|
90
|
-
options: [
|
|
91
|
-
{
|
|
92
|
-
type: ApplicationCommandOptionType.Subcommand,
|
|
93
|
-
name: nameSplitted[2],
|
|
94
|
-
description: current.description,
|
|
95
|
-
dm_permission: current.directMessages,
|
|
96
|
-
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
97
|
-
name_localizations: localeData.nameLocales(2),
|
|
98
|
-
description_localizations: localeData.descriptionLocales,
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
let level2Item = level1Item.options.find(i => i.name == current.name.split(" ")[1]);
|
|
106
|
-
if (!level2Item) {
|
|
107
|
-
level1Item.options.push({
|
|
108
|
-
type: ApplicationCommandOptionType.SubcommandGroup,
|
|
109
|
-
name: nameSplitted[1],
|
|
110
|
-
name_localizations: localeData.nameLocales(1),
|
|
111
|
-
description: "...",
|
|
112
|
-
options: [
|
|
113
|
-
{
|
|
114
|
-
type: ApplicationCommandOptionType.Subcommand,
|
|
115
|
-
name: nameSplitted[2],
|
|
116
|
-
description: current.description,
|
|
117
|
-
dm_permission: current.directMessages,
|
|
118
|
-
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
119
|
-
name_localizations: localeData.nameLocales(2),
|
|
120
|
-
description_localizations: localeData.descriptionLocales
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
})
|
|
124
|
-
} else {
|
|
125
|
-
level2Item.options.push({
|
|
126
|
-
type: ApplicationCommandOptionType.Subcommand,
|
|
127
|
-
name: nameSplitted[2],
|
|
128
|
-
description: current.description,
|
|
129
|
-
dm_permission: current.directMessages,
|
|
130
|
-
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
131
|
-
name_localizations: localeData.nameLocales(2),
|
|
132
|
-
description_localizations: localeData.descriptionLocales,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case "MessageContextMenu": {
|
|
142
|
-
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
143
|
-
all[current.publish].push({
|
|
144
|
-
type: ApplicationCommandType.Message,
|
|
145
|
-
name: current.name,
|
|
146
|
-
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
147
|
-
dm_permission: current.directMessages,
|
|
148
|
-
name_localizations: localeData.allNameLocales,
|
|
149
|
-
description_localizations: localeData.descriptionLocales,
|
|
150
|
-
});
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
case "UserContextMenu": {
|
|
154
|
-
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
155
|
-
all[current.publish].push({
|
|
156
|
-
type: ApplicationCommandType.User,
|
|
157
|
-
name: current.name,
|
|
158
|
-
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
159
|
-
dm_permission: current.directMessages,
|
|
160
|
-
name_localizations: localeData.allNameLocales,
|
|
161
|
-
description_localizations: localeData.descriptionLocales,
|
|
162
|
-
});
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return all;
|
|
168
|
-
}, {} as { [k: string]: any });
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
for (let i = 0; i < clients.length; i++) {
|
|
172
|
-
const client = clients[i];
|
|
173
|
-
const rest = new REST({ version: "10" });
|
|
174
|
-
rest.setToken(client.token);
|
|
175
|
-
|
|
176
|
-
const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;
|
|
177
|
-
|
|
178
|
-
switch (publishType) {
|
|
179
|
-
case "Guild": {
|
|
180
|
-
await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] || [] });
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case "Global": {
|
|
184
|
-
await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] || [] });
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function localeifyOptions(options: any[], localeData: any): any[] {
|
|
193
|
-
return options.map(i => {
|
|
194
|
-
let optionData = localeData[i.name];
|
|
195
|
-
return optionData ? Object.assign(i, {
|
|
196
|
-
name_localizations: optionData.nameLocales,
|
|
197
|
-
description_localizations: optionData.descriptionLocales,
|
|
198
|
-
choices: i.choices ? i.choices.map((j) => {
|
|
199
|
-
let choiceLocale = optionData.choiceLocales[j.value ?? j.name];
|
|
200
|
-
return choiceLocale ? Object.assign(j, {
|
|
201
|
-
name_localizations: choiceLocale
|
|
202
|
-
}) : j;
|
|
203
|
-
}) : undefined
|
|
204
|
-
}) : i;
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export function formatLocale(locale: DBIInteractionLocale): any {
|
|
209
|
-
let allNameLocales = {};
|
|
210
|
-
let descriptionLocales = {};
|
|
211
|
-
let optionsLocales = {};
|
|
212
|
-
|
|
213
|
-
function nameLocales(index) {
|
|
214
|
-
return Object.fromEntries(Object.entries(allNameLocales).map(i => [i[0], (i[1] as string).split(" ").at(index)]));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (!locale?.data) return {
|
|
218
|
-
nameLocales,
|
|
219
|
-
allNameLocales,
|
|
220
|
-
descriptionLocales,
|
|
221
|
-
optionsLocales
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
Object.entries(locale.data).forEach(([shortLocale, localeData]) => {
|
|
225
|
-
let longAliases = ORIGINAL_LOCALES.filter(i => i.split("-").at(0) == shortLocale);
|
|
226
|
-
longAliases.forEach((longLocale) => {
|
|
227
|
-
allNameLocales[longLocale] = localeData.name;
|
|
228
|
-
descriptionLocales[longLocale] = localeData.description;
|
|
229
|
-
Object.entries(localeData?.options || {}).forEach(([optionName, optionData]) => {
|
|
230
|
-
if (!optionsLocales[optionName]) optionsLocales[optionName] = {};
|
|
231
|
-
let optionLocale = optionsLocales[optionName];
|
|
232
|
-
if (!optionLocale.nameLocales) optionLocale.nameLocales = {};
|
|
233
|
-
if (!optionLocale.descriptionLocales) optionLocale.descriptionLocales = {};
|
|
234
|
-
if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};
|
|
235
|
-
|
|
236
|
-
Object.entries(optionData?.choices || {}).forEach(([choiceOriginalName, choiceName]) => {
|
|
237
|
-
if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};
|
|
238
|
-
if (!optionLocale.choiceLocales[choiceOriginalName]) optionLocale.choiceLocales[choiceOriginalName] = {};
|
|
239
|
-
let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];
|
|
240
|
-
|
|
241
|
-
choiceLocale[longLocale] = choiceName;
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
optionLocale.nameLocales[longLocale] = optionData.name;
|
|
245
|
-
optionLocale.descriptionLocales[longLocale] = optionData.description;
|
|
246
|
-
})
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
nameLocales,
|
|
252
|
-
allNameLocales,
|
|
253
|
-
descriptionLocales,
|
|
254
|
-
optionsLocales
|
|
255
|
-
}
|
|
256
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export enum ApplicationRoleConnectionMetadataType {
|
|
2
|
-
INTEGER_LESS_THAN_OR_EQUAL = 1,
|
|
3
|
-
INTEGER_GREATER_THAN_OR_EQUAL = 2,
|
|
4
|
-
INTEGER_EQUAL = 3,
|
|
5
|
-
INTEGER_NOT_EQUAL = 4,
|
|
6
|
-
DATETIME_LESS_THAN_OR_EQUAL = 5,
|
|
7
|
-
DATETIME_GREATER_THAN_OR_EQUAL = 6,
|
|
8
|
-
BOOLEAN_EQUAL = 7,
|
|
9
|
-
BOOLEAN_NOT_EQUAL = 8,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ApplicationRoleConnectionMetadata {
|
|
13
|
-
type: ApplicationRoleConnectionMetadataType;
|
|
14
|
-
key: string;
|
|
15
|
-
name: string;
|
|
16
|
-
name_localizations?: { [key: string]: string };
|
|
17
|
-
description: string;
|
|
18
|
-
description_localizations?: { [key: string]: string };
|
|
19
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ButtonComponentData, ButtonStyle } from "discord.js";
|
|
2
|
-
import { defaultify } from "stuffs";
|
|
3
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
4
|
-
import { DBIButton } from "../Components/Button";
|
|
5
|
-
import { RecursivePartial } from "../../utils/UtilTypes";
|
|
6
|
-
|
|
7
|
-
export type DBIButtonOverrides = RecursivePartial<{ style?: ButtonStyle } & Omit<ButtonComponentData, "customId" | "type" | "style">>
|
|
8
|
-
|
|
9
|
-
export class DBIButtonBuilder<TNamespace extends NamespaceEnums> {
|
|
10
|
-
component: DBIButton<TNamespace>
|
|
11
|
-
overrides: DBIButtonOverrides;
|
|
12
|
-
reference: { data: (string | number | object | boolean | null | undefined)[], ttl?: number };
|
|
13
|
-
constructor(arg: { component: DBIButton<TNamespace>, overrides?: DBIButtonOverrides, reference?: { data: (string | number | object | boolean | null | undefined)[], ttl?: number } }) {
|
|
14
|
-
this.component = arg.component;
|
|
15
|
-
this.overrides = arg.overrides ?? {};
|
|
16
|
-
this.reference = arg.reference ?? { data: [] };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setTTL(ttl: number): DBIButtonBuilder<TNamespace> {
|
|
20
|
-
this.reference.ttl = ttl;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
addTTL(ttl: number): DBIButtonBuilder<TNamespace> {
|
|
25
|
-
this.reference.ttl = (this.reference.ttl ?? 0) + ttl;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setData(...data: (string | number | object | boolean | null | undefined)[]): DBIButtonBuilder<TNamespace> {
|
|
30
|
-
this.reference.data = data;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
addData(...data: (string | number | object | boolean | null | undefined)[]): DBIButtonBuilder<TNamespace> {
|
|
35
|
-
this.reference.data = [...this.reference.data, ...data];
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setOverrides(overrides: DBIButtonOverrides): DBIButtonBuilder<TNamespace> {
|
|
40
|
-
this.overrides = overrides;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addOverrides(overrides: DBIButtonOverrides): DBIButtonBuilder<TNamespace> {
|
|
45
|
-
this.overrides = defaultify(overrides, this.overrides, true);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
toJSON(): ButtonComponentData {
|
|
50
|
-
return this.component.toJSON({ overrides: this.overrides, reference: this.reference });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { BaseSelectMenuComponentData, ChannelSelectMenuComponentData } from "discord.js";
|
|
2
|
-
import { defaultify } from "stuffs";
|
|
3
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
4
|
-
import { DBIChannelSelectMenu } from "../Components/ChannelSelectMenu";
|
|
5
|
-
import { RecursivePartial } from "../../utils/UtilTypes";
|
|
6
|
-
|
|
7
|
-
export type DBIChannelSelectMenuOverrides = RecursivePartial<Omit<ChannelSelectMenuComponentData, "customId" | "type">>
|
|
8
|
-
|
|
9
|
-
export class DBIChannelSelectMenuBuilder<TNamespace extends NamespaceEnums> {
|
|
10
|
-
component: DBIChannelSelectMenu<TNamespace>
|
|
11
|
-
overrides: DBIChannelSelectMenuOverrides;
|
|
12
|
-
reference: { data: (string | number | object | boolean | null | undefined)[], ttl?: number };
|
|
13
|
-
constructor(arg: { component: DBIChannelSelectMenu<TNamespace>, overrides?: DBIChannelSelectMenuOverrides, reference?: { data: (string | number | object | boolean | null | undefined)[], ttl?: number } }) {
|
|
14
|
-
this.component = arg.component;
|
|
15
|
-
this.overrides = arg.overrides ?? {};
|
|
16
|
-
this.reference = arg.reference ?? { data: [] };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setTTL(ttl: number): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
20
|
-
this.reference.ttl = ttl;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
addTTL(ttl: number): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
25
|
-
this.reference.ttl = (this.reference.ttl ?? 0) + ttl;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setData(...data: (string | number | object | boolean | null | undefined)[]): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
30
|
-
this.reference.data = data;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
addData(...data: (string | number | object | boolean | null | undefined)[]): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
35
|
-
this.reference.data = [...this.reference.data, ...data];
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setOverrides(overrides: DBIChannelSelectMenuOverrides): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
40
|
-
this.overrides = overrides;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addOverrides(overrides: DBIChannelSelectMenuOverrides): DBIChannelSelectMenuBuilder<TNamespace> {
|
|
45
|
-
this.overrides = defaultify(overrides, this.overrides, true);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
toJSON(): BaseSelectMenuComponentData {
|
|
50
|
-
return this.component.toJSON({ overrides: this.overrides as any, reference: this.reference });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|