@mostfeatured/dbi 0.0.27 → 0.0.30
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/.gitattributes +2 -2
- package/dist/DBI.d.ts +35 -5
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +45 -16
- package/dist/DBI.js.map +1 -1
- package/dist/methods/publishInteractions.d.ts.map +1 -1
- package/dist/methods/publishInteractions.js +27 -12
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/Button.d.ts +1 -0
- package/dist/types/Button.d.ts.map +1 -1
- package/dist/types/Button.js +2 -1
- package/dist/types/Button.js.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts +6 -0
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js +8 -0
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/dist/types/InteractionLocale.d.ts +3 -0
- package/dist/types/InteractionLocale.d.ts.map +1 -1
- package/dist/types/InteractionLocale.js.map +1 -1
- package/dist/types/Locale.d.ts +7 -7
- package/dist/types/Locale.d.ts.map +1 -1
- package/dist/types/Locale.js.map +1 -1
- package/dist/types/Modal.d.ts +2 -1
- package/dist/types/Modal.d.ts.map +1 -1
- package/dist/types/Modal.js +4 -3
- package/dist/types/Modal.js.map +1 -1
- package/dist/types/SelectMenu.d.ts +2 -1
- package/dist/types/SelectMenu.d.ts.map +1 -1
- package/dist/types/SelectMenu.js +2 -1
- package/dist/types/SelectMenu.js.map +1 -1
- package/dist/utils/customId.d.ts +1 -1
- package/dist/utils/customId.d.ts.map +1 -1
- package/dist/utils/customId.js +2 -2
- package/dist/utils/customId.js.map +1 -1
- package/package.json +40 -40
- package/src/DBI.ts +74 -25
- package/src/methods/publishInteractions.ts +24 -9
- package/src/types/Button.ts +3 -2
- package/src/types/ChatInput/ChatInputOptions.ts +9 -0
- package/src/types/InteractionLocale.ts +3 -0
- package/src/types/Locale.ts +9 -9
- package/src/types/Modal.ts +7 -4
- package/src/types/SelectMenu.ts +5 -2
- package/src/utils/customId.ts +2 -2
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
package/dist/DBI.d.ts
CHANGED
|
@@ -27,12 +27,18 @@ export interface DBIConfig {
|
|
|
27
27
|
directMessages: boolean;
|
|
28
28
|
defaultMemberPermissions: Discord.PermissionsString[];
|
|
29
29
|
};
|
|
30
|
-
sharding:
|
|
30
|
+
sharding: "hybrid" | "default" | "off";
|
|
31
31
|
/**
|
|
32
32
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
33
33
|
*/
|
|
34
34
|
store: DBIStore;
|
|
35
|
-
|
|
35
|
+
references: {
|
|
36
|
+
autoClear?: {
|
|
37
|
+
check: number;
|
|
38
|
+
ttl: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
strict: boolean;
|
|
36
42
|
}
|
|
37
43
|
export interface DBIConfigConstructor {
|
|
38
44
|
discord: {
|
|
@@ -44,12 +50,18 @@ export interface DBIConfigConstructor {
|
|
|
44
50
|
directMessages?: boolean;
|
|
45
51
|
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
46
52
|
};
|
|
47
|
-
sharding?:
|
|
53
|
+
sharding?: "hybrid" | "default" | "off";
|
|
48
54
|
/**
|
|
49
55
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
50
56
|
*/
|
|
51
57
|
store?: DBIStore;
|
|
52
|
-
|
|
58
|
+
references?: {
|
|
59
|
+
autoClear?: {
|
|
60
|
+
check: number;
|
|
61
|
+
ttl: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
strict?: boolean;
|
|
53
65
|
}
|
|
54
66
|
export interface DBIRegisterAPI {
|
|
55
67
|
ChatInput(cfg: TDBIChatInputOmitted): DBIChatInput;
|
|
@@ -64,12 +76,13 @@ export interface DBIRegisterAPI {
|
|
|
64
76
|
Modal(cfg: TDBIModalOmitted): DBIModal;
|
|
65
77
|
onUnload(cb: () => Promise<any> | any): any;
|
|
66
78
|
}
|
|
79
|
+
export declare type TDBIInteractions = DBIChatInput | DBIButton | DBISelectMenu | DBIMessageContextMenu | DBIUserContextMenu | DBIModal;
|
|
67
80
|
export declare class DBI<TOtherData = Record<string, any>> {
|
|
68
81
|
namespace: string;
|
|
69
82
|
config: DBIConfig;
|
|
70
83
|
client: Discord.Client<true>;
|
|
71
84
|
data: {
|
|
72
|
-
interactions: Discord.Collection<string,
|
|
85
|
+
interactions: Discord.Collection<string, TDBIInteractions>;
|
|
73
86
|
events: Discord.Collection<string, DBIEvent>;
|
|
74
87
|
plugins: Discord.Collection<string, any>;
|
|
75
88
|
locales: Discord.Collection<string, DBILocale>;
|
|
@@ -82,6 +95,7 @@ export declare class DBI<TOtherData = Record<string, any>> {
|
|
|
82
95
|
refs: Map<string, {
|
|
83
96
|
at: number;
|
|
84
97
|
value: any;
|
|
98
|
+
ttl?: number;
|
|
85
99
|
}>;
|
|
86
100
|
};
|
|
87
101
|
events: Events;
|
|
@@ -93,6 +107,22 @@ export declare class DBI<TOtherData = Record<string, any>> {
|
|
|
93
107
|
private _unhookListeners;
|
|
94
108
|
private _unregisterAll;
|
|
95
109
|
private _registerAll;
|
|
110
|
+
/**
|
|
111
|
+
* this.data.interactions.get(name)
|
|
112
|
+
*/
|
|
113
|
+
interaction(name: string): TDBIInteractions;
|
|
114
|
+
/**
|
|
115
|
+
* this.data.events.get(name)
|
|
116
|
+
*/
|
|
117
|
+
event(name: string): DBIEvent;
|
|
118
|
+
/**
|
|
119
|
+
* this.data.locales.get(name)
|
|
120
|
+
*/
|
|
121
|
+
locale(name: string): DBILocale;
|
|
122
|
+
/**
|
|
123
|
+
* this.data.plugins.get(name)
|
|
124
|
+
*/
|
|
125
|
+
plugin(name: string): any;
|
|
96
126
|
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
41
41
|
};
|
|
42
|
-
config.sharding = config.sharding ??
|
|
42
|
+
config.sharding = config.sharding ?? "off";
|
|
43
|
+
config.strict = config.strict ?? true;
|
|
44
|
+
config.references = {
|
|
45
|
+
autoClear: undefined,
|
|
46
|
+
...(config.references || {})
|
|
47
|
+
};
|
|
43
48
|
// @ts-ignore
|
|
44
49
|
this.config = config;
|
|
45
50
|
this.data = {
|
|
@@ -58,12 +63,12 @@ class DBI {
|
|
|
58
63
|
this.events = new Events_1.Events(this);
|
|
59
64
|
this.client = new discord_js_1.default.Client({
|
|
60
65
|
...(config.discord?.options || {}),
|
|
61
|
-
...(config.sharding ? {
|
|
66
|
+
...(config.sharding == "hybrid" ? {
|
|
62
67
|
shards: Sharding.data.SHARD_LIST,
|
|
63
68
|
shardCount: Sharding.data.TOTAL_SHARDS
|
|
64
69
|
} : {})
|
|
65
70
|
});
|
|
66
|
-
this.cluster = config.sharding ? new Sharding.Client(this.client) : undefined;
|
|
71
|
+
this.cluster = config.sharding == "hybrid" ? new Sharding.Client(this.client) : undefined;
|
|
67
72
|
this._loaded = false;
|
|
68
73
|
this._hooked = false;
|
|
69
74
|
}
|
|
@@ -73,15 +78,15 @@ class DBI {
|
|
|
73
78
|
this._hooked = true;
|
|
74
79
|
this.data.unloaders.add((0, hookInteractionListeners_1.hookInteractionListeners)(this));
|
|
75
80
|
this.data.unloaders.add((0, hookEventListeners_1.hookEventListeners)(this));
|
|
76
|
-
if (typeof this.config.
|
|
81
|
+
if (typeof this.config.references.autoClear != "undefined") {
|
|
77
82
|
this.data.unloaders.add((() => {
|
|
78
83
|
let interval = setInterval(() => {
|
|
79
|
-
this.data.refs.forEach(({ at }, key) => {
|
|
80
|
-
if (Date.now() > (at + this.config.
|
|
84
|
+
this.data.refs.forEach(({ at, ttl }, key) => {
|
|
85
|
+
if (Date.now() > (at + (ttl || this.config.references.autoClear.ttl))) {
|
|
81
86
|
this.data.refs.delete(key);
|
|
82
87
|
}
|
|
83
88
|
});
|
|
84
|
-
},
|
|
89
|
+
}, this.config.references.autoClear.check);
|
|
85
90
|
return () => {
|
|
86
91
|
clearInterval(interval);
|
|
87
92
|
};
|
|
@@ -119,7 +124,7 @@ class DBI {
|
|
|
119
124
|
});
|
|
120
125
|
let Event = function (cfg) {
|
|
121
126
|
let dbiEvent = new Event_1.DBIEvent(self, cfg);
|
|
122
|
-
if (self.data.events.has(dbiEvent.id || dbiEvent.name))
|
|
127
|
+
if (self.config.strict && self.data.events.has(dbiEvent.id || dbiEvent.name))
|
|
123
128
|
throw new Error(`DBIEvent "${dbiEvent.id || dbiEvent.name}" already loaded!`);
|
|
124
129
|
self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);
|
|
125
130
|
return dbiEvent;
|
|
@@ -129,7 +134,7 @@ class DBI {
|
|
|
129
134
|
});
|
|
130
135
|
let Button = function (cfg) {
|
|
131
136
|
let dbiButton = new Button_1.DBIButton(self, cfg);
|
|
132
|
-
if (self.data.interactions.has(dbiButton.name))
|
|
137
|
+
if (self.config.strict && self.data.interactions.has(dbiButton.name))
|
|
133
138
|
throw new Error(`DBIButton "${dbiButton.name}" already loaded as "${self.data.interactions.get(dbiButton.name)?.type}"!`);
|
|
134
139
|
self.data.interactions.set(dbiButton.name, dbiButton);
|
|
135
140
|
return dbiButton;
|
|
@@ -139,7 +144,7 @@ class DBI {
|
|
|
139
144
|
});
|
|
140
145
|
let SelectMenu = function (cfg) {
|
|
141
146
|
let dbiSelectMenu = new SelectMenu_1.DBISelectMenu(self, cfg);
|
|
142
|
-
if (self.data.interactions.has(dbiSelectMenu.name))
|
|
147
|
+
if (self.config.strict && self.data.interactions.has(dbiSelectMenu.name))
|
|
143
148
|
throw new Error(`DBISelectMenu "${dbiSelectMenu.name}" already loaded as "${self.data.interactions.get(dbiSelectMenu.name)?.type}"!`);
|
|
144
149
|
self.data.interactions.set(dbiSelectMenu.name, dbiSelectMenu);
|
|
145
150
|
return dbiSelectMenu;
|
|
@@ -149,7 +154,7 @@ class DBI {
|
|
|
149
154
|
});
|
|
150
155
|
let MessageContextMenu = function (cfg) {
|
|
151
156
|
let dbiMessageContextMenu = new MessageContextMenu_1.DBIMessageContextMenu(self, cfg);
|
|
152
|
-
if (self.data.interactions.has(dbiMessageContextMenu.name))
|
|
157
|
+
if (self.config.strict && self.data.interactions.has(dbiMessageContextMenu.name))
|
|
153
158
|
throw new Error(`DBIMessageContextMenu "${dbiMessageContextMenu.name}" already loaded as "${self.data.interactions.get(dbiMessageContextMenu.name)?.type}"!`);
|
|
154
159
|
self.data.interactions.set(dbiMessageContextMenu.name, dbiMessageContextMenu);
|
|
155
160
|
return dbiMessageContextMenu;
|
|
@@ -159,7 +164,7 @@ class DBI {
|
|
|
159
164
|
});
|
|
160
165
|
let UserContextMenu = function (cfg) {
|
|
161
166
|
let dbiUserContextMenu = new UserContextMenu_1.DBIUserContextMenu(self, cfg);
|
|
162
|
-
if (self.data.interactions.has(dbiUserContextMenu.name))
|
|
167
|
+
if (self.config.strict && self.data.interactions.has(dbiUserContextMenu.name))
|
|
163
168
|
throw new Error(`DBIUserContextMenu "${dbiUserContextMenu.name}" already loaded as "${self.data.interactions.get(dbiUserContextMenu.name)?.type}"!`);
|
|
164
169
|
self.data.interactions.set(dbiUserContextMenu.name, dbiUserContextMenu);
|
|
165
170
|
return dbiUserContextMenu;
|
|
@@ -169,7 +174,7 @@ class DBI {
|
|
|
169
174
|
});
|
|
170
175
|
let Modal = function (cfg) {
|
|
171
176
|
let dbiModal = new Modal_1.DBIModal(self, cfg);
|
|
172
|
-
if (self.data.interactions.has(dbiModal.name))
|
|
177
|
+
if (self.config.strict && self.data.interactions.has(dbiModal.name))
|
|
173
178
|
throw new Error(`DBIModal "${dbiModal.name}" already loaded as "${self.data.interactions.get(dbiModal.name)?.type}"!`);
|
|
174
179
|
self.data.interactions.set(dbiModal.name, dbiModal);
|
|
175
180
|
return dbiModal;
|
|
@@ -179,7 +184,7 @@ class DBI {
|
|
|
179
184
|
});
|
|
180
185
|
let Locale = function (cfg) {
|
|
181
186
|
let dbiLocale = new Locale_1.DBILocale(self, cfg);
|
|
182
|
-
if (self.data.locales.has(dbiLocale.name))
|
|
187
|
+
if (self.config.strict && self.data.locales.has(dbiLocale.name))
|
|
183
188
|
throw new Error(`DBILocale "${dbiLocale.name}" already loaded!`);
|
|
184
189
|
self.data.locales.set(dbiLocale.name, dbiLocale);
|
|
185
190
|
return dbiLocale;
|
|
@@ -189,7 +194,7 @@ class DBI {
|
|
|
189
194
|
});
|
|
190
195
|
let InteractionLocale = function (cfg) {
|
|
191
196
|
let dbiInteractionLocale = new InteractionLocale_1.DBIInteractionLocale(self, cfg);
|
|
192
|
-
if (self.data.interactionLocales.has(dbiInteractionLocale.name))
|
|
197
|
+
if (self.config.strict && self.data.interactionLocales.has(dbiInteractionLocale.name))
|
|
193
198
|
throw new Error(`DBIInteractionLocale "${dbiInteractionLocale.name}" already loaded!`);
|
|
194
199
|
self.data.interactionLocales.set(dbiInteractionLocale.name, dbiInteractionLocale);
|
|
195
200
|
return dbiInteractionLocale;
|
|
@@ -214,6 +219,30 @@ class DBI {
|
|
|
214
219
|
});
|
|
215
220
|
}
|
|
216
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* this.data.interactions.get(name)
|
|
224
|
+
*/
|
|
225
|
+
interaction(name) {
|
|
226
|
+
return this.data.interactions.get(name);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* this.data.events.get(name)
|
|
230
|
+
*/
|
|
231
|
+
event(name) {
|
|
232
|
+
return this.data.events.get(name);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* this.data.locales.get(name)
|
|
236
|
+
*/
|
|
237
|
+
locale(name) {
|
|
238
|
+
return this.data.locales.get(name);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* this.data.plugins.get(name)
|
|
242
|
+
*/
|
|
243
|
+
plugin(name) {
|
|
244
|
+
return this.data.plugins.get(name);
|
|
245
|
+
}
|
|
217
246
|
/**
|
|
218
247
|
* Shorthands for modifying `dbi.data.other`
|
|
219
248
|
*/
|
|
@@ -243,7 +272,7 @@ class DBI {
|
|
|
243
272
|
return lodash_1.default.unset(this.data.other, k);
|
|
244
273
|
}
|
|
245
274
|
async login() {
|
|
246
|
-
await this.client.login(this.config.discord.token);
|
|
275
|
+
await this.client.login(this.config.sharding == "default" ? undefined : this.config.discord.token);
|
|
247
276
|
}
|
|
248
277
|
async register(cb) {
|
|
249
278
|
this.data.registers.add(cb);
|
package/dist/DBI.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBI.js","sourceRoot":"","sources":["../src/DBI.ts"],"names":[],"mappings":";;;;AAAA,oEAAiC;AACjC,2DAAiF;AACjF,yEAAyE;AACzE,uEAAoE;AACpE,yCAA2D;AAC3D,qDAAkD;AAClD,iFAA8E;AAC9E,qCAAkC;AAClC,2CAAoF;AACpF,2CAA8D;AAC9D,mDAA0E;AAC1E,mEAAkG;AAClG,6DAAyF;AACzF,qEAAkE;AAClE,iFAA4C;AAC5C,yCAA2D;AAC3D,0EAAoD;AACpD,4DAAuB;AACvB,iEAA+F;AA+D/F,MAAa,GAAG;IACd,SAAS,CAAS;IAClB,MAAM,CAAY;IAClB,MAAM,CAAuB;IAC7B,IAAI,CAYF;IACF,MAAM,CAAS;IACf,OAAO,CAAmB;IAClB,OAAO,CAAU;IACjB,OAAO,CAAU;IACzB,YAAY,SAAiB,EAAE,MAA4B;QACzD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAY,IAAI,IAAI,yBAAW,EAAE,CAAC;QACxD,MAAM,CAAC,QAAQ,GAAG;YAChB,MAAM,EAAE,IAAI;YACZ,wBAAwB,EAAE,EAAE;YAC5B,cAAc,EAAE,KAAK;YACrB,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;SAC3B,CAAC;QACF,MAAM,CAAC,QAAQ,GAAG,MA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AW,IAAI,CAAC,CAAC,IAAI,IAAI,oBAAoB,IAAI,CAAC,CAAC,IAAI,IAAI,iBAAiB,CAAQ,CAAC;QACrJ,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE;YACf,KAAK,QAAQ,CAAC,CAAC;gBACb,OAAO,MAAM,IAAA,yCAAmB,EAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EACzB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,YAAY,EACjD,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAC5B,IAAI,CAAC,CAAC,CAAC,CACR,CAAC;aACH;YACD,KAAK,OAAO,CAAC,CAAC;gBACZ,OAAO,MAAM,IAAA,yCAAmB,EAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EACzB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,YAAY,EACjD,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAC5B,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,CACR,CAAC;aACH;SACF;IACH,CAAC;CAGF;AA1RD,kBA0RC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { DBIChatInput, TDBIChatInputOmitted } from \"./types/ChatInput/ChatInput\";\r\nimport { DBIChatInputOptions } from \"./types/ChatInput/ChatInputOptions\";\r\nimport { publishInteractions } from \"./methods/publishInteractions\";\r\nimport { DBIEvent, TDBIEventOmitted } from \"./types/Event\";\r\nimport { MemoryStore } from \"./utils/MemoryStore\";\r\nimport { hookInteractionListeners } from \"./methods/hookInteractionListeners\";\r\nimport { Events } from \"./Events\";\r\nimport { DBILocale, TDBILocaleConstructor, TDBILocaleString } from \"./types/Locale\";\r\nimport { DBIButton, TDBIButtonOmitted } from \"./types/Button\";\r\nimport { DBISelectMenu, TDBISelectMenuOmitted } from \"./types/SelectMenu\";\r\nimport { DBIMessageContextMenu, TDBIMessageContextMenuOmitted } from \"./types/MessageContextMenu\";\r\nimport { DBIUserContextMenu, TDBIUserContextMenuOmitted } from \"./types/UserContextMenu\";\r\nimport { hookEventListeners } from \"./methods/hookEventListeners\";\r\nimport eventMap from \"./data/eventMap.json\";\r\nimport { DBIModal, TDBIModalOmitted } from \"./types/Modal\";\r\nimport * as Sharding from \"discord-hybrid-sharding\";\r\nimport _ from \"lodash\";\r\nimport { DBIInteractionLocale, TDBIInteractionLocaleOmitted } from \"./types/InteractionLocale\";\r\n\r\nexport interface DBIStore {\r\n get(key: string, defaultValue?: any): Promise<any>;\r\n set(key: string, value: any): Promise<void>;\r\n delete(key: string): Promise<void>;\r\n has(key: string): Promise<boolean>;\r\n}\r\n\r\nexport interface DBIConfig {\r\n discord: {\r\n token: string;\r\n options: Discord.ClientOptions\r\n }\r\n defaults: {\r\n locale: TDBILocaleString,\r\n directMessages: boolean,\r\n defaultMemberPermissions: Discord.PermissionsString[]\r\n };\r\n\r\n sharding: boolean;\r\n /**\r\n * Persist store. (Default to MemoryStore thats not persis tho.)\r\n */\r\n store: DBIStore;\r\n\r\n clearRefsAfter?: number;\r\n}\r\n\r\nexport interface DBIConfigConstructor {\r\n discord: {\r\n token: string;\r\n options: Discord.ClientOptions\r\n }\r\n defaults?: {\r\n locale?: TDBILocaleString,\r\n directMessages?: boolean,\r\n defaultMemberPermissions?: Discord.PermissionsString[]\r\n };\r\n\r\n sharding?: boolean;\r\n /**\r\n * Persist store. (Default to MemoryStore thats not persis tho.)\r\n */\r\n store?: DBIStore;\r\n\r\n clearRefsAfter?: number;\r\n}\r\n\r\nexport interface DBIRegisterAPI {\r\n ChatInput(cfg: TDBIChatInputOmitted): DBIChatInput;\r\n ChatInputOptions: typeof DBIChatInputOptions;\r\n Event(cfg: TDBIEventOmitted): DBIEvent;\r\n Locale(cfg: TDBILocaleConstructor): DBILocale;\r\n Button(cfg: TDBIButtonOmitted): DBIButton;\r\n SelectMenu(cfg: TDBISelectMenuOmitted): DBISelectMenu;\r\n MessageContextMenu(cfg: TDBIMessageContextMenuOmitted): DBIMessageContextMenu;\r\n UserContextMenu(cfg: TDBIUserContextMenuOmitted): DBIUserContextMenu;\r\n InteractionLocale(cfg: TDBIInteractionLocaleOmitted): DBIInteractionLocale;\r\n Modal(cfg: TDBIModalOmitted): DBIModal;\r\n onUnload(cb: () => Promise<any> | any): any;\r\n}\r\n\r\nexport class DBI<TOtherData = Record<string, any>> {\r\n namespace: string;\r\n config: DBIConfig;\r\n client: Discord.Client<true>;\r\n data: {\r\n interactions: Discord.Collection<string, DBIChatInput | DBIButton | DBISelectMenu | DBIMessageContextMenu | DBIUserContextMenu | DBIModal>;\r\n events: Discord.Collection<string, DBIEvent>;\r\n plugins: Discord.Collection<string, any>;\r\n locales: Discord.Collection<string, DBILocale>;\r\n interactionLocales: Discord.Collection<string, DBIInteractionLocale>;\r\n other: TOtherData;\r\n eventMap: Record<string, string[]>;\r\n unloaders: Set<() => void>;\r\n registers: Set<(...args: any[]) => any>;\r\n registerUnloaders: Set<(...args: any[]) => any>;\r\n refs: Map<string, { at: number, value: any }>;\r\n };\r\n events: Events;\r\n cluster?: Sharding.Client;\r\n private _loaded: boolean;\r\n private _hooked: boolean;\r\n constructor(namespace: string, config: DBIConfigConstructor) {\r\n this.namespace = namespace;\r\n\r\n config.store = config.store as any || new MemoryStore();\r\n config.defaults = {\r\n locale: \"en\",\r\n defaultMemberPermissions: [],\r\n directMessages: false,\r\n ...(config.defaults || {})\r\n };\r\n config.sharding = config.sharding ?? false;\r\n\r\n // @ts-ignore\r\n this.config = config;\r\n\r\n this.data = {\r\n interactions: new Discord.Collection(),\r\n events: new Discord.Collection(),\r\n plugins: new Discord.Collection(),\r\n locales: new Discord.Collection(),\r\n interactionLocales: new Discord.Collection(),\r\n other: {} as TOtherData,\r\n eventMap,\r\n unloaders: new Set(),\r\n registers: new Set(),\r\n registerUnloaders: new Set(),\r\n refs: new Map()\r\n }\r\n\r\n this.events = new Events(this);\r\n this.client = new Discord.Client({\r\n ...(config.discord?.options || {}) as any,\r\n ...(config.sharding ? {\r\n shards: (Sharding as any).data.SHARD_LIST,\r\n shardCount: (Sharding as any).data.TOTAL_SHARDS\r\n } : {})\r\n });\r\n this.cluster = config.sharding ? new Sharding.Client(this.client) : undefined;\r\n this._loaded = false;\r\n this._hooked = false;\r\n }\r\n\r\n private async _hookListeners() {\r\n if (this._hooked) return;\r\n this._hooked = true;\r\n this.data.unloaders.add(hookInteractionListeners(this));\r\n this.data.unloaders.add(hookEventListeners(this));\r\n if (typeof this.config.clearRefsAfter == \"number\") {\r\n this.data.unloaders.add((() => {\r\n let interval = setInterval(() => {\r\n this.data.refs.forEach(({ at }, key) => {\r\n if (Date.now() > (at + this.config.clearRefsAfter)) {\r\n this.data.refs.delete(key);\r\n }\r\n });\r\n }, 60000);\r\n return () => {\r\n clearInterval(interval);\r\n }\r\n })());\r\n }\r\n }\r\n\r\n private async _unhookListeners() {\r\n if (!this._hooked) return;\r\n this._hooked = false;\r\n this.data.unloaders.forEach(f => {\r\n f();\r\n });\r\n }\r\n\r\n private async _unregisterAll() {\r\n for await (const cb of this.data.registerUnloaders) {\r\n await cb();\r\n }\r\n this.data.events.clear();\r\n this.data.interactions.clear();\r\n this.data.plugins.clear();\r\n }\r\n\r\n private async _registerAll() {\r\n const self = this;\r\n\r\n for await (const cb of this.data.registers) {\r\n let ChatInput = function(cfg: DBIChatInput) {\r\n let dbiChatInput = new DBIChatInput(self, cfg);\r\n if (self.data.interactions.has(dbiChatInput.name)) throw new Error(`DBIChatInput \"${dbiChatInput.name}\" already loaded as \"${self.data.interactions.get(dbiChatInput.name)?.type}\"!`);\r\n self.data.interactions.set(dbiChatInput.name, dbiChatInput);\r\n return dbiChatInput;\r\n };\r\n ChatInput = Object.assign(ChatInput, class { constructor(...args: any[]) { return ChatInput.apply(this, args as any); } });\r\n\r\n let Event = function(cfg: TDBIEventOmitted) {\r\n let dbiEvent = new DBIEvent(self, cfg);\r\n if (self.data.events.has(dbiEvent.id || dbiEvent.name)) throw new Error(`DBIEvent \"${dbiEvent.id || dbiEvent.name}\" already loaded!`);\r\n self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);\r\n return dbiEvent;\r\n };\r\n Event = Object.assign(Event, class { constructor(...args: any[]) { return Event.apply(this, args as any); } });\r\n\r\n let Button = function(cfg: TDBIButtonOmitted) {\r\n let dbiButton = new DBIButton(self, cfg);\r\n if (self.data.interactions.has(dbiButton.name)) throw new Error(`DBIButton \"${dbiButton.name}\" already loaded as \"${self.data.interactions.get(dbiButton.name)?.type}\"!`);\r\n self.data.interactions.set(dbiButton.name, dbiButton);\r\n return dbiButton;\r\n };\r\n Button = Object.assign(Button, class { constructor(...args: any[]) { return Button.apply(this, args as any); } });\r\n\r\n let SelectMenu = function(cfg: TDBISelectMenuOmitted) {\r\n let dbiSelectMenu = new DBISelectMenu(self, cfg);\r\n if (self.data.interactions.has(dbiSelectMenu.name)) throw new Error(`DBISelectMenu \"${dbiSelectMenu.name}\" already loaded as \"${self.data.interactions.get(dbiSelectMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiSelectMenu.name, dbiSelectMenu);\r\n return dbiSelectMenu;\r\n };\r\n SelectMenu = Object.assign(SelectMenu, class { constructor(...args: any[]) { return SelectMenu.apply(this, args as any); } });\r\n\r\n let MessageContextMenu = function(cfg: TDBIMessageContextMenuOmitted) {\r\n let dbiMessageContextMenu = new DBIMessageContextMenu(self, cfg);\r\n if (self.data.interactions.has(dbiMessageContextMenu.name)) throw new Error(`DBIMessageContextMenu \"${dbiMessageContextMenu.name}\" already loaded as \"${self.data.interactions.get(dbiMessageContextMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiMessageContextMenu.name, dbiMessageContextMenu);\r\n return dbiMessageContextMenu;\r\n };\r\n MessageContextMenu = Object.assign(MessageContextMenu, class { constructor(...args: any[]) { return MessageContextMenu.apply(this, args as any); } });\r\n\r\n let UserContextMenu = function(cfg: TDBIUserContextMenuOmitted) {\r\n let dbiUserContextMenu = new DBIUserContextMenu(self, cfg);\r\n if (self.data.interactions.has(dbiUserContextMenu.name)) throw new Error(`DBIUserContextMenu \"${dbiUserContextMenu.name}\" already loaded as \"${self.data.interactions.get(dbiUserContextMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiUserContextMenu.name, dbiUserContextMenu);\r\n return dbiUserContextMenu;\r\n };\r\n UserContextMenu = Object.assign(UserContextMenu, class { constructor(...args: any[]) { return UserContextMenu.apply(this, args as any); } });\r\n\r\n let Modal = function(cfg: TDBIModalOmitted) {\r\n let dbiModal = new DBIModal(self, cfg);\r\n if (self.data.interactions.has(dbiModal.name)) throw new Error(`DBIModal \"${dbiModal.name}\" already loaded as \"${self.data.interactions.get(dbiModal.name)?.type}\"!`);\r\n self.data.interactions.set(dbiModal.name, dbiModal);\r\n return dbiModal;\r\n };\r\n Modal = Object.assign(Modal, class { constructor(...args: any[]) { return Modal.apply(this, args as any); } });\r\n\r\n let Locale = function(cfg: TDBILocaleConstructor) {\r\n let dbiLocale = new DBILocale(self, cfg);\r\n if (self.data.locales.has(dbiLocale.name)) throw new Error(`DBILocale \"${dbiLocale.name}\" already loaded!`);\r\n self.data.locales.set(dbiLocale.name, dbiLocale);\r\n return dbiLocale;\r\n };\r\n Locale = Object.assign(Locale, class { constructor(...args: any[]) { return Locale.apply(this, args as any); } });\r\n\r\n let InteractionLocale = function(cfg: TDBIInteractionLocaleOmitted) {\r\n let dbiInteractionLocale = new DBIInteractionLocale(self, cfg);\r\n if (self.data.interactionLocales.has(dbiInteractionLocale.name)) throw new Error(`DBIInteractionLocale \"${dbiInteractionLocale.name}\" already loaded!`);\r\n self.data.interactionLocales.set(dbiInteractionLocale.name, dbiInteractionLocale);\r\n return dbiInteractionLocale;\r\n };\r\n InteractionLocale = Object.assign(InteractionLocale, class { constructor(...args: any[]) { return InteractionLocale.apply(this, args as any); } });\r\n\r\n await cb({\r\n ChatInput,\r\n Event,\r\n ChatInputOptions: DBIChatInputOptions,\r\n Locale,\r\n Button,\r\n SelectMenu,\r\n MessageContextMenu,\r\n UserContextMenu,\r\n Modal,\r\n InteractionLocale,\r\n onUnload(cb: ()=> Promise<any> | any) {\r\n self.data.registerUnloaders.add(cb);\r\n },\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n get<K extends keyof TOtherData>(k: K, defaultValue?: TOtherData[K]): TOtherData[K] {\r\n if (defaultValue && !this.has(k as any)) {\r\n this.set(k, defaultValue);\r\n return defaultValue;\r\n }\r\n return _.get(this.data.other, k);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n set<K extends keyof TOtherData>(k: K, v: TOtherData[K]): any {\r\n this.data.other = _.set(this.data.other as any, k, v);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n has(k: string): boolean {\r\n return _.has(this.data.other, k as any);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n delete(k: string): boolean {\r\n return _.unset(this.data.other, k);\r\n }\r\n\r\n async login(): Promise<any> {\r\n await this.client.login(this.config.discord.token);\r\n }\r\n\r\n async register(cb: (api: DBIRegisterAPI) => void): Promise<any> {\r\n this.data.registers.add(cb);\r\n }\r\n\r\n async load(): Promise<boolean> {\r\n if (this._loaded) return false;\r\n await this._registerAll();\r\n await this._hookListeners();\r\n this._loaded = true;\r\n return true;\r\n }\r\n\r\n async unload(): Promise<boolean> {\r\n if (!this._loaded) return false;\r\n await this._unregisterAll();\r\n await this._unhookListeners();\r\n this._loaded = false;\r\n return true;\r\n }\r\n\r\n get loaded(): boolean {\r\n return this._loaded;\r\n }\r\n\r\n async publish(type: \"Global\", clear?: boolean): Promise<any>;\r\n async publish(type: \"Guild\", guildId: string, clear?: boolean): Promise<any>;\r\n\r\n async publish(...args: any[]) {\r\n let interactions = this.data.interactions.filter(i => i.type == \"ChatInput\" || i.type == \"MessageContextMenu\" || i.type == \"UserContextMenu\") as any;\r\n switch (args[0]) {\r\n case \"Global\": {\r\n return await publishInteractions(\r\n this.config.discord.token,\r\n args[1] ? new Discord.Collection() : interactions,\r\n this.data.interactionLocales,\r\n args[0]\r\n );\r\n }\r\n case \"Guild\": {\r\n return await publishInteractions(\r\n this.config.discord.token,\r\n args[2] ? new Discord.Collection() : interactions,\r\n this.data.interactionLocales,\r\n args[0],\r\n args[1]\r\n );\r\n }\r\n }\r\n }\r\n\r\n \r\n}"]}
|
|
1
|
+
{"version":3,"file":"DBI.js","sourceRoot":"","sources":["../src/DBI.ts"],"names":[],"mappings":";;;;AAAA,oEAAiC;AACjC,2DAAiF;AACjF,yEAAyE;AACzE,uEAAoE;AACpE,yCAA2D;AAC3D,qDAAkD;AAClD,iFAA8E;AAC9E,qCAAkC;AAClC,2CAAoF;AACpF,2CAA8D;AAC9D,mDAA0E;AAC1E,mEAAkG;AAClG,6DAAyF;AACzF,qEAAkE;AAClE,iFAA4C;AAC5C,yCAA2D;AAC3D,0EAAoD;AACpD,4DAAuB;AACvB,iEAA+F;AA+E/F,MAAa,GAAG;IACd,SAAS,CAAS;IAClB,MAAM,CAAY;IAClB,MAAM,CAAuB;IAC7B,IAAI,CAYF;IACF,MAAM,CAAS;IACf,OAAO,CAAmB;IAClB,OAAO,CAAU;IACjB,OAAO,CAAU;IACzB,YAAY,SAAiB,EAAE,MAA4B;QACzD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAY,IAAI,IAAI,yBAAW,EAAE,CAAC;QACxD,MAAM,CAAC,QAAQ,GAAG;YAChB,MAAM,EAAE,IAAI;YACZ,wBAAwB,EAAE,EAAE;YAC5B,cAAc,EAAE,KAAK;YACrB,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;SAC3B,CAAC;QACF,MAAM,CAAC,QAAQ,GAA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AC,IAAI,IAAI,oBAAoB,IAAI,CAAC,CAAC,IAAI,IAAI,iBAAiB,CAAQ,CAAC;QACrJ,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE;YACf,KAAK,QAAQ,CAAC,CAAC;gBACb,OAAO,MAAM,IAAA,yCAAmB,EAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EACzB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,YAAY,EACjD,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAC5B,IAAI,CAAC,CAAC,CAAC,CACR,CAAC;aACH;YACD,KAAK,OAAO,CAAC,CAAC;gBACZ,OAAO,MAAM,IAAA,yCAAmB,EAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EACzB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,YAAY,EACjD,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAC5B,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,CACR,CAAC;aACH;SACF;IACH,CAAC;CAGF;AA3TD,kBA2TC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { DBIChatInput, TDBIChatInputOmitted } from \"./types/ChatInput/ChatInput\";\r\nimport { DBIChatInputOptions } from \"./types/ChatInput/ChatInputOptions\";\r\nimport { publishInteractions } from \"./methods/publishInteractions\";\r\nimport { DBIEvent, TDBIEventOmitted } from \"./types/Event\";\r\nimport { MemoryStore } from \"./utils/MemoryStore\";\r\nimport { hookInteractionListeners } from \"./methods/hookInteractionListeners\";\r\nimport { Events } from \"./Events\";\r\nimport { DBILocale, TDBILocaleConstructor, TDBILocaleString } from \"./types/Locale\";\r\nimport { DBIButton, TDBIButtonOmitted } from \"./types/Button\";\r\nimport { DBISelectMenu, TDBISelectMenuOmitted } from \"./types/SelectMenu\";\r\nimport { DBIMessageContextMenu, TDBIMessageContextMenuOmitted } from \"./types/MessageContextMenu\";\r\nimport { DBIUserContextMenu, TDBIUserContextMenuOmitted } from \"./types/UserContextMenu\";\r\nimport { hookEventListeners } from \"./methods/hookEventListeners\";\r\nimport eventMap from \"./data/eventMap.json\";\r\nimport { DBIModal, TDBIModalOmitted } from \"./types/Modal\";\r\nimport * as Sharding from \"discord-hybrid-sharding\";\r\nimport _ from \"lodash\";\r\nimport { DBIInteractionLocale, TDBIInteractionLocaleOmitted } from \"./types/InteractionLocale\";\r\n\r\nexport interface DBIStore {\r\n get(key: string, defaultValue?: any): Promise<any>;\r\n set(key: string, value: any): Promise<void>;\r\n delete(key: string): Promise<void>;\r\n has(key: string): Promise<boolean>;\r\n}\r\n\r\nexport interface DBIConfig {\r\n discord: {\r\n token: string;\r\n options: Discord.ClientOptions\r\n }\r\n defaults: {\r\n locale: TDBILocaleString,\r\n directMessages: boolean,\r\n defaultMemberPermissions: Discord.PermissionsString[]\r\n };\r\n\r\n sharding: \"hybrid\" | \"default\" | \"off\";\r\n /**\r\n * Persist store. (Default to MemoryStore thats not persis tho.)\r\n */\r\n store: DBIStore;\r\n\r\n references: {\r\n autoClear?: {\r\n check: number;\r\n ttl: number;\r\n }\r\n };\r\n\r\n strict: boolean;\r\n}\r\n\r\nexport interface DBIConfigConstructor {\r\n discord: {\r\n token: string;\r\n options: Discord.ClientOptions\r\n }\r\n defaults?: {\r\n locale?: TDBILocaleString,\r\n directMessages?: boolean,\r\n defaultMemberPermissions?: Discord.PermissionsString[]\r\n };\r\n\r\n sharding?: \"hybrid\" | \"default\" | \"off\";\r\n /**\r\n * Persist store. (Default to MemoryStore thats not persis tho.)\r\n */\r\n store?: DBIStore;\r\n\r\n references?: {\r\n autoClear?: {\r\n check: number;\r\n ttl: number;\r\n }\r\n };\r\n\r\n strict?: boolean;\r\n}\r\n\r\nexport interface DBIRegisterAPI {\r\n ChatInput(cfg: TDBIChatInputOmitted): DBIChatInput;\r\n ChatInputOptions: typeof DBIChatInputOptions;\r\n Event(cfg: TDBIEventOmitted): DBIEvent;\r\n Locale(cfg: TDBILocaleConstructor): DBILocale;\r\n Button(cfg: TDBIButtonOmitted): DBIButton;\r\n SelectMenu(cfg: TDBISelectMenuOmitted): DBISelectMenu;\r\n MessageContextMenu(cfg: TDBIMessageContextMenuOmitted): DBIMessageContextMenu;\r\n UserContextMenu(cfg: TDBIUserContextMenuOmitted): DBIUserContextMenu;\r\n InteractionLocale(cfg: TDBIInteractionLocaleOmitted): DBIInteractionLocale;\r\n Modal(cfg: TDBIModalOmitted): DBIModal;\r\n onUnload(cb: () => Promise<any> | any): any;\r\n}\r\n\r\nexport type TDBIInteractions = DBIChatInput | DBIButton | DBISelectMenu | DBIMessageContextMenu | DBIUserContextMenu | DBIModal;\r\n\r\nexport class DBI<TOtherData = Record<string, any>> {\r\n namespace: string;\r\n config: DBIConfig;\r\n client: Discord.Client<true>;\r\n data: {\r\n interactions: Discord.Collection<string, TDBIInteractions>;\r\n events: Discord.Collection<string, DBIEvent>;\r\n plugins: Discord.Collection<string, any>;\r\n locales: Discord.Collection<string, DBILocale>;\r\n interactionLocales: Discord.Collection<string, DBIInteractionLocale>;\r\n other: TOtherData;\r\n eventMap: Record<string, string[]>;\r\n unloaders: Set<() => void>;\r\n registers: Set<(...args: any[]) => any>;\r\n registerUnloaders: Set<(...args: any[]) => any>;\r\n refs: Map<string, { at: number, value: any, ttl?: number }>;\r\n };\r\n events: Events;\r\n cluster?: Sharding.Client;\r\n private _loaded: boolean;\r\n private _hooked: boolean;\r\n constructor(namespace: string, config: DBIConfigConstructor) {\r\n this.namespace = namespace;\r\n\r\n config.store = config.store as any || new MemoryStore();\r\n config.defaults = {\r\n locale: \"en\",\r\n defaultMemberPermissions: [],\r\n directMessages: false,\r\n ...(config.defaults || {})\r\n };\r\n config.sharding = config.sharding ?? \"off\";\r\n config.strict = config.strict ?? true;\r\n config.references = {\r\n autoClear: undefined,\r\n ...(config.references || {})\r\n }\r\n\r\n // @ts-ignore\r\n this.config = config;\r\n\r\n this.data = {\r\n interactions: new Discord.Collection(),\r\n events: new Discord.Collection(),\r\n plugins: new Discord.Collection(),\r\n locales: new Discord.Collection(),\r\n interactionLocales: new Discord.Collection(),\r\n other: {} as TOtherData,\r\n eventMap,\r\n unloaders: new Set(),\r\n registers: new Set(),\r\n registerUnloaders: new Set(),\r\n refs: new Map()\r\n }\r\n\r\n this.events = new Events(this as any);\r\n this.client = new Discord.Client({\r\n ...(config.discord?.options || {}) as any,\r\n ...(config.sharding == \"hybrid\" ? {\r\n shards: (Sharding as any).data.SHARD_LIST,\r\n shardCount: (Sharding as any).data.TOTAL_SHARDS\r\n } : {})\r\n });\r\n this.cluster = config.sharding == \"hybrid\" ? new Sharding.Client(this.client) : undefined;\r\n this._loaded = false;\r\n this._hooked = false;\r\n }\r\n\r\n private async _hookListeners() {\r\n if (this._hooked) return;\r\n this._hooked = true;\r\n this.data.unloaders.add(hookInteractionListeners(this as any));\r\n this.data.unloaders.add(hookEventListeners(this as any));\r\n if (typeof this.config.references.autoClear != \"undefined\") {\r\n this.data.unloaders.add((() => {\r\n let interval = setInterval(() => {\r\n this.data.refs.forEach(({ at, ttl }, key) => {\r\n if (Date.now() > (at + (ttl || this.config.references.autoClear.ttl))) {\r\n this.data.refs.delete(key);\r\n }\r\n });\r\n }, this.config.references.autoClear.check);\r\n return () => {\r\n clearInterval(interval);\r\n }\r\n })());\r\n }\r\n }\r\n\r\n private async _unhookListeners() {\r\n if (!this._hooked) return;\r\n this._hooked = false;\r\n this.data.unloaders.forEach(f => {\r\n f();\r\n });\r\n }\r\n\r\n private async _unregisterAll() {\r\n for await (const cb of this.data.registerUnloaders) {\r\n await cb();\r\n }\r\n this.data.events.clear();\r\n this.data.interactions.clear();\r\n this.data.plugins.clear();\r\n }\r\n\r\n private async _registerAll() {\r\n const self = this;\r\n\r\n for await (const cb of this.data.registers) {\r\n let ChatInput = function(cfg: DBIChatInput) {\r\n let dbiChatInput = new DBIChatInput(self, cfg);\r\n if (self.data.interactions.has(dbiChatInput.name)) throw new Error(`DBIChatInput \"${dbiChatInput.name}\" already loaded as \"${self.data.interactions.get(dbiChatInput.name)?.type}\"!`);\r\n self.data.interactions.set(dbiChatInput.name, dbiChatInput);\r\n return dbiChatInput;\r\n };\r\n ChatInput = Object.assign(ChatInput, class { constructor(...args: any[]) { return ChatInput.apply(this, args as any); } });\r\n\r\n let Event = function(cfg: TDBIEventOmitted) {\r\n let dbiEvent = new DBIEvent(self, cfg);\r\n if (self.config.strict && self.data.events.has(dbiEvent.id || dbiEvent.name)) throw new Error(`DBIEvent \"${dbiEvent.id || dbiEvent.name}\" already loaded!`);\r\n self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);\r\n return dbiEvent;\r\n };\r\n Event = Object.assign(Event, class { constructor(...args: any[]) { return Event.apply(this, args as any); } });\r\n\r\n let Button = function(cfg: TDBIButtonOmitted) {\r\n let dbiButton = new DBIButton(self, cfg);\r\n if (self.config.strict && self.data.interactions.has(dbiButton.name)) throw new Error(`DBIButton \"${dbiButton.name}\" already loaded as \"${self.data.interactions.get(dbiButton.name)?.type}\"!`);\r\n self.data.interactions.set(dbiButton.name, dbiButton);\r\n return dbiButton;\r\n };\r\n Button = Object.assign(Button, class { constructor(...args: any[]) { return Button.apply(this, args as any); } });\r\n\r\n let SelectMenu = function(cfg: TDBISelectMenuOmitted) {\r\n let dbiSelectMenu = new DBISelectMenu(self, cfg);\r\n if (self.config.strict && self.data.interactions.has(dbiSelectMenu.name)) throw new Error(`DBISelectMenu \"${dbiSelectMenu.name}\" already loaded as \"${self.data.interactions.get(dbiSelectMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiSelectMenu.name, dbiSelectMenu);\r\n return dbiSelectMenu;\r\n };\r\n SelectMenu = Object.assign(SelectMenu, class { constructor(...args: any[]) { return SelectMenu.apply(this, args as any); } });\r\n\r\n let MessageContextMenu = function(cfg: TDBIMessageContextMenuOmitted) {\r\n let dbiMessageContextMenu = new DBIMessageContextMenu(self, cfg);\r\n if (self.config.strict && self.data.interactions.has(dbiMessageContextMenu.name)) throw new Error(`DBIMessageContextMenu \"${dbiMessageContextMenu.name}\" already loaded as \"${self.data.interactions.get(dbiMessageContextMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiMessageContextMenu.name, dbiMessageContextMenu);\r\n return dbiMessageContextMenu;\r\n };\r\n MessageContextMenu = Object.assign(MessageContextMenu, class { constructor(...args: any[]) { return MessageContextMenu.apply(this, args as any); } });\r\n\r\n let UserContextMenu = function(cfg: TDBIUserContextMenuOmitted) {\r\n let dbiUserContextMenu = new DBIUserContextMenu(self, cfg);\r\n if (self.config.strict && self.data.interactions.has(dbiUserContextMenu.name)) throw new Error(`DBIUserContextMenu \"${dbiUserContextMenu.name}\" already loaded as \"${self.data.interactions.get(dbiUserContextMenu.name)?.type}\"!`);\r\n self.data.interactions.set(dbiUserContextMenu.name, dbiUserContextMenu);\r\n return dbiUserContextMenu;\r\n };\r\n UserContextMenu = Object.assign(UserContextMenu, class { constructor(...args: any[]) { return UserContextMenu.apply(this, args as any); } });\r\n\r\n let Modal = function(cfg: TDBIModalOmitted) {\r\n let dbiModal = new DBIModal(self, cfg);\r\n if (self.config.strict && self.data.interactions.has(dbiModal.name)) throw new Error(`DBIModal \"${dbiModal.name}\" already loaded as \"${self.data.interactions.get(dbiModal.name)?.type}\"!`);\r\n self.data.interactions.set(dbiModal.name, dbiModal);\r\n return dbiModal;\r\n };\r\n Modal = Object.assign(Modal, class { constructor(...args: any[]) { return Modal.apply(this, args as any); } });\r\n\r\n let Locale = function(cfg: TDBILocaleConstructor) {\r\n let dbiLocale = new DBILocale(self, cfg);\r\n if (self.config.strict && self.data.locales.has(dbiLocale.name)) throw new Error(`DBILocale \"${dbiLocale.name}\" already loaded!`);\r\n self.data.locales.set(dbiLocale.name, dbiLocale);\r\n return dbiLocale;\r\n };\r\n Locale = Object.assign(Locale, class { constructor(...args: any[]) { return Locale.apply(this, args as any); } });\r\n\r\n let InteractionLocale = function(cfg: TDBIInteractionLocaleOmitted) {\r\n let dbiInteractionLocale = new DBIInteractionLocale(self, cfg);\r\n if (self.config.strict && self.data.interactionLocales.has(dbiInteractionLocale.name)) throw new Error(`DBIInteractionLocale \"${dbiInteractionLocale.name}\" already loaded!`);\r\n self.data.interactionLocales.set(dbiInteractionLocale.name, dbiInteractionLocale);\r\n return dbiInteractionLocale;\r\n };\r\n InteractionLocale = Object.assign(InteractionLocale, class { constructor(...args: any[]) { return InteractionLocale.apply(this, args as any); } });\r\n\r\n await cb({\r\n ChatInput,\r\n Event,\r\n ChatInputOptions: DBIChatInputOptions,\r\n Locale,\r\n Button,\r\n SelectMenu,\r\n MessageContextMenu,\r\n UserContextMenu,\r\n Modal,\r\n InteractionLocale,\r\n onUnload(cb: ()=> Promise<any> | any) {\r\n self.data.registerUnloaders.add(cb);\r\n },\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * this.data.interactions.get(name)\r\n */\r\n interaction(name: string): TDBIInteractions {\r\n return this.data.interactions.get(name);\r\n }\r\n\r\n /**\r\n * this.data.events.get(name)\r\n */\r\n event(name: string): DBIEvent {\r\n return this.data.events.get(name);\r\n }\r\n\r\n /**\r\n * this.data.locales.get(name)\r\n */\r\n locale(name: string): DBILocale {\r\n return this.data.locales.get(name);\r\n }\r\n\r\n /**\r\n * this.data.plugins.get(name)\r\n */\r\n plugin(name: string): any {\r\n return this.data.plugins.get(name);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n get<K extends keyof TOtherData>(k: K, defaultValue?: TOtherData[K]): TOtherData[K] {\r\n if (defaultValue && !this.has(k as any)) {\r\n this.set(k, defaultValue);\r\n return defaultValue;\r\n }\r\n return _.get(this.data.other, k);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n set<K extends keyof TOtherData>(k: K, v: TOtherData[K]): any {\r\n this.data.other = _.set(this.data.other as any, k, v);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n has(k: string): boolean {\r\n return _.has(this.data.other, k as any);\r\n }\r\n\r\n /**\r\n * Shorthands for modifying `dbi.data.other`\r\n */\r\n delete(k: string): boolean {\r\n return _.unset(this.data.other, k);\r\n }\r\n\r\n async login(): Promise<any> {\r\n await this.client.login(this.config.sharding == \"default\" ? undefined : this.config.discord.token);\r\n }\r\n\r\n async register(cb: (api: DBIRegisterAPI) => void): Promise<any> {\r\n this.data.registers.add(cb);\r\n }\r\n\r\n async load(): Promise<boolean> {\r\n if (this._loaded) return false;\r\n await this._registerAll();\r\n await this._hookListeners();\r\n this._loaded = true;\r\n return true;\r\n }\r\n\r\n async unload(): Promise<boolean> {\r\n if (!this._loaded) return false;\r\n await this._unregisterAll();\r\n await this._unhookListeners();\r\n this._loaded = false;\r\n return true;\r\n }\r\n\r\n get loaded(): boolean {\r\n return this._loaded;\r\n }\r\n\r\n async publish(type: \"Global\", clear?: boolean): Promise<any>;\r\n async publish(type: \"Guild\", guildId: string, clear?: boolean): Promise<any>;\r\n\r\n async publish(...args: any[]) {\r\n let interactions = this.data.interactions.filter(i => i.type == \"ChatInput\" || i.type == \"MessageContextMenu\" || i.type == \"UserContextMenu\") as any;\r\n switch (args[0]) {\r\n case \"Global\": {\r\n return await publishInteractions(\r\n this.config.discord.token,\r\n args[1] ? new Discord.Collection() : interactions,\r\n this.data.interactionLocales,\r\n args[0]\r\n );\r\n }\r\n case \"Guild\": {\r\n return await publishInteractions(\r\n this.config.discord.token,\r\n args[2] ? new Discord.Collection() : interactions,\r\n this.data.interactionLocales,\r\n args[0],\r\n args[1]\r\n );\r\n }\r\n }\r\n }\r\n\r\n \r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publishInteractions.d.ts","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAM5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAKlE,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,YAAY,CAAC,EACtD,mBAAmB,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,oBAAoB,CAAC,EACrE,WAAW,EAAE,OAAO,GAAG,QAAQ,EAC/B,OAAO,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"publishInteractions.d.ts","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAM5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAKlE,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,YAAY,CAAC,EACtD,mBAAmB,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,oBAAoB,CAAC,EACrE,WAAW,EAAE,OAAO,GAAG,QAAQ,EAC/B,OAAO,CAAC,EAAE,MAAM,iBAuKjB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,GAAG,GAAG,EAAE,CAcvE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,oBAAoB,GAAG,GAAG,CAgD9D"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatLocale = exports.localeifyOptions = exports.publishInteractions = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const rest_1 = require("@discordjs/rest");
|
|
6
5
|
const v9_1 = require("discord-api-types/v9");
|
|
7
6
|
const permissions_1 = require("../utils/permissions");
|
|
8
|
-
const snakecase_keys_1 = tslib_1.__importDefault(require("snakecase-keys"));
|
|
9
7
|
const PUBLISHABLE_TYPES = ["ChatInput", "UserContextMenu", "MessageContextMenu"];
|
|
10
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"];
|
|
11
9
|
async function publishInteractions(clientToken, interactions, interactionsLocales, publishType, guildId) {
|
|
@@ -160,7 +158,6 @@ async function publishInteractions(clientToken, interactions, interactionsLocale
|
|
|
160
158
|
}
|
|
161
159
|
return all;
|
|
162
160
|
}, []);
|
|
163
|
-
body = (0, snakecase_keys_1.default)(body);
|
|
164
161
|
switch (publishType) {
|
|
165
162
|
case "Global": {
|
|
166
163
|
await rest.put(v9_1.Routes.applicationGuildCommands(me.id, guildId), { body });
|
|
@@ -175,9 +172,16 @@ async function publishInteractions(clientToken, interactions, interactionsLocale
|
|
|
175
172
|
exports.publishInteractions = publishInteractions;
|
|
176
173
|
function localeifyOptions(options, localeData) {
|
|
177
174
|
return options.map(i => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
let optionData = localeData[i.name];
|
|
176
|
+
return optionData ? Object.assign(i, {
|
|
177
|
+
name_localizations: optionData.nameLocales,
|
|
178
|
+
description_localizations: optionData.descriptionLocales,
|
|
179
|
+
choices: i.choices ? i.choices.map((j) => {
|
|
180
|
+
let choiceLocale = optionData.choiceLocales[j.name];
|
|
181
|
+
return choiceLocale ? Object.assign(j, {
|
|
182
|
+
name_localizations: choiceLocale
|
|
183
|
+
}) : j;
|
|
184
|
+
}) : undefined
|
|
181
185
|
}) : i;
|
|
182
186
|
});
|
|
183
187
|
}
|
|
@@ -204,12 +208,23 @@ function formatLocale(locale) {
|
|
|
204
208
|
Object.entries(localeData.options || []).forEach(([optionName, optionData]) => {
|
|
205
209
|
if (!optionsLocales[optionName])
|
|
206
210
|
optionsLocales[optionName] = {};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
let optionLocale = optionsLocales[optionName];
|
|
212
|
+
if (!optionLocale.nameLocales)
|
|
213
|
+
optionLocale.nameLocales = {};
|
|
214
|
+
if (!optionLocale.descriptionLocales)
|
|
215
|
+
optionLocale.descriptionLocales = {};
|
|
216
|
+
if (!optionLocale.choiceLocales)
|
|
217
|
+
optionLocale.choiceLocales = {};
|
|
218
|
+
Object.entries(optionData.choices).forEach(([choiceOriginalName, choiceName]) => {
|
|
219
|
+
if (!optionLocale.choiceLocales)
|
|
220
|
+
optionLocale.choiceLocales = {};
|
|
221
|
+
if (!optionLocale.choiceLocales[choiceOriginalName])
|
|
222
|
+
optionLocale.choiceLocales[choiceOriginalName] = {};
|
|
223
|
+
let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];
|
|
224
|
+
choiceLocale[longLocale] = choiceName;
|
|
225
|
+
});
|
|
226
|
+
optionLocale.nameLocales[longLocale] = optionData.name;
|
|
227
|
+
optionLocale.descriptionLocales[longLocale] = optionData.description;
|
|
213
228
|
});
|
|
214
229
|
});
|
|
215
230
|
});
|
|
@@ -1 +1 @@
|
|
|
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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AAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC;QAClF,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACjC,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;YAC7C,kBAAkB,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;YACxD,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,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 interactions = interactions.sort((a, b) => b.name.split(\" \").length - a.name.split(\" \").length);\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 == 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 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 == ApplicationCommandType.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]);\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}"]}
|
|
1
|
+
{"version":3,"file":"publishInteractions.js","sourceRoot":"","sources":["../../src/methods/publishInteractions.ts"],"names":[],"mappings":";;;AAEA,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kB,GAAG,EAAE,CAAC;gBAC3E,IAAI,CAAC,YAAY,CAAC,aAAa;oBAAE,YAAY,CAAC,aAAa,GAAG,EAAE,CAAC;gBAEjE,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,EAAE;oBAC9E,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 } 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 interactions = interactions.sort((a, b) => b.name.split(\" \").length - a.name.split(\" \").length);\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 == 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 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 == ApplicationCommandType.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]);\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 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 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}"]}
|
package/dist/types/Button.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class DBIButton extends DBIBaseInteraction {
|
|
|
10
10
|
constructor(dbi: DBI, args: TDBIButtonOmitted);
|
|
11
11
|
options?: Omit<Discord.ButtonComponentData, "customId" | "type"> | ((data: (number | string | any)[]) => Omit<Discord.ButtonComponentData, "customId" | "type">);
|
|
12
12
|
onExecute(ctx: IDBIButtonExecuteCtx): Promise<any> | any;
|
|
13
|
+
referenceTTL?: number;
|
|
13
14
|
toJSON(...customData: (string | number | object)[]): Discord.ButtonComponentData;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=Button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/types/Button.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG3F,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,WAAW,EAAE,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAED,oBAAY,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC;AAE3F,qBAAa,SAAU,SAAQ,kBAAkB;gBACnC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/types/Button.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG3F,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,WAAW,EAAE,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAED,oBAAY,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC;AAE3F,qBAAa,SAAU,SAAQ,kBAAkB;gBACnC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB;IAQrC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC;IAEhK,SAAS,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;IACzD,YAAY,CAAC,EAAE,MAAM,CAAA;IAC7B,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,mBAAmB;CAOjF"}
|
package/dist/types/Button.js
CHANGED
|
@@ -11,13 +11,14 @@ class DBIButton extends Interaction_1.DBIBaseInteraction {
|
|
|
11
11
|
...args,
|
|
12
12
|
type: "Button",
|
|
13
13
|
});
|
|
14
|
+
this.referenceTTL = args.referenceTTL;
|
|
14
15
|
}
|
|
15
16
|
onExecute(ctx) { }
|
|
16
17
|
;
|
|
17
18
|
toJSON(...customData) {
|
|
18
19
|
return {
|
|
19
20
|
...(typeof this.options == "function" ? this.options(customData) : this.options),
|
|
20
|
-
customId: (0, customId_1.customIdBuilder)(this.dbi, this.name, customData),
|
|
21
|
+
customId: (0, customId_1.customIdBuilder)(this.dbi, this.name, customData, this.referenceTTL),
|
|
21
22
|
type: discord_js_1.default.ComponentType.Button
|
|
22
23
|
};
|
|
23
24
|
}
|