@mostfeatured/dbi 0.0.66 → 0.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,242 +1,242 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatLocale = exports.localeifyOptions = exports.publishInteractions = void 0;
4
- const rest_1 = require("@discordjs/rest");
5
- const v9_1 = require("discord-api-types/v9");
6
- const permissions_1 = require("../utils/permissions");
7
- const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"];
8
- 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
- async function publishInteractions(clients, interactions, interactionsLocales, publishType, guildId) {
10
- interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));
11
- interactions = interactions.sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
12
- let body = interactions.reduce((all, current) => {
13
- if (current.publish && !all[current.publish])
14
- all[current.publish] = [];
15
- switch (current.type) {
16
- case "ChatInput": {
17
- let nameSplitted = current.name.split(" ");
18
- let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
19
- switch (nameSplitted.length) {
20
- case 1: {
21
- all[current.publish].push({
22
- type: v9_1.ApplicationCommandType.ChatInput,
23
- description: current.description,
24
- name: nameSplitted[0],
25
- default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
26
- dm_permission: current.directMessages,
27
- options: localeifyOptions(current.options || [], localeData.optionsLocales),
28
- name_localizations: localeData.nameLocales(0),
29
- description_localizations: localeData.descriptionLocales,
30
- });
31
- break;
32
- }
33
- case 2: {
34
- let baseItem = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == v9_1.ApplicationCommandType.ChatInput);
35
- let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
36
- let option = {
37
- type: v9_1.ApplicationCommandOptionType.Subcommand,
38
- name: nameSplitted[1],
39
- description: current.description,
40
- dm_permission: current.directMessages,
41
- options: localeifyOptions(current.options || [], localeData.optionsLocales),
42
- name_localizations: localeData.nameLocales(1),
43
- description_localizations: localeData.descriptionLocales,
44
- };
45
- if (!baseItem) {
46
- all[current.publish].push({
47
- type: v9_1.ApplicationCommandType.ChatInput,
48
- name: nameSplitted[0],
49
- default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
50
- name_localizations: localeData.nameLocales(0),
51
- description: "...",
52
- options: [
53
- option
54
- ]
55
- });
56
- }
57
- else {
58
- baseItem.options.push(option);
59
- }
60
- break;
61
- }
62
- case 3: {
63
- let level1Item = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == v9_1.ApplicationCommandType.ChatInput);
64
- let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
65
- if (!level1Item) {
66
- all[current.publish].push({
67
- type: v9_1.ApplicationCommandType.ChatInput,
68
- name: nameSplitted[0],
69
- name_localizations: localeData.nameLocales(0),
70
- default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
71
- description: "...",
72
- options: [
73
- {
74
- type: v9_1.ApplicationCommandOptionType.SubcommandGroup,
75
- name: nameSplitted[1],
76
- name_localizations: localeData.nameLocales(1),
77
- description: "...",
78
- options: [
79
- {
80
- type: v9_1.ApplicationCommandOptionType.Subcommand,
81
- name: nameSplitted[2],
82
- description: current.description,
83
- dm_permission: current.directMessages,
84
- options: localeifyOptions(current.options || [], localeData.optionsLocales),
85
- name_localizations: localeData.nameLocales(2),
86
- description_localizations: localeData.descriptionLocales,
87
- }
88
- ]
89
- }
90
- ]
91
- });
92
- }
93
- else {
94
- let level2Item = level1Item.options.find(i => i.name == current.name.split(" ")[1]);
95
- if (!level2Item) {
96
- level1Item.options.push({
97
- type: v9_1.ApplicationCommandOptionType.SubcommandGroup,
98
- name: nameSplitted[1],
99
- name_localizations: localeData.nameLocales(1),
100
- description: "...",
101
- options: [
102
- {
103
- type: v9_1.ApplicationCommandOptionType.Subcommand,
104
- name: nameSplitted[2],
105
- description: current.description,
106
- dm_permission: current.directMessages,
107
- options: localeifyOptions(current.options || [], localeData.optionsLocales),
108
- name_localizations: localeData.nameLocales(2),
109
- description_localizations: localeData.descriptionLocales
110
- }
111
- ]
112
- });
113
- }
114
- else {
115
- level2Item.options.push({
116
- type: v9_1.ApplicationCommandOptionType.Subcommand,
117
- name: nameSplitted[2],
118
- description: current.description,
119
- dm_permission: current.directMessages,
120
- options: localeifyOptions(current.options || [], localeData.optionsLocales),
121
- name_localizations: localeData.nameLocales(2),
122
- description_localizations: localeData.descriptionLocales,
123
- });
124
- }
125
- }
126
- break;
127
- }
128
- }
129
- break;
130
- }
131
- case "MessageContextMenu": {
132
- let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
133
- all[current.publish].push({
134
- type: v9_1.ApplicationCommandType.Message,
135
- name: current.name,
136
- default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
137
- dm_permission: current.directMessages,
138
- name_localizations: localeData.allNameLocales,
139
- description_localizations: localeData.descriptionLocales,
140
- });
141
- break;
142
- }
143
- case "UserContextMenu": {
144
- let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
145
- all[current.publish].push({
146
- type: v9_1.ApplicationCommandType.User,
147
- name: current.name,
148
- default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
149
- dm_permission: current.directMessages,
150
- name_localizations: localeData.allNameLocales,
151
- description_localizations: localeData.descriptionLocales,
152
- });
153
- break;
154
- }
155
- }
156
- return all;
157
- }, {});
158
- for (let i = 0; i < clients.length; i++) {
159
- const client = clients[i];
160
- const rest = new rest_1.REST({ version: "10" });
161
- rest.setToken(client.token);
162
- const me = await rest.get(v9_1.Routes.user());
163
- switch (publishType) {
164
- case "Guild": {
165
- await rest.put(v9_1.Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] });
166
- break;
167
- }
168
- case "Global": {
169
- await rest.put(v9_1.Routes.applicationCommands(me.id), { body: body[client.namespace] });
170
- break;
171
- }
172
- }
173
- }
174
- }
175
- exports.publishInteractions = publishInteractions;
176
- function localeifyOptions(options, localeData) {
177
- return options.map(i => {
178
- let optionData = localeData[i.name];
179
- return optionData ? Object.assign(i, {
180
- name_localizations: optionData.nameLocales,
181
- description_localizations: optionData.descriptionLocales,
182
- choices: i.choices ? i.choices.map((j) => {
183
- let choiceLocale = optionData.choiceLocales[j.name];
184
- return choiceLocale ? Object.assign(j, {
185
- name_localizations: choiceLocale
186
- }) : j;
187
- }) : undefined
188
- }) : i;
189
- });
190
- }
191
- exports.localeifyOptions = localeifyOptions;
192
- function formatLocale(locale) {
193
- let allNameLocales = {};
194
- let descriptionLocales = {};
195
- let optionsLocales = {};
196
- function nameLocales(index) {
197
- return Object.fromEntries(Object.entries(allNameLocales).map(i => [i[0], i[1].split(" ").at(index)]));
198
- }
199
- if (!locale?.data)
200
- return {
201
- nameLocales,
202
- allNameLocales,
203
- descriptionLocales,
204
- optionsLocales
205
- };
206
- Object.entries(locale.data).forEach(([shortLocale, localeData]) => {
207
- let longAliases = ORIGINAL_LOCALES.filter(i => i.split("-").at(0) == shortLocale);
208
- longAliases.forEach((longLocale) => {
209
- allNameLocales[longLocale] = localeData.name;
210
- descriptionLocales[longLocale] = localeData.description;
211
- Object.entries(localeData?.options || {}).forEach(([optionName, optionData]) => {
212
- if (!optionsLocales[optionName])
213
- optionsLocales[optionName] = {};
214
- let optionLocale = optionsLocales[optionName];
215
- if (!optionLocale.nameLocales)
216
- optionLocale.nameLocales = {};
217
- if (!optionLocale.descriptionLocales)
218
- optionLocale.descriptionLocales = {};
219
- if (!optionLocale.choiceLocales)
220
- optionLocale.choiceLocales = {};
221
- Object.entries(optionData?.choices || {}).forEach(([choiceOriginalName, choiceName]) => {
222
- if (!optionLocale.choiceLocales)
223
- optionLocale.choiceLocales = {};
224
- if (!optionLocale.choiceLocales[choiceOriginalName])
225
- optionLocale.choiceLocales[choiceOriginalName] = {};
226
- let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];
227
- choiceLocale[longLocale] = choiceName;
228
- });
229
- optionLocale.nameLocales[longLocale] = optionData.name;
230
- optionLocale.descriptionLocales[longLocale] = optionData.description;
231
- });
232
- });
233
- });
234
- return {
235
- nameLocales,
236
- allNameLocales,
237
- descriptionLocales,
238
- optionsLocales
239
- };
240
- }
241
- exports.formatLocale = formatLocale;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatLocale = exports.localeifyOptions = exports.publishInteractions = void 0;
4
+ const rest_1 = require("@discordjs/rest");
5
+ const v9_1 = require("discord-api-types/v9");
6
+ const permissions_1 = require("../utils/permissions");
7
+ const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"];
8
+ 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
+ async function publishInteractions(clients, interactions, interactionsLocales, publishType, guildId) {
10
+ interactions = interactions.filter(i => PUBLISHABLE_TYPES.includes(i.type));
11
+ interactions = interactions.sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
12
+ let body = interactions.reduce((all, current) => {
13
+ if (current.publish && !all[current.publish])
14
+ all[current.publish] = [];
15
+ switch (current.type) {
16
+ case "ChatInput": {
17
+ let nameSplitted = current.name.split(" ");
18
+ let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
19
+ switch (nameSplitted.length) {
20
+ case 1: {
21
+ all[current.publish].push({
22
+ type: v9_1.ApplicationCommandType.ChatInput,
23
+ description: current.description,
24
+ name: nameSplitted[0],
25
+ default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
26
+ dm_permission: current.directMessages,
27
+ options: localeifyOptions(current.options || [], localeData.optionsLocales),
28
+ name_localizations: localeData.nameLocales(0),
29
+ description_localizations: localeData.descriptionLocales,
30
+ });
31
+ break;
32
+ }
33
+ case 2: {
34
+ let baseItem = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == v9_1.ApplicationCommandType.ChatInput);
35
+ let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
36
+ let option = {
37
+ type: v9_1.ApplicationCommandOptionType.Subcommand,
38
+ name: nameSplitted[1],
39
+ description: current.description,
40
+ dm_permission: current.directMessages,
41
+ options: localeifyOptions(current.options || [], localeData.optionsLocales),
42
+ name_localizations: localeData.nameLocales(1),
43
+ description_localizations: localeData.descriptionLocales,
44
+ };
45
+ if (!baseItem) {
46
+ all[current.publish].push({
47
+ type: v9_1.ApplicationCommandType.ChatInput,
48
+ name: nameSplitted[0],
49
+ default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
50
+ name_localizations: localeData.nameLocales(0),
51
+ description: "...",
52
+ options: [
53
+ option
54
+ ]
55
+ });
56
+ }
57
+ else {
58
+ baseItem.options.push(option);
59
+ }
60
+ break;
61
+ }
62
+ case 3: {
63
+ let level1Item = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == v9_1.ApplicationCommandType.ChatInput);
64
+ let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
65
+ if (!level1Item) {
66
+ all[current.publish].push({
67
+ type: v9_1.ApplicationCommandType.ChatInput,
68
+ name: nameSplitted[0],
69
+ name_localizations: localeData.nameLocales(0),
70
+ default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
71
+ description: "...",
72
+ options: [
73
+ {
74
+ type: v9_1.ApplicationCommandOptionType.SubcommandGroup,
75
+ name: nameSplitted[1],
76
+ name_localizations: localeData.nameLocales(1),
77
+ description: "...",
78
+ options: [
79
+ {
80
+ type: v9_1.ApplicationCommandOptionType.Subcommand,
81
+ name: nameSplitted[2],
82
+ description: current.description,
83
+ dm_permission: current.directMessages,
84
+ options: localeifyOptions(current.options || [], localeData.optionsLocales),
85
+ name_localizations: localeData.nameLocales(2),
86
+ description_localizations: localeData.descriptionLocales,
87
+ }
88
+ ]
89
+ }
90
+ ]
91
+ });
92
+ }
93
+ else {
94
+ let level2Item = level1Item.options.find(i => i.name == current.name.split(" ")[1]);
95
+ if (!level2Item) {
96
+ level1Item.options.push({
97
+ type: v9_1.ApplicationCommandOptionType.SubcommandGroup,
98
+ name: nameSplitted[1],
99
+ name_localizations: localeData.nameLocales(1),
100
+ description: "...",
101
+ options: [
102
+ {
103
+ type: v9_1.ApplicationCommandOptionType.Subcommand,
104
+ name: nameSplitted[2],
105
+ description: current.description,
106
+ dm_permission: current.directMessages,
107
+ options: localeifyOptions(current.options || [], localeData.optionsLocales),
108
+ name_localizations: localeData.nameLocales(2),
109
+ description_localizations: localeData.descriptionLocales
110
+ }
111
+ ]
112
+ });
113
+ }
114
+ else {
115
+ level2Item.options.push({
116
+ type: v9_1.ApplicationCommandOptionType.Subcommand,
117
+ name: nameSplitted[2],
118
+ description: current.description,
119
+ dm_permission: current.directMessages,
120
+ options: localeifyOptions(current.options || [], localeData.optionsLocales),
121
+ name_localizations: localeData.nameLocales(2),
122
+ description_localizations: localeData.descriptionLocales,
123
+ });
124
+ }
125
+ }
126
+ break;
127
+ }
128
+ }
129
+ break;
130
+ }
131
+ case "MessageContextMenu": {
132
+ let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
133
+ all[current.publish].push({
134
+ type: v9_1.ApplicationCommandType.Message,
135
+ name: current.name,
136
+ default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
137
+ dm_permission: current.directMessages,
138
+ name_localizations: localeData.allNameLocales,
139
+ description_localizations: localeData.descriptionLocales,
140
+ });
141
+ break;
142
+ }
143
+ case "UserContextMenu": {
144
+ let localeData = formatLocale(interactionsLocales.get(current.name) ?? {});
145
+ all[current.publish].push({
146
+ type: v9_1.ApplicationCommandType.User,
147
+ name: current.name,
148
+ default_member_permissions: (0, permissions_1.reducePermissions)(current.defaultMemberPermissions).toString(),
149
+ dm_permission: current.directMessages,
150
+ name_localizations: localeData.allNameLocales,
151
+ description_localizations: localeData.descriptionLocales,
152
+ });
153
+ break;
154
+ }
155
+ }
156
+ return all;
157
+ }, {});
158
+ for (let i = 0; i < clients.length; i++) {
159
+ const client = clients[i];
160
+ const rest = new rest_1.REST({ version: "10" });
161
+ rest.setToken(client.token);
162
+ const me = await rest.get(v9_1.Routes.user());
163
+ switch (publishType) {
164
+ case "Guild": {
165
+ await rest.put(v9_1.Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] || [] });
166
+ break;
167
+ }
168
+ case "Global": {
169
+ await rest.put(v9_1.Routes.applicationCommands(me.id), { body: body[client.namespace] || [] });
170
+ break;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ exports.publishInteractions = publishInteractions;
176
+ function localeifyOptions(options, localeData) {
177
+ return options.map(i => {
178
+ let optionData = localeData[i.name];
179
+ return optionData ? Object.assign(i, {
180
+ name_localizations: optionData.nameLocales,
181
+ description_localizations: optionData.descriptionLocales,
182
+ choices: i.choices ? i.choices.map((j) => {
183
+ let choiceLocale = optionData.choiceLocales[j.name];
184
+ return choiceLocale ? Object.assign(j, {
185
+ name_localizations: choiceLocale
186
+ }) : j;
187
+ }) : undefined
188
+ }) : i;
189
+ });
190
+ }
191
+ exports.localeifyOptions = localeifyOptions;
192
+ function formatLocale(locale) {
193
+ let allNameLocales = {};
194
+ let descriptionLocales = {};
195
+ let optionsLocales = {};
196
+ function nameLocales(index) {
197
+ return Object.fromEntries(Object.entries(allNameLocales).map(i => [i[0], i[1].split(" ").at(index)]));
198
+ }
199
+ if (!locale?.data)
200
+ return {
201
+ nameLocales,
202
+ allNameLocales,
203
+ descriptionLocales,
204
+ optionsLocales
205
+ };
206
+ Object.entries(locale.data).forEach(([shortLocale, localeData]) => {
207
+ let longAliases = ORIGINAL_LOCALES.filter(i => i.split("-").at(0) == shortLocale);
208
+ longAliases.forEach((longLocale) => {
209
+ allNameLocales[longLocale] = localeData.name;
210
+ descriptionLocales[longLocale] = localeData.description;
211
+ Object.entries(localeData?.options || {}).forEach(([optionName, optionData]) => {
212
+ if (!optionsLocales[optionName])
213
+ optionsLocales[optionName] = {};
214
+ let optionLocale = optionsLocales[optionName];
215
+ if (!optionLocale.nameLocales)
216
+ optionLocale.nameLocales = {};
217
+ if (!optionLocale.descriptionLocales)
218
+ optionLocale.descriptionLocales = {};
219
+ if (!optionLocale.choiceLocales)
220
+ optionLocale.choiceLocales = {};
221
+ Object.entries(optionData?.choices || {}).forEach(([choiceOriginalName, choiceName]) => {
222
+ if (!optionLocale.choiceLocales)
223
+ optionLocale.choiceLocales = {};
224
+ if (!optionLocale.choiceLocales[choiceOriginalName])
225
+ optionLocale.choiceLocales[choiceOriginalName] = {};
226
+ let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];
227
+ choiceLocale[longLocale] = choiceName;
228
+ });
229
+ optionLocale.nameLocales[longLocale] = optionData.name;
230
+ optionLocale.descriptionLocales[longLocale] = optionData.description;
231
+ });
232
+ });
233
+ });
234
+ return {
235
+ nameLocales,
236
+ allNameLocales,
237
+ descriptionLocales,
238
+ optionsLocales
239
+ };
240
+ }
241
+ exports.formatLocale = formatLocale;
242
242
  //# sourceMappingURL=publishInteractions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"publishInteractions.js","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":";;;AAEA,0CAAuC;AACvC,6CAAiK;AACjK,sDAAyD;AAMzD,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,EA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AG,EAAE,CAAC;gBACjE,IAAI,YAAY,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;gBAC9C,IAAI,CAAC,YAAY,CAAC,WAAW;oBAAE,YAAY,CAAC,WAAW,GAAG,EAAE,CAAC;gBAC7D,IAAI,CAAC,YAAY,CAAC,kBAAkB;oBAAE,YAAY,CAAC,kBAAkB,GAAG,EAAE,CAAC;gBAC3E,IAAI,CAAC,YAAY,CAAC,aAAa;oBAAE,YAAY,CAAC,aAAa,GAAG,EAAE,CAAC;gBAEjE,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,EAAE;oBACrF,IAAI,CAAC,YAAY,CAAC,aAAa;wBAAE,YAAY,CAAC,aAAa,GAAG,EAAE,CAAC;oBACjE,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC;wBAAE,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;oBACzG,IAAI,YAAY,GAAG,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;oBAElE,YAAY,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;gBACxC,CAAC,CAAC,CAAC;gBAEH,YAAY,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;gBACvD,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;YACvE,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;AAhDD,oCAgDC","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, DBIClientData } from \"../DBI\";\r\nimport { DBIInteractionLocale } from \"../types/InteractionLocale\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\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 clients: DBIClientData<NamespaceEnums>[],\r\n interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>,\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 interactions = interactions.sort((a, b) => b.name.split(\" \").length - a.name.split(\" \").length);\r\n\r\n let body: {[k: string]: RESTPutAPIApplicationCommandsJSONBody} =\r\n interactions.reduce((all, current) => {\r\n if (current.publish && !all[current.publish]) all[current.publish] = [];\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[current.publish].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[current.publish].find(i => i.name == current.name.split(\" \")[0] && i.type == ApplicationCommandType.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 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[current.publish].push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\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[current.publish].find(i => i.name == current.name.split(\" \")[0] && i.type == ApplicationCommandType.ChatInput);\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n if (!level1Item) {\r\n all[current.publish].push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n name_localizations: localeData.nameLocales(0),\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\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 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]);\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 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 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[current.publish].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[current.publish].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 }, {} as {[k: string]: any});\r\n \r\n\r\n for (let i = 0; i < clients.length; i++) {\r\n const client = clients[i];\r\n const rest = new REST({ version: \"10\" });\r\n rest.setToken(client.token);\r\n \r\n const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;\r\n \r\n switch (publishType) {\r\n case \"Guild\": {\r\n await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] });\r\n break;\r\n }\r\n case \"Global\": {\r\n await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] });\r\n break;\r\n }\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 let optionData = localeData[i.name];\r\n return optionData ? Object.assign(i, {\r\n name_localizations: optionData.nameLocales,\r\n description_localizations: optionData.descriptionLocales,\r\n choices: i.choices ? i.choices.map((j) => {\r\n let choiceLocale = optionData.choiceLocales[j.name];\r\n return choiceLocale ? Object.assign(j, {\r\n name_localizations: choiceLocale\r\n }) : j;\r\n }) : undefined\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 let optionLocale = optionsLocales[optionName];\r\n if (!optionLocale.nameLocales) optionLocale.nameLocales = {};\r\n if (!optionLocale.descriptionLocales) optionLocale.descriptionLocales = {};\r\n if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};\r\n\r\n Object.entries(optionData?.choices || {}).forEach(([choiceOriginalName, choiceName]) => {\r\n if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};\r\n if (!optionLocale.choiceLocales[choiceOriginalName]) optionLocale.choiceLocales[choiceOriginalName] = {};\r\n let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];\r\n \r\n choiceLocale[longLocale] = choiceName;\r\n });\r\n\r\n optionLocale.nameLocales[longLocale] = optionData.name;\r\n optionLocale.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}"]}
1
+ {"version":3,"file":"publishInteractions.js","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":";;;AAEA,0CAAuC;AACvC,6CAAiK;AACjK,sDAAyD;AAMzD,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,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAE5N,KAAK,UAAU,mBAAmB,CACvC,OAAwC,EACxC,YAAsE,EACtE,mBAAqE,EACrE,WAA+B,EAC/B,OAAgB;IAEhB,YAAY,GAAG,YAAY,CAAC,MAAM,CA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AAC,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,EAAE;oBACrF,IAAI,CAAC,YAAY,CAAC,aAAa;wBAAE,YAAY,CAAC,aAAa,GAAG,EAAE,CAAC;oBACjE,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC;wBAAE,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;oBACzG,IAAI,YAAY,GAAG,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;oBAElE,YAAY,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;gBACxC,CAAC,CAAC,CAAC;gBAEH,YAAY,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;gBACvD,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;YACvE,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;AAhDD,oCAgDC","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, DBIClientData } from \"../DBI\";\r\nimport { DBIInteractionLocale } from \"../types/InteractionLocale\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\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 clients: DBIClientData<NamespaceEnums>[],\r\n interactions: Discord.Collection<string, DBIChatInput<NamespaceEnums>>,\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 interactions = interactions.sort((a, b) => b.name.split(\" \").length - a.name.split(\" \").length);\r\n\r\n let body: {[k: string]: RESTPutAPIApplicationCommandsJSONBody} =\r\n interactions.reduce((all, current) => {\r\n if (current.publish && !all[current.publish]) all[current.publish] = [];\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[current.publish].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[current.publish].find(i => i.name == current.name.split(\" \")[0] && i.type == ApplicationCommandType.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 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[current.publish].push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\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[current.publish].find(i => i.name == current.name.split(\" \")[0] && i.type == ApplicationCommandType.ChatInput);\r\n let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);\r\n if (!level1Item) {\r\n all[current.publish].push({\r\n type: ApplicationCommandType.ChatInput,\r\n name: nameSplitted[0],\r\n name_localizations: localeData.nameLocales(0),\r\n default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),\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 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]);\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 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 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[current.publish].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[current.publish].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 }, {} as {[k: string]: any});\r\n \r\n\r\n for (let i = 0; i < clients.length; i++) {\r\n const client = clients[i];\r\n const rest = new REST({ version: \"10\" });\r\n rest.setToken(client.token);\r\n \r\n const me: RESTGetAPIUserResult = await rest.get(Routes.user()) as any;\r\n \r\n switch (publishType) {\r\n case \"Guild\": {\r\n await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] || [] });\r\n break;\r\n }\r\n case \"Global\": {\r\n await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] || [] });\r\n break;\r\n }\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 let optionData = localeData[i.name];\r\n return optionData ? Object.assign(i, {\r\n name_localizations: optionData.nameLocales,\r\n description_localizations: optionData.descriptionLocales,\r\n choices: i.choices ? i.choices.map((j) => {\r\n let choiceLocale = optionData.choiceLocales[j.name];\r\n return choiceLocale ? Object.assign(j, {\r\n name_localizations: choiceLocale\r\n }) : j;\r\n }) : undefined\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 let optionLocale = optionsLocales[optionName];\r\n if (!optionLocale.nameLocales) optionLocale.nameLocales = {};\r\n if (!optionLocale.descriptionLocales) optionLocale.descriptionLocales = {};\r\n if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};\r\n\r\n Object.entries(optionData?.choices || {}).forEach(([choiceOriginalName, choiceName]) => {\r\n if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};\r\n if (!optionLocale.choiceLocales[choiceOriginalName]) optionLocale.choiceLocales[choiceOriginalName] = {};\r\n let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];\r\n \r\n choiceLocale[longLocale] = choiceName;\r\n });\r\n\r\n optionLocale.nameLocales[longLocale] = optionData.name;\r\n optionLocale.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}"]}
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DBICustomEvent = void 0;
4
- class DBICustomEvent {
5
- dbi;
6
- name;
7
- map;
8
- type;
9
- trigger(args) {
10
- return this.dbi.data.clients.first().client.emit(this.name, { ...args, _DIRECT_: true });
11
- }
12
- constructor(dbi, cfg) {
13
- this.dbi = dbi;
14
- this.name = cfg.name;
15
- this.map = cfg.map;
16
- this.type = "CustomEvent";
17
- }
18
- }
19
- exports.DBICustomEvent = DBICustomEvent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DBICustomEvent = void 0;
4
+ class DBICustomEvent {
5
+ dbi;
6
+ name;
7
+ map;
8
+ type;
9
+ trigger(args) {
10
+ return this.dbi.data.clients.first().client.emit(this.name, { ...args, _DIRECT_: true });
11
+ }
12
+ constructor(dbi, cfg) {
13
+ this.dbi = dbi;
14
+ this.name = cfg.name;
15
+ this.map = cfg.map;
16
+ this.type = "CustomEvent";
17
+ }
18
+ }
19
+ exports.DBICustomEvent = DBICustomEvent;
20
20
  //# sourceMappingURL=CustomEvent.js.map