@mostfeatured/dbi 0.0.10 → 0.0.11
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 +25 -3
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +44 -2
- package/dist/DBI.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/hookInteractionListeners.js +1 -1
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/methods/publishInteractions.d.ts +4 -1
- package/dist/methods/publishInteractions.d.ts.map +1 -1
- package/dist/methods/publishInteractions.js +83 -10
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +46 -0
- package/dist/test.js.map +1 -0
- package/dist/types/InteractionLocale.d.ts +22 -0
- package/dist/types/InteractionLocale.d.ts.map +1 -0
- package/dist/types/InteractionLocale.js +15 -0
- package/dist/types/InteractionLocale.js.map +1 -0
- package/dist/utils/MemoryStore.d.ts +1 -1
- package/dist/utils/MemoryStore.d.ts.map +1 -1
- package/dist/utils/MemoryStore.js +1 -1
- package/dist/utils/MemoryStore.js.map +1 -1
- package/package.json +2 -2
- package/src/DBI.ts +55 -6
- package/src/index.ts +2 -2
- package/src/methods/hookInteractionListeners.ts +1 -1
- package/src/methods/publishInteractions.ts +85 -8
- package/src/types/InteractionLocale.ts +28 -0
- package/src/utils/MemoryStore.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publishInteractions.js","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":";;;;AAEA,0CAAuC;AACvC,6CAAiK;AACjK,sDAAyD;AACzD,4EAA2C;AAE3C,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AAE1E,KAAK,UAAU,mBAAmB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,CAAC,CAAC;YACb,MAAM,IAAI,CAAC,GAAG,CAAC,WAAM,CAAC,wBAAwB,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,MAAM;SACP;QACD,KAAK,OAAO,CAAC,CAAC;YACZ,MAAM,IAAI,CAAC,GAAG,CAAC,WAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,MAAM;SACP;KACF;AAEH,CAAC;AApJD,kDAoJC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { DBIChatInput } from \"../types/ChatInput/ChatInput\";\r\nimport { REST } from \"@discordjs/rest\";\r\nimport { Routes, RESTGetAPIUserResult, RESTPutAPIApplicationCommandsJSONBody, ApplicationCommandType, ApplicationCommandOptionType } from \"discord-api-types/v9\";\r\nimport { reducePermissions } from \"../utils/permissions\";\r\nimport snakecaseKeys from \"snakecase-keys\";\r\n\r\nconst PUBLISHABLE_TYPES = [\"ChatInput\", \"UserContextMenu\", \"MessageContextMenu\"];\r\n\r\nexport async function publishInteractions(\r\n clientToken: string,\r\n interactions: Discord.Collection<string, DBIChatInput>,\r\n publishType: \"Guild\" | \"Global\",\r\n guildId?: string\r\n) {\r\n interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));\r\n\r\n const rest = new REST({ version: \"9\" });\r\n rest.setToken(clientToken);\r\n\r\n const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;\r\n \r\n const body: RESTPutAPIApplicationCommandsJSONBody =\r\n interactions.reduce((all, current) => {\r\n switch (current.type) {\r\n case \"ChatInput\": {\r\n let nameSplitted = current.name.split(\" \");\r\n switch (nameSplitted.length) {\r\n case 1: {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n description: current.description,\r\n name: nameSplitted[0],\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: snakecaseKeys(current.options || [])\r\n });\r\n break;\r\n }\r\n case 2: {\r\n let baseItem = all.find(i => i.name == current.name.split(\" \")[0] && i.type == \"ChatInput\");\r\n let option = {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[1],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: snakecaseKeys(current.options || [])\r\n };\r\n if (!baseItem) {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n description: \"...\",\r\n options: [\r\n option\r\n ]\r\n });\r\n } else {\r\n baseItem.options.push(option);\r\n }\r\n break;\r\n }\r\n case 3: {\r\n let level1Item = all.find(i => i.name == current.name.split(\" \")[0] && i.type == \"ChatInput\");\r\n if (!level1Item) {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.SubcommandGroup,\r\n name: nameSplitted[1],\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: snakecaseKeys(current.options || [])\r\n }\r\n ]\r\n }\r\n ]\r\n });\r\n } else {\r\n let level2Item = level1Item.options.find(i => i.name == current.name.split(\" \")[1] && i.type == \"ChatInput\");\r\n if (!level2Item) {\r\n level1Item.options.push({\r\n type: ApplicationCommandOptionType.SubcommandGroup,\r\n name: nameSplitted[1],\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: snakecaseKeys(current.options || [])\r\n }\r\n ]\r\n })\r\n } else {\r\n level2Item.options.push({\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: snakecaseKeys(current.options || [])\r\n });\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n case \"MessageContextMenu\": {\r\n all.push({\r\n type: ApplicationCommandType.Message,\r\n name: current.name,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages\r\n });\r\n break;\r\n }\r\n case \"UserContextMenu\": {\r\n all.push({\r\n type: ApplicationCommandType.User,\r\n name: current.name,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages\r\n });\r\n break;\r\n }\r\n }\r\n\r\n return all;\r\n }, []);\r\n \r\n \r\n switch (publishType) {\r\n case \"Global\": {\r\n await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body });\r\n break;\r\n }\r\n case \"Guild\": {\r\n await rest.put(Routes.applicationCommands(me.id), { body });\r\n break;\r\n }\r\n }\r\n \r\n}"]}
|
|
1
|
+
{"version":3,"file":"publishInteractions.js","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":";;;;AAEA,0CAAuC;AACvC,6CAAiK;AACjK,sDAAyD;AACzD,4EAA2C;AAI3C,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AACjF,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAA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E,EAAE;gBAC5E,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;oBAAE,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;gBACjE,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,WAAW;oBAAE,cAAc,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC;gBACzF,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,kBAAkB;oBAAE,cAAc,CAAC,UAAU,CAAC,CAAC,kBAAkB,GAAG,EAAE,CAAC;gBAEvG,cAAc,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;gBACrE,cAAc,CAAC,UAAU,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;YACrF,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,cAAc;QACd,kBAAkB;QAClB,cAAc;KACf,CAAA;AACH,CAAC;AAtCD,oCAsCC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { DBIChatInput } from \"../types/ChatInput/ChatInput\";\r\nimport { REST } from \"@discordjs/rest\";\r\nimport { Routes, RESTGetAPIUserResult, RESTPutAPIApplicationCommandsJSONBody, ApplicationCommandType, ApplicationCommandOptionType } from \"discord-api-types/v9\";\r\nimport { reducePermissions } from \"../utils/permissions\";\r\nimport snakecaseKeys from \"snakecase-keys\";\r\nimport { DBI } from \"../DBI\";\r\nimport { DBIInteractionLocale } from \"../types/InteractionLocale\";\r\n\r\nconst PUBLISHABLE_TYPES = [\"ChatInput\", \"UserContextMenu\", \"MessageContextMenu\"];\r\nconst 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\"];\r\n\r\nexport async function publishInteractions(\r\n clientToken: string,\r\n interactions: Discord.Collection<string, DBIChatInput>,\r\n interactionsLocales: Discord.Collection<string, DBIInteractionLocale>,\r\n publishType: \"Guild\" | \"Global\",\r\n guildId?: string\r\n) {\r\n interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));\r\n\r\n const rest = new REST({ version: \"9\" });\r\n rest.setToken(clientToken);\r\n\r\n const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;\r\n \r\n let body: RESTPutAPIApplicationCommandsJSONBody =\r\n interactions.reduce((all, current) => {\r\n switch (current.type) {\r\n case \"ChatInput\": {\r\n let nameSplitted = current.name.split(\" \");\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n switch (nameSplitted.length) {\r\n case 1: {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n description: current.description,\r\n name: nameSplitted[0],\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: localeifyOptions(current.options || [], localeData.optionsLocales),\r\n name_localizations: localeData.nameLocales(0),\r\n description_localizations: localeData.descriptionLocales,\r\n });\r\n break;\r\n }\r\n case 2: {\r\n let baseItem = all.find(i => i.name == current.name.split(\" \")[0] && i.type == \"ChatInput\");\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n let option = {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[1],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: localeifyOptions(current.options || [], localeData.optionsLocales),\r\n name_localizations: localeData.nameLocales(1),\r\n description_localizations: localeData.descriptionLocales,\r\n };\r\n if (!baseItem) {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n name_localizations: localeData.nameLocales(0),\r\n description: \"...\",\r\n options: [\r\n option\r\n ]\r\n });\r\n } else {\r\n baseItem.options.push(option);\r\n }\r\n break;\r\n }\r\n case 3: {\r\n let level1Item = all.find(i => i.name == current.name.split(\" \")[0] && i.type == \"ChatInput\");\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n if (!level1Item) {\r\n all.push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n name_localizations: localeData.nameLocales(0),\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.SubcommandGroup,\r\n name: nameSplitted[1],\r\n name_localizations: localeData.nameLocales(1),\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: localeifyOptions(current.options || [], localeData.optionsLocales),\r\n name_localizations: localeData.nameLocales(2),\r\n description_localizations: localeData.descriptionLocales,\r\n }\r\n ]\r\n }\r\n ]\r\n });\r\n } else {\r\n let level2Item = level1Item.options.find(i => i.name == current.name.split(\" \")[1] && i.type == \"ChatInput\");\r\n if (!level2Item) {\r\n level1Item.options.push({\r\n type: ApplicationCommandOptionType.SubcommandGroup,\r\n name: nameSplitted[1],\r\n name_localizations: localeData.nameLocales(1),\r\n description: \"...\",\r\n options: [\r\n {\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: localeifyOptions(current.options || [], localeData.optionsLocales),\r\n name_localizations: localeData.nameLocales(2),\r\n description_localizations: localeData.descriptionLocales\r\n }\r\n ]\r\n })\r\n } else {\r\n level2Item.options.push({\r\n type: ApplicationCommandOptionType.Subcommand,\r\n name: nameSplitted[2],\r\n description: current.description,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n options: localeifyOptions(current.options || [], localeData.optionsLocales),\r\n name_localizations: localeData.nameLocales(2),\r\n description_localizations: localeData.descriptionLocales,\r\n });\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n case \"MessageContextMenu\": {\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n all.push({\r\n type: ApplicationCommandType.Message,\r\n name: current.name,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n name_localizations: localeData.allNameLocales,\r\n description_localizations: localeData.descriptionLocales,\r\n });\r\n break;\r\n }\r\n case \"UserContextMenu\": {\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n all.push({\r\n type: ApplicationCommandType.User,\r\n name: current.name,\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\r\n dm_permission: current.directMessages,\r\n name_localizations: localeData.allNameLocales,\r\n description_localizations: localeData.descriptionLocales\r\n });\r\n break;\r\n }\r\n }\r\n\r\n return all;\r\n }, []);\r\n \r\n body = snakecaseKeys(body);\r\n \r\n switch (publishType) {\r\n case \"Global\": {\r\n await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body });\r\n break;\r\n }\r\n case \"Guild\": {\r\n await rest.put(Routes.applicationCommands(me.id), { body });\r\n break;\r\n }\r\n }\r\n \r\n}\r\n\r\nexport function localeifyOptions(options: any[], localeData: any): any[] {\r\n return options.map(i => {\r\n return localeData[i.name] ? Object.assign(i, {\r\n name_localizations: localeData[i.name].nameLocales,\r\n description_localizations: localeData[i.name].descriptionLocales,\r\n }) : i;\r\n })\r\n}\r\n\r\nexport function formatLocale(locale: DBIInteractionLocale): any {\r\n let allNameLocales = {};\r\n let descriptionLocales = {};\r\n let optionsLocales = {};\r\n\r\n function nameLocales(index) {\r\n return Object.fromEntries(Object.entries(allNameLocales).map(i => [i[0], (i[1] as string).split(\" \").at(index)]));\r\n }\r\n\r\n if (!locale?.data) return {\r\n nameLocales,\r\n allNameLocales,\r\n descriptionLocales,\r\n optionsLocales\r\n };\r\n\r\n Object.entries(locale.data).forEach(([shortLocale, localeData]) => {\r\n let longAliases = ORIGINAL_LOCALES.filter(i => i.split(\"-\").at(0) == shortLocale);\r\n longAliases.forEach((longLocale) => {\r\n allNameLocales[longLocale] = localeData.name;\r\n descriptionLocales[longLocale] = localeData.description;\r\n Object.entries(localeData.options || []).forEach(([optionName, optionData]) => {\r\n if (!optionsLocales[optionName]) optionsLocales[optionName] = {};\r\n if (!optionsLocales[optionName].nameLocales) optionsLocales[optionName].nameLocales = {};\r\n if (!optionsLocales[optionName].descriptionLocales) optionsLocales[optionName].descriptionLocales = {};\r\n\r\n optionsLocales[optionName].nameLocales[longLocale] = optionData.name;\r\n optionsLocales[optionName].descriptionLocales[longLocale] = optionData.description;\r\n })\r\n });\r\n });\r\n \r\n return {\r\n nameLocales,\r\n allNameLocales,\r\n descriptionLocales,\r\n optionsLocales\r\n }\r\n}"]}
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
let dbi = (0, _1.createDBI)("asd", {
|
|
5
|
+
discord: {
|
|
6
|
+
token: "ODI0MjEwMTMyMzUwMDA5MzY2.G8YRue.GPxxFyZTOG0cnijU_O8U9uvBDwf01zuVHBBoKI",
|
|
7
|
+
options: {
|
|
8
|
+
intents: ["Guilds"]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
dbi.register(({ InteractionLocale, ChatInput, ChatInputOptions }) => {
|
|
13
|
+
ChatInput({
|
|
14
|
+
name: "english command",
|
|
15
|
+
description: "english command",
|
|
16
|
+
onExecute(ctx) {
|
|
17
|
+
ctx.interaction.reply("wow");
|
|
18
|
+
},
|
|
19
|
+
options: [
|
|
20
|
+
ChatInputOptions.string({
|
|
21
|
+
name: "value",
|
|
22
|
+
description: "..."
|
|
23
|
+
})
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
// InteractionLocale({
|
|
27
|
+
// name: "english command",
|
|
28
|
+
// data: {
|
|
29
|
+
// tr: {
|
|
30
|
+
// name: "turkce komut",
|
|
31
|
+
// description: "turkce komut",
|
|
32
|
+
// options: {
|
|
33
|
+
// value: {
|
|
34
|
+
// name: "deger",
|
|
35
|
+
// description: "..."
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
40
|
+
// })
|
|
41
|
+
});
|
|
42
|
+
(async () => {
|
|
43
|
+
await dbi.load();
|
|
44
|
+
await dbi.publish("Guild", "817408899904438282");
|
|
45
|
+
})();
|
|
46
|
+
//# sourceMappingURL=test.js.map
|
package/dist/test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,wBAA8B;AAE9B,IAAI,GAAG,GAAG,IAAA,YAAS,EAA+B,KAAK,EAAE;IACvD,OAAO,EAAE;QACP,KAAK,EAAE,wEAAwE;QAC/E,OAAO,EAAE;YACP,OAAO,EAAE,CAAC,QAAQ,CAAC;SACpB;KACF;CACF,CAAC,CAAC;AAEH,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAiB,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE;IAClE,SAAS,CAAC;QACR,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,iBAAiB;QAC9B,SAAS,CAAC,GAAG;YACX,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE;YACP,gBAAgB,CAAC,MAAM,CAAC;gBACtB,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,KAAK;aACnB,CAAC;SACH;KACF,CAAC,CAAC;IAEH,sBAAsB;IACtB,6BAA6B;IAC7B,YAAY;IACZ,YAAY;IACZ,8BAA8B;IAC9B,qCAAqC;IACrC,mBAAmB;IACnB,mBAAmB;IACnB,2BAA2B;IAC3B,+BAA+B;IAC/B,YAAY;IACZ,UAAU;IACV,QAAQ;IACR,MAAM;IACN,KAAK;AACP,CAAC,CAAC,CAAC;AAEH,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACnD,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { createDBI } from \".\";\r\n\r\nlet dbi = createDBI<{ musics: Map<string, any> }>(\"asd\", {\r\n discord: {\r\n token: \"ODI0MjEwMTMyMzUwMDA5MzY2.G8YRue.GPxxFyZTOG0cnijU_O8U9uvBDwf01zuVHBBoKI\",\r\n options: {\r\n intents: [\"Guilds\"]\r\n }\r\n }\r\n});\r\n\r\ndbi.register(({ InteractionLocale, ChatInput, ChatInputOptions }) => {\r\n ChatInput({\r\n name: \"english command\",\r\n description: \"english command\",\r\n onExecute(ctx) {\r\n ctx.interaction.reply(\"wow\");\r\n },\r\n options: [\r\n ChatInputOptions.string({\r\n name: \"value\",\r\n description: \"...\"\r\n })\r\n ]\r\n });\r\n\r\n // InteractionLocale({\r\n // name: \"english command\",\r\n // data: {\r\n // tr: {\r\n // name: \"turkce komut\",\r\n // description: \"turkce komut\",\r\n // options: {\r\n // value: {\r\n // name: \"deger\",\r\n // description: \"...\"\r\n // }\r\n // }\r\n // }\r\n // }\r\n // })\r\n});\r\n\r\n(async () => {\r\n await dbi.load();\r\n await dbi.publish(\"Guild\", \"817408899904438282\");\r\n})();"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DBI } from "../DBI";
|
|
2
|
+
import { TDBILocaleString } from "./Locale";
|
|
3
|
+
export declare type TDBIInteractionLocaleData = {
|
|
4
|
+
[K in TDBILocaleString]?: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
options?: {
|
|
8
|
+
[k: string]: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, "dbi">;
|
|
16
|
+
export declare class DBIInteractionLocale {
|
|
17
|
+
name: string;
|
|
18
|
+
data: TDBIInteractionLocaleData;
|
|
19
|
+
dbi: DBI;
|
|
20
|
+
constructor(dbi: any, cfg: TDBIInteractionLocaleOmitted);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=InteractionLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractionLocale.d.ts","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,oBAAY,yBAAyB,GAAG;KACrC,CAAC,IAAI,gBAAgB,CAAC,CAAC,EAAE;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE;YACR,CAAC,CAAC,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,EAAE,MAAM,CAAC;aACrB,CAAA;SACF,CAAA;KACF;CACF,CAAC;AAEF,oBAAY,4BAA4B,GAAG,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;AAE7E,qBAAa,oBAAoB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,yBAAyB,CAAC;IAChC,GAAG,EAAE,GAAG,CAAC;gBACG,GAAG,KAAA,EAAE,GAAG,EAAE,4BAA4B;CAKnD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DBIInteractionLocale = void 0;
|
|
4
|
+
class DBIInteractionLocale {
|
|
5
|
+
name;
|
|
6
|
+
data;
|
|
7
|
+
dbi;
|
|
8
|
+
constructor(dbi, cfg) {
|
|
9
|
+
this.dbi = dbi;
|
|
10
|
+
this.name = cfg.name;
|
|
11
|
+
this.data = cfg.data;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DBIInteractionLocale = DBIInteractionLocale;
|
|
15
|
+
//# sourceMappingURL=InteractionLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractionLocale.js","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":";;;AAkBA,MAAa,oBAAoB;IAC/B,IAAI,CAAS;IACb,IAAI,CAA4B;IAChC,GAAG,CAAM;IACT,YAAY,GAAG,EAAE,GAAiC;QAChD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AATD,oDASC","sourcesContent":["import { DBI } from \"../DBI\";\r\nimport { TDBILocaleString } from \"./Locale\";\r\n\r\nexport type TDBIInteractionLocaleData = {\r\n [K in TDBILocaleString]?: {\r\n name: string;\r\n description: string;\r\n options?: {\r\n [k: string]: {\r\n name: string;\r\n description: string;\r\n }\r\n }\r\n };\r\n};\r\n\r\nexport type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, \"dbi\">;\r\n\r\nexport class DBIInteractionLocale {\r\n name: string;\r\n data: TDBIInteractionLocaleData;\r\n dbi: DBI;\r\n constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {\r\n this.dbi = dbi;\r\n this.name = cfg.name;\r\n this.data = cfg.data;\r\n }\r\n}"]}
|
|
@@ -3,7 +3,7 @@ export declare class MemoryStore {
|
|
|
3
3
|
constructor();
|
|
4
4
|
get(key: string, defaultValue?: any): Promise<any>;
|
|
5
5
|
set(key: string, value: any): Promise<any>;
|
|
6
|
-
|
|
6
|
+
delete(key: string): Promise<boolean>;
|
|
7
7
|
has(key: string): Promise<boolean>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=MemoryStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryStore.d.ts","sourceRoot":"","sources":["../../src/utils/MemoryStore.ts"],"names":[],"mappings":"AAEA,qBAAa,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;;IAIrB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IASlD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAI1C,
|
|
1
|
+
{"version":3,"file":"MemoryStore.d.ts","sourceRoot":"","sources":["../../src/utils/MemoryStore.ts"],"names":[],"mappings":"AAEA,qBAAa,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;;IAIrB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IASlD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAI1C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIrC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryStore.js","sourceRoot":"","sources":["../../src/utils/MemoryStore.ts"],"names":[],"mappings":";;;;AAAA,4DAAuB;AAEvB,MAAa,WAAW;IACtB,KAAK,CAAsB;IAC3B;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,YAAkB;QACvC,IAAI,GAAG,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,EAAE;YACR,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAC5B,OAAO,YAAY,CAAC;SACrB;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAU;QAC/B,OAAO,IAAI,CAAC,KAAK,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"MemoryStore.js","sourceRoot":"","sources":["../../src/utils/MemoryStore.ts"],"names":[],"mappings":";;;;AAAA,4DAAuB;AAEvB,MAAa,WAAW;IACtB,KAAK,CAAsB;IAC3B;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,YAAkB;QACvC,IAAI,GAAG,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,EAAE;YACR,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAC5B,OAAO,YAAY,CAAC;SACrB;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAU;QAC/B,OAAO,IAAI,CAAC,KAAK,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,OAAO,gBAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,gBAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;CACF;AAzBD,kCAyBC","sourcesContent":["import _ from \"lodash\";\r\n\r\nexport class MemoryStore {\r\n store: Record<string, any>;\r\n constructor() {\r\n this.store = {};\r\n }\r\n async get(key: string, defaultValue?: any): Promise<any> {\r\n let val = _.get(this.store, key);\r\n if (!val) {\r\n this.set(key, defaultValue);\r\n return defaultValue;\r\n }\r\n return val;\r\n }\r\n\r\n async set(key: string, value: any): Promise<any> {\r\n return this.store = _.set(this.store, key, value);\r\n }\r\n\r\n async delete(key: string): Promise<boolean> {\r\n return _.unset(this.store, key);\r\n }\r\n\r\n async has(key: string): Promise<boolean> {\r\n return _.has(this.store, key);\r\n }\r\n}"]}
|
package/package.json
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
"@discordjs/rest": "^1.0.1",
|
|
4
4
|
"discord-api-types": "^0.37.0",
|
|
5
5
|
"discord-hybrid-sharding": "^1.7.4",
|
|
6
|
-
"discord.js": "^14.
|
|
6
|
+
"discord.js": "^14.3.0",
|
|
7
7
|
"lodash": "^4.17.21",
|
|
8
8
|
"snakecase-keys": "^5.4.2",
|
|
9
9
|
"stuffs": "^0.1.17"
|
|
10
10
|
},
|
|
11
11
|
"name": "@mostfeatured/dbi",
|
|
12
|
-
"version": "0.0.
|
|
12
|
+
"version": "0.0.11",
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"private": false,
|
package/src/DBI.ts
CHANGED
|
@@ -15,11 +15,13 @@ import { hookEventListeners } from "./methods/hookEventListeners";
|
|
|
15
15
|
import eventMap from "./data/eventMap.json";
|
|
16
16
|
import { DBIModal, TDBIModalOmitted } from "./types/Modal";
|
|
17
17
|
import * as Sharding from "discord-hybrid-sharding";
|
|
18
|
+
import _ from "lodash";
|
|
19
|
+
import { DBIInteractionLocale, TDBIInteractionLocaleOmitted } from "./types/InteractionLocale";
|
|
18
20
|
|
|
19
21
|
export interface DBIStore {
|
|
20
22
|
get(key: string, defaultValue?: any): Promise<any>;
|
|
21
23
|
set(key: string, value: any): Promise<void>;
|
|
22
|
-
|
|
24
|
+
delete(key: string): Promise<void>;
|
|
23
25
|
has(key: string): Promise<boolean>;
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -35,7 +37,9 @@ export interface DBIConfig {
|
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
sharding: boolean;
|
|
38
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
42
|
+
*/
|
|
39
43
|
store: DBIStore;
|
|
40
44
|
}
|
|
41
45
|
|
|
@@ -50,11 +54,12 @@ export interface DBIRegisterAPI {
|
|
|
50
54
|
SelectMenu(cfg: TDBISelectMenuOmitted): DBISelectMenu;
|
|
51
55
|
MessageContextMenu(cfg: TDBIMessageContextMenuOmitted): DBIMessageContextMenu;
|
|
52
56
|
UserContextMenu(cfg: TDBIUserContextMenuOmitted): DBIUserContextMenu;
|
|
57
|
+
InteractionLocale(cfg: TDBIInteractionLocaleOmitted): DBIInteractionLocale;
|
|
53
58
|
Modal(cfg: TDBIModalOmitted): DBIModal;
|
|
54
59
|
onUnload(cb: () => Promise<any> | any): any;
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
export class DBI {
|
|
62
|
+
export class DBI<TOtherData = Record<string, any>> {
|
|
58
63
|
namespace: string;
|
|
59
64
|
config: DBIConfig;
|
|
60
65
|
client: Discord.Client<true>;
|
|
@@ -63,7 +68,8 @@ export class DBI {
|
|
|
63
68
|
events: Discord.Collection<string, DBIEvent>;
|
|
64
69
|
plugins: Discord.Collection<string, any>;
|
|
65
70
|
locales: Discord.Collection<string, DBILocale>;
|
|
66
|
-
|
|
71
|
+
interactionLocales: Discord.Collection<string, DBIInteractionLocale>;
|
|
72
|
+
other: TOtherData;
|
|
67
73
|
eventMap: Record<string, string[]>;
|
|
68
74
|
unloaders: Set<() => void>;
|
|
69
75
|
registers: Set<(...args: any[]) => any>;
|
|
@@ -93,7 +99,8 @@ export class DBI {
|
|
|
93
99
|
events: new Discord.Collection(),
|
|
94
100
|
plugins: new Discord.Collection(),
|
|
95
101
|
locales: new Discord.Collection(),
|
|
96
|
-
|
|
102
|
+
interactionLocales: new Discord.Collection(),
|
|
103
|
+
other: {} as TOtherData,
|
|
97
104
|
eventMap,
|
|
98
105
|
unloaders: new Set(),
|
|
99
106
|
registers: new Set(),
|
|
@@ -188,7 +195,6 @@ export class DBI {
|
|
|
188
195
|
};
|
|
189
196
|
Modal = Object.assign(Modal, class { constructor(...args: any[]) { return Modal.apply(this, args as any); } });
|
|
190
197
|
|
|
191
|
-
|
|
192
198
|
let Locale = function(cfg: TDBILocaleConstructor) {
|
|
193
199
|
let dbiLocale = new DBILocale(self, cfg);
|
|
194
200
|
if (self.data.locales.has(dbiLocale.name)) throw new Error(`DBILocale "${dbiLocale.name}" already loaded!`);
|
|
@@ -197,6 +203,14 @@ export class DBI {
|
|
|
197
203
|
};
|
|
198
204
|
Locale = Object.assign(Locale, class { constructor(...args: any[]) { return Locale.apply(this, args as any); } });
|
|
199
205
|
|
|
206
|
+
let InteractionLocale = function(cfg: TDBIInteractionLocaleOmitted) {
|
|
207
|
+
let dbiInteractionLocale = new DBIInteractionLocale(self, cfg);
|
|
208
|
+
if (self.data.interactionLocales.has(dbiInteractionLocale.name)) throw new Error(`DBIInteractionLocale "${dbiInteractionLocale.name}" already loaded!`);
|
|
209
|
+
self.data.interactionLocales.set(dbiInteractionLocale.name, dbiInteractionLocale);
|
|
210
|
+
return dbiInteractionLocale;
|
|
211
|
+
};
|
|
212
|
+
InteractionLocale = Object.assign(InteractionLocale, class { constructor(...args: any[]) { return InteractionLocale.apply(this, args as any); } });
|
|
213
|
+
|
|
200
214
|
await cb({
|
|
201
215
|
ChatInput,
|
|
202
216
|
Event,
|
|
@@ -207,6 +221,7 @@ export class DBI {
|
|
|
207
221
|
MessageContextMenu,
|
|
208
222
|
UserContextMenu,
|
|
209
223
|
Modal,
|
|
224
|
+
InteractionLocale,
|
|
210
225
|
onUnload(cb: ()=> Promise<any> | any) {
|
|
211
226
|
self.data.registerUnloaders.add(cb);
|
|
212
227
|
},
|
|
@@ -214,6 +229,38 @@ export class DBI {
|
|
|
214
229
|
}
|
|
215
230
|
}
|
|
216
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Shorthands for modifying `dbi.data.other`
|
|
234
|
+
*/
|
|
235
|
+
get<K extends keyof TOtherData>(k: K, defaultValue?: TOtherData[K]): TOtherData[K] {
|
|
236
|
+
if (this.has(k as any)) {
|
|
237
|
+
this.set(k, defaultValue);
|
|
238
|
+
return defaultValue;
|
|
239
|
+
}
|
|
240
|
+
return _.get(this.data.other, k);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Shorthands for modifying `dbi.data.other`
|
|
245
|
+
*/
|
|
246
|
+
set<K extends keyof TOtherData>(k: K, v: TOtherData[K]): any {
|
|
247
|
+
this.data.other = _.set(this.data.other as any, k, v);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Shorthands for modifying `dbi.data.other`
|
|
252
|
+
*/
|
|
253
|
+
has(k: string): boolean {
|
|
254
|
+
return _.has(this.data.other, k as any);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Shorthands for modifying `dbi.data.other`
|
|
259
|
+
*/
|
|
260
|
+
delete(k: string): boolean {
|
|
261
|
+
return _.unset(this.data.other, k);
|
|
262
|
+
}
|
|
263
|
+
|
|
217
264
|
async login(): Promise<any> {
|
|
218
265
|
await this.client.login(this.config.discord.token);
|
|
219
266
|
}
|
|
@@ -250,6 +297,7 @@ export class DBI {
|
|
|
250
297
|
return await publishInteractions(
|
|
251
298
|
this.config.discord.token,
|
|
252
299
|
args[1] ? new Discord.Collection() : interactions,
|
|
300
|
+
this.data.interactionLocales,
|
|
253
301
|
args[0]
|
|
254
302
|
);
|
|
255
303
|
}
|
|
@@ -257,6 +305,7 @@ export class DBI {
|
|
|
257
305
|
return await publishInteractions(
|
|
258
306
|
this.config.discord.token,
|
|
259
307
|
args[2] ? new Discord.Collection() : interactions,
|
|
308
|
+
this.data.interactionLocales,
|
|
260
309
|
args[0],
|
|
261
310
|
args[1]
|
|
262
311
|
);
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { DBI, TDBIConfigConstructor } from "./DBI";
|
|
|
2
2
|
export { recursiveImport } from "./utils/recursiveImport";
|
|
3
3
|
export { MemoryStore } from "./utils/MemoryStore";
|
|
4
4
|
|
|
5
|
-
export function createDBI(namespace: string, cfg: TDBIConfigConstructor): DBI {
|
|
6
|
-
return new DBI(namespace, cfg);
|
|
5
|
+
export function createDBI<TOtherType = Record<string, any>>(namespace: string, cfg: TDBIConfigConstructor): DBI<TOtherType> {
|
|
6
|
+
return new DBI<TOtherType>(namespace, cfg);
|
|
7
7
|
}
|
|
@@ -72,7 +72,7 @@ export function hookInteractionListeners(dbi: DBI): () => any {
|
|
|
72
72
|
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
73
73
|
let val = await dbi.config.store.get(key);
|
|
74
74
|
if (val && Date.now() > val.at + val.duration) {
|
|
75
|
-
await dbi.config.store.
|
|
75
|
+
await dbi.config.store.delete(key);
|
|
76
76
|
val = null;
|
|
77
77
|
}
|
|
78
78
|
if (val) {
|
|
@@ -4,12 +4,16 @@ 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";
|
|
8
|
+
import { DBIInteractionLocale } from "../types/InteractionLocale";
|
|
7
9
|
|
|
8
10
|
const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"];
|
|
11
|
+
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"];
|
|
9
12
|
|
|
10
13
|
export async function publishInteractions(
|
|
11
14
|
clientToken: string,
|
|
12
15
|
interactions: Discord.Collection<string, DBIChatInput>,
|
|
16
|
+
interactionsLocales: Discord.Collection<string, DBIInteractionLocale>,
|
|
13
17
|
publishType: "Guild" | "Global",
|
|
14
18
|
guildId?: string
|
|
15
19
|
) {
|
|
@@ -20,11 +24,12 @@ export async function publishInteractions(
|
|
|
20
24
|
|
|
21
25
|
const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
let body: RESTPutAPIApplicationCommandsJSONBody =
|
|
24
28
|
interactions.reduce((all, current) => {
|
|
25
29
|
switch (current.type) {
|
|
26
30
|
case "ChatInput": {
|
|
27
31
|
let nameSplitted = current.name.split(" ");
|
|
32
|
+
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
28
33
|
switch (nameSplitted.length) {
|
|
29
34
|
case 1: {
|
|
30
35
|
all.push({
|
|
@@ -33,24 +38,30 @@ export async function publishInteractions(
|
|
|
33
38
|
name: nameSplitted[0],
|
|
34
39
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
35
40
|
dm_permission: current.directMessages,
|
|
36
|
-
options:
|
|
41
|
+
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
42
|
+
name_localizations: localeData.nameLocales(0),
|
|
43
|
+
description_localizations: localeData.descriptionLocales,
|
|
37
44
|
});
|
|
38
45
|
break;
|
|
39
46
|
}
|
|
40
47
|
case 2: {
|
|
41
48
|
let baseItem = all.find(i => i.name == current.name.split(" ")[0] && i.type == "ChatInput");
|
|
49
|
+
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
42
50
|
let option = {
|
|
43
51
|
type: ApplicationCommandOptionType.Subcommand,
|
|
44
52
|
name: nameSplitted[1],
|
|
45
53
|
description: current.description,
|
|
46
54
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
47
55
|
dm_permission: current.directMessages,
|
|
48
|
-
options:
|
|
56
|
+
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
57
|
+
name_localizations: localeData.nameLocales(1),
|
|
58
|
+
description_localizations: localeData.descriptionLocales,
|
|
49
59
|
};
|
|
50
60
|
if (!baseItem) {
|
|
51
61
|
all.push({
|
|
52
62
|
type: ApplicationCommandType.ChatInput,
|
|
53
63
|
name: nameSplitted[0],
|
|
64
|
+
name_localizations: localeData.nameLocales(0),
|
|
54
65
|
description: "...",
|
|
55
66
|
options: [
|
|
56
67
|
option
|
|
@@ -63,15 +74,18 @@ export async function publishInteractions(
|
|
|
63
74
|
}
|
|
64
75
|
case 3: {
|
|
65
76
|
let level1Item = all.find(i => i.name == current.name.split(" ")[0] && i.type == "ChatInput");
|
|
77
|
+
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
66
78
|
if (!level1Item) {
|
|
67
79
|
all.push({
|
|
68
80
|
type: ApplicationCommandType.ChatInput,
|
|
69
81
|
name: nameSplitted[0],
|
|
82
|
+
name_localizations: localeData.nameLocales(0),
|
|
70
83
|
description: "...",
|
|
71
84
|
options: [
|
|
72
85
|
{
|
|
73
86
|
type: ApplicationCommandOptionType.SubcommandGroup,
|
|
74
87
|
name: nameSplitted[1],
|
|
88
|
+
name_localizations: localeData.nameLocales(1),
|
|
75
89
|
description: "...",
|
|
76
90
|
options: [
|
|
77
91
|
{
|
|
@@ -80,7 +94,9 @@ export async function publishInteractions(
|
|
|
80
94
|
description: current.description,
|
|
81
95
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
82
96
|
dm_permission: current.directMessages,
|
|
83
|
-
options:
|
|
97
|
+
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
98
|
+
name_localizations: localeData.nameLocales(2),
|
|
99
|
+
description_localizations: localeData.descriptionLocales,
|
|
84
100
|
}
|
|
85
101
|
]
|
|
86
102
|
}
|
|
@@ -92,6 +108,7 @@ export async function publishInteractions(
|
|
|
92
108
|
level1Item.options.push({
|
|
93
109
|
type: ApplicationCommandOptionType.SubcommandGroup,
|
|
94
110
|
name: nameSplitted[1],
|
|
111
|
+
name_localizations: localeData.nameLocales(1),
|
|
95
112
|
description: "...",
|
|
96
113
|
options: [
|
|
97
114
|
{
|
|
@@ -100,7 +117,9 @@ export async function publishInteractions(
|
|
|
100
117
|
description: current.description,
|
|
101
118
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
102
119
|
dm_permission: current.directMessages,
|
|
103
|
-
options:
|
|
120
|
+
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
121
|
+
name_localizations: localeData.nameLocales(2),
|
|
122
|
+
description_localizations: localeData.descriptionLocales
|
|
104
123
|
}
|
|
105
124
|
]
|
|
106
125
|
})
|
|
@@ -111,7 +130,9 @@ export async function publishInteractions(
|
|
|
111
130
|
description: current.description,
|
|
112
131
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
113
132
|
dm_permission: current.directMessages,
|
|
114
|
-
options:
|
|
133
|
+
options: localeifyOptions(current.options || [], localeData.optionsLocales),
|
|
134
|
+
name_localizations: localeData.nameLocales(2),
|
|
135
|
+
description_localizations: localeData.descriptionLocales,
|
|
115
136
|
});
|
|
116
137
|
}
|
|
117
138
|
}
|
|
@@ -121,20 +142,26 @@ export async function publishInteractions(
|
|
|
121
142
|
break;
|
|
122
143
|
}
|
|
123
144
|
case "MessageContextMenu": {
|
|
145
|
+
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
124
146
|
all.push({
|
|
125
147
|
type: ApplicationCommandType.Message,
|
|
126
148
|
name: current.name,
|
|
127
149
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
128
|
-
dm_permission: current.directMessages
|
|
150
|
+
dm_permission: current.directMessages,
|
|
151
|
+
name_localizations: localeData.allNameLocales,
|
|
152
|
+
description_localizations: localeData.descriptionLocales,
|
|
129
153
|
});
|
|
130
154
|
break;
|
|
131
155
|
}
|
|
132
156
|
case "UserContextMenu": {
|
|
157
|
+
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
133
158
|
all.push({
|
|
134
159
|
type: ApplicationCommandType.User,
|
|
135
160
|
name: current.name,
|
|
136
161
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
137
|
-
dm_permission: current.directMessages
|
|
162
|
+
dm_permission: current.directMessages,
|
|
163
|
+
name_localizations: localeData.allNameLocales,
|
|
164
|
+
description_localizations: localeData.descriptionLocales
|
|
138
165
|
});
|
|
139
166
|
break;
|
|
140
167
|
}
|
|
@@ -143,6 +170,7 @@ export async function publishInteractions(
|
|
|
143
170
|
return all;
|
|
144
171
|
}, []);
|
|
145
172
|
|
|
173
|
+
body = snakecaseKeys(body);
|
|
146
174
|
|
|
147
175
|
switch (publishType) {
|
|
148
176
|
case "Global": {
|
|
@@ -155,4 +183,53 @@ export async function publishInteractions(
|
|
|
155
183
|
}
|
|
156
184
|
}
|
|
157
185
|
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function localeifyOptions(options: any[], localeData: any): any[] {
|
|
189
|
+
return options.map(i => {
|
|
190
|
+
return localeData[i.name] ? Object.assign(i, {
|
|
191
|
+
name_localizations: localeData[i.name].nameLocales,
|
|
192
|
+
description_localizations: localeData[i.name].descriptionLocales,
|
|
193
|
+
}) : i;
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function formatLocale(locale: DBIInteractionLocale): any {
|
|
198
|
+
let allNameLocales = {};
|
|
199
|
+
let descriptionLocales = {};
|
|
200
|
+
let optionsLocales = {};
|
|
201
|
+
|
|
202
|
+
function nameLocales(index) {
|
|
203
|
+
return Object.fromEntries(Object.entries(allNameLocales).map(i => [i[0], (i[1] as string).split(" ").at(index)]));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!locale?.data) return {
|
|
207
|
+
nameLocales,
|
|
208
|
+
allNameLocales,
|
|
209
|
+
descriptionLocales,
|
|
210
|
+
optionsLocales
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
Object.entries(locale.data).forEach(([shortLocale, localeData]) => {
|
|
214
|
+
let longAliases = ORIGINAL_LOCALES.filter(i => i.split("-").at(0) == shortLocale);
|
|
215
|
+
longAliases.forEach((longLocale) => {
|
|
216
|
+
allNameLocales[longLocale] = localeData.name;
|
|
217
|
+
descriptionLocales[longLocale] = localeData.description;
|
|
218
|
+
Object.entries(localeData.options || []).forEach(([optionName, optionData]) => {
|
|
219
|
+
if (!optionsLocales[optionName]) optionsLocales[optionName] = {};
|
|
220
|
+
if (!optionsLocales[optionName].nameLocales) optionsLocales[optionName].nameLocales = {};
|
|
221
|
+
if (!optionsLocales[optionName].descriptionLocales) optionsLocales[optionName].descriptionLocales = {};
|
|
222
|
+
|
|
223
|
+
optionsLocales[optionName].nameLocales[longLocale] = optionData.name;
|
|
224
|
+
optionsLocales[optionName].descriptionLocales[longLocale] = optionData.description;
|
|
225
|
+
})
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
nameLocales,
|
|
231
|
+
allNameLocales,
|
|
232
|
+
descriptionLocales,
|
|
233
|
+
optionsLocales
|
|
234
|
+
}
|
|
158
235
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DBI } from "../DBI";
|
|
2
|
+
import { TDBILocaleString } from "./Locale";
|
|
3
|
+
|
|
4
|
+
export type TDBIInteractionLocaleData = {
|
|
5
|
+
[K in TDBILocaleString]?: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
options?: {
|
|
9
|
+
[k: string]: {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, "dbi">;
|
|
18
|
+
|
|
19
|
+
export class DBIInteractionLocale {
|
|
20
|
+
name: string;
|
|
21
|
+
data: TDBIInteractionLocaleData;
|
|
22
|
+
dbi: DBI;
|
|
23
|
+
constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {
|
|
24
|
+
this.dbi = dbi;
|
|
25
|
+
this.name = cfg.name;
|
|
26
|
+
this.data = cfg.data;
|
|
27
|
+
}
|
|
28
|
+
}
|