@mostfeatured/dbi 0.1.29 → 0.1.31

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.
Files changed (102) hide show
  1. package/.gitattributes +2 -2
  2. package/.hintrc +7 -7
  3. package/.vscode/settings.json +2 -2
  4. package/LICENSE +674 -674
  5. package/dist/DBI.js.map +1 -1
  6. package/dist/Events.js.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methods/handleMessageCommands.js +1 -1
  9. package/dist/methods/handleMessageCommands.js.map +1 -1
  10. package/dist/methods/hookEventListeners.js.map +1 -1
  11. package/dist/methods/hookInteractionListeners.js.map +1 -1
  12. package/dist/methods/publishInteractions.js.map +1 -1
  13. package/dist/types/ApplicationRoleConnectionMetadata.js.map +1 -1
  14. package/dist/types/Builders/ButtonBuilder.js.map +1 -1
  15. package/dist/types/Builders/ChannelSelectMenuBuilder.js.map +1 -1
  16. package/dist/types/Builders/MentionableSelectMenuBuilder.js.map +1 -1
  17. package/dist/types/Builders/ModalBuilder.js.map +1 -1
  18. package/dist/types/Builders/RoleSelectMenuBuilder.js.map +1 -1
  19. package/dist/types/Builders/StringSelectMenuBuilder.js.map +1 -1
  20. package/dist/types/Builders/UserSelectMenuBuilder.js.map +1 -1
  21. package/dist/types/ChatInput/ChatInput.js.map +1 -1
  22. package/dist/types/ChatInput/ChatInputOptions.d.ts +16 -16
  23. package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
  24. package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
  25. package/dist/types/Components/Button.js.map +1 -1
  26. package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
  27. package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
  28. package/dist/types/Components/Modal.js.map +1 -1
  29. package/dist/types/Components/RoleSelectMenu.js.map +1 -1
  30. package/dist/types/Components/StringSelectMenu.js.map +1 -1
  31. package/dist/types/Components/UserSelectMenu.js.map +1 -1
  32. package/dist/types/Event.js.map +1 -1
  33. package/dist/types/Interaction.d.ts +1 -0
  34. package/dist/types/Interaction.d.ts.map +1 -1
  35. package/dist/types/Interaction.js.map +1 -1
  36. package/dist/types/other/CustomEvent.js.map +1 -1
  37. package/dist/types/other/FakeMessageInteraction.js.map +1 -1
  38. package/dist/types/other/InteractionLocale.js.map +1 -1
  39. package/dist/types/other/Locale.js.map +1 -1
  40. package/dist/types/other/MessageContextMenu.js.map +1 -1
  41. package/dist/types/other/UserContextMenu.js.map +1 -1
  42. package/dist/utils/MemoryStore.js.map +1 -1
  43. package/dist/utils/UtilTypes.js.map +1 -1
  44. package/dist/utils/customId.js.map +1 -1
  45. package/dist/utils/permissions.js.map +1 -1
  46. package/dist/utils/recursiveImport.js.map +1 -1
  47. package/dist/utils/recursiveUnload.js.map +1 -1
  48. package/dist/utils/unloadModule.js.map +1 -1
  49. package/examples/modal/dbi.js +29 -29
  50. package/examples/modal/login.js +14 -14
  51. package/examples/modal/package.json +15 -15
  52. package/examples/modal/publish.js +12 -12
  53. package/examples/modal/src/chatInput.js +37 -37
  54. package/examples/modal/src/components.js +32 -32
  55. package/examples/modal/src/event.js +19 -19
  56. package/examples/modal/src/interactionlocales.js +23 -23
  57. package/examples/modal/src/locales.js +37 -37
  58. package/examples/modal/src/modal.js +27 -27
  59. package/generated/namespaceData.d.ts +14 -14
  60. package/package.json +45 -45
  61. package/readme.md +591 -591
  62. package/src/DBI.ts +1090 -1090
  63. package/src/Events.ts +189 -189
  64. package/src/data/eventMap.json +247 -247
  65. package/src/index.ts +23 -23
  66. package/src/methods/handleMessageCommands.ts +482 -482
  67. package/src/methods/hookEventListeners.ts +118 -118
  68. package/src/methods/hookInteractionListeners.ts +260 -260
  69. package/src/methods/publishInteractions.ts +255 -255
  70. package/src/types/ApplicationRoleConnectionMetadata.ts +19 -19
  71. package/src/types/Builders/ButtonBuilder.ts +52 -52
  72. package/src/types/Builders/ChannelSelectMenuBuilder.ts +52 -52
  73. package/src/types/Builders/MentionableSelectMenuBuilder.ts +52 -52
  74. package/src/types/Builders/ModalBuilder.ts +52 -52
  75. package/src/types/Builders/RoleSelectMenuBuilder.ts +52 -52
  76. package/src/types/Builders/StringSelectMenuBuilder.ts +52 -52
  77. package/src/types/Builders/UserSelectMenuBuilder.ts +52 -52
  78. package/src/types/ChatInput/ChatInput.ts +27 -27
  79. package/src/types/ChatInput/ChatInputOptions.ts +388 -388
  80. package/src/types/Components/Button.ts +38 -38
  81. package/src/types/Components/ChannelSelectMenu.ts +42 -42
  82. package/src/types/Components/MentionableSelectMenu.ts +42 -42
  83. package/src/types/Components/Modal.ts +45 -45
  84. package/src/types/Components/RoleSelectMenu.ts +42 -42
  85. package/src/types/Components/StringSelectMenu.ts +42 -42
  86. package/src/types/Components/UserSelectMenu.ts +42 -42
  87. package/src/types/Event.ts +144 -144
  88. package/src/types/Interaction.ts +96 -96
  89. package/src/types/other/CustomEvent.ts +18 -18
  90. package/src/types/other/FakeMessageInteraction.ts +407 -407
  91. package/src/types/other/InteractionLocale.ts +33 -33
  92. package/src/types/other/Locale.ts +69 -69
  93. package/src/types/other/MessageContextMenu.ts +26 -26
  94. package/src/types/other/UserContextMenu.ts +24 -24
  95. package/src/utils/MemoryStore.ts +27 -27
  96. package/src/utils/UtilTypes.ts +10 -10
  97. package/src/utils/customId.ts +44 -44
  98. package/src/utils/permissions.ts +4 -4
  99. package/src/utils/recursiveImport.ts +22 -22
  100. package/src/utils/recursiveUnload.ts +24 -24
  101. package/src/utils/unloadModule.ts +6 -6
  102. package/tsconfig.json +40 -40
@@ -1,256 +1,256 @@
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
- }
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
256
  }
@@ -1,19 +1,19 @@
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
+ 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 +1,53 @@
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
-
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
53
  }