@mostfeatured/dbi 0.0.26 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DBI.d.ts +22 -1
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +53 -1
- 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/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/package.json +1 -1
- package/src/DBI.ts +68 -7
- package/src/methods/publishInteractions.ts +24 -9
- package/src/types/ChatInput/ChatInputOptions.ts +9 -0
- package/src/types/InteractionLocale.ts +3 -0
- package/src/types/Locale.ts +9 -9
package/dist/DBI.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface DBIConfig {
|
|
|
32
32
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
33
33
|
*/
|
|
34
34
|
store: DBIStore;
|
|
35
|
+
clearRefsAfter?: number;
|
|
35
36
|
}
|
|
36
37
|
export interface DBIConfigConstructor {
|
|
37
38
|
discord: {
|
|
@@ -48,6 +49,7 @@ export interface DBIConfigConstructor {
|
|
|
48
49
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
49
50
|
*/
|
|
50
51
|
store?: DBIStore;
|
|
52
|
+
clearRefsAfter?: number;
|
|
51
53
|
}
|
|
52
54
|
export interface DBIRegisterAPI {
|
|
53
55
|
ChatInput(cfg: TDBIChatInputOmitted): DBIChatInput;
|
|
@@ -62,12 +64,13 @@ export interface DBIRegisterAPI {
|
|
|
62
64
|
Modal(cfg: TDBIModalOmitted): DBIModal;
|
|
63
65
|
onUnload(cb: () => Promise<any> | any): any;
|
|
64
66
|
}
|
|
67
|
+
export declare type TDBIInteractions = DBIChatInput | DBIButton | DBISelectMenu | DBIMessageContextMenu | DBIUserContextMenu | DBIModal;
|
|
65
68
|
export declare class DBI<TOtherData = Record<string, any>> {
|
|
66
69
|
namespace: string;
|
|
67
70
|
config: DBIConfig;
|
|
68
71
|
client: Discord.Client<true>;
|
|
69
72
|
data: {
|
|
70
|
-
interactions: Discord.Collection<string,
|
|
73
|
+
interactions: Discord.Collection<string, TDBIInteractions>;
|
|
71
74
|
events: Discord.Collection<string, DBIEvent>;
|
|
72
75
|
plugins: Discord.Collection<string, any>;
|
|
73
76
|
locales: Discord.Collection<string, DBILocale>;
|
|
@@ -85,10 +88,28 @@ export declare class DBI<TOtherData = Record<string, any>> {
|
|
|
85
88
|
events: Events;
|
|
86
89
|
cluster?: Sharding.Client;
|
|
87
90
|
private _loaded;
|
|
91
|
+
private _hooked;
|
|
88
92
|
constructor(namespace: string, config: DBIConfigConstructor);
|
|
89
93
|
private _hookListeners;
|
|
94
|
+
private _unhookListeners;
|
|
90
95
|
private _unregisterAll;
|
|
91
96
|
private _registerAll;
|
|
97
|
+
/**
|
|
98
|
+
* this.data.interactions.get(name)
|
|
99
|
+
*/
|
|
100
|
+
interaction(name: string): TDBIInteractions;
|
|
101
|
+
/**
|
|
102
|
+
* this.data.events.get(name)
|
|
103
|
+
*/
|
|
104
|
+
event(name: string): DBIEvent;
|
|
105
|
+
/**
|
|
106
|
+
* this.data.locales.get(name)
|
|
107
|
+
*/
|
|
108
|
+
locale(name: string): DBILocale;
|
|
109
|
+
/**
|
|
110
|
+
* this.data.plugins.get(name)
|
|
111
|
+
*/
|
|
112
|
+
plugin(name: string): any;
|
|
92
113
|
/**
|
|
93
114
|
* Shorthands for modifying `dbi.data.other`
|
|
94
115
|
*/
|
package/dist/DBI.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBI.d.ts","sourceRoot":"","sources":["../src/DBI.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"DBI.d.ts","sourceRoot":"","sources":["../src/DBI.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAA4B,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAGzF,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO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EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAQlF;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG;IAI5D;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAIvB;;OAEG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAIpB,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;IAIrB,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAIzD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAQxB,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAQhC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAEK,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IACtD,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;CA0B7E"}
|
package/dist/DBI.js
CHANGED
|
@@ -29,6 +29,7 @@ class DBI {
|
|
|
29
29
|
events;
|
|
30
30
|
cluster;
|
|
31
31
|
_loaded;
|
|
32
|
+
_hooked;
|
|
32
33
|
constructor(namespace, config) {
|
|
33
34
|
this.namespace = namespace;
|
|
34
35
|
config.store = config.store || new MemoryStore_1.MemoryStore();
|
|
@@ -63,12 +64,37 @@ class DBI {
|
|
|
63
64
|
} : {})
|
|
64
65
|
});
|
|
65
66
|
this.cluster = config.sharding ? new Sharding.Client(this.client) : undefined;
|
|
66
|
-
this._hookListeners();
|
|
67
67
|
this._loaded = false;
|
|
68
|
+
this._hooked = false;
|
|
68
69
|
}
|
|
69
70
|
async _hookListeners() {
|
|
71
|
+
if (this._hooked)
|
|
72
|
+
return;
|
|
73
|
+
this._hooked = true;
|
|
70
74
|
this.data.unloaders.add((0, hookInteractionListeners_1.hookInteractionListeners)(this));
|
|
71
75
|
this.data.unloaders.add((0, hookEventListeners_1.hookEventListeners)(this));
|
|
76
|
+
if (typeof this.config.clearRefsAfter == "number") {
|
|
77
|
+
this.data.unloaders.add((() => {
|
|
78
|
+
let interval = setInterval(() => {
|
|
79
|
+
this.data.refs.forEach(({ at }, key) => {
|
|
80
|
+
if (Date.now() > (at + this.config.clearRefsAfter)) {
|
|
81
|
+
this.data.refs.delete(key);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}, 60000);
|
|
85
|
+
return () => {
|
|
86
|
+
clearInterval(interval);
|
|
87
|
+
};
|
|
88
|
+
})());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async _unhookListeners() {
|
|
92
|
+
if (!this._hooked)
|
|
93
|
+
return;
|
|
94
|
+
this._hooked = false;
|
|
95
|
+
this.data.unloaders.forEach(f => {
|
|
96
|
+
f();
|
|
97
|
+
});
|
|
72
98
|
}
|
|
73
99
|
async _unregisterAll() {
|
|
74
100
|
for await (const cb of this.data.registerUnloaders) {
|
|
@@ -188,6 +214,30 @@ class DBI {
|
|
|
188
214
|
});
|
|
189
215
|
}
|
|
190
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* this.data.interactions.get(name)
|
|
219
|
+
*/
|
|
220
|
+
interaction(name) {
|
|
221
|
+
return this.data.interactions.get(name);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* this.data.events.get(name)
|
|
225
|
+
*/
|
|
226
|
+
event(name) {
|
|
227
|
+
return this.data.events.get(name);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* this.data.locales.get(name)
|
|
231
|
+
*/
|
|
232
|
+
locale(name) {
|
|
233
|
+
return this.data.locales.get(name);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* this.data.plugins.get(name)
|
|
237
|
+
*/
|
|
238
|
+
plugin(name) {
|
|
239
|
+
return this.data.plugins.get(name);
|
|
240
|
+
}
|
|
191
241
|
/**
|
|
192
242
|
* Shorthands for modifying `dbi.data.other`
|
|
193
243
|
*/
|
|
@@ -226,6 +276,7 @@ class DBI {
|
|
|
226
276
|
if (this._loaded)
|
|
227
277
|
return false;
|
|
228
278
|
await this._registerAll();
|
|
279
|
+
await this._hookListeners();
|
|
229
280
|
this._loaded = true;
|
|
230
281
|
return true;
|
|
231
282
|
}
|
|
@@ -233,6 +284,7 @@ class DBI {
|
|
|
233
284
|
if (!this._loaded)
|
|
234
285
|
return false;
|
|
235
286
|
await this._unregisterAll();
|
|
287
|
+
await this._unhookListeners();
|
|
236
288
|
this._loaded = false;
|
|
237
289
|
return true;
|
|
238
290
|
}
|
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;AA2D/F,MAAa,GAAG;IACd,SAAS,CAAS;IAClB,MAAM,CAAY;IAClB,MAAM,CAAuB;IAC7B,IAAI,CAYF;IACF,MAAM,CAAS;IACf,OAAO,CAAmB;IAClB,OAAO,CAAU;IACzB,YAAY,SAAiB,EAAE,MAA4B;QACzD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,MAAM,CAAC,KAAK,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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\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\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 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._hookListeners();\r\n this._loaded = false;\r\n }\r\n\r\n private async _hookListeners() {\r\n this.data.unloaders.add(hookInteractionListeners(this));\r\n this.data.unloaders.add(hookEventListeners(this));\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 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 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,2CAA8G;AAC9G,2CAA8D;AAC9D,mDAA0E;AAC1E,mEAAkG;AAClG,6DAAyF;AACzF,qEAAkE;AAClE,iFAA4C;AAC5C,yCAA2D;AAC3D,0EAAoD;AACpD,4DAAuB;AACvB,iEAA+F;AAiE/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,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;QAE3C,aA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IACH,CAAC;CAGF;AAtTD,kBAsTC","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, DBILangConstructorObject, 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 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 }>;\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 as any);\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 as any));\r\n this.data.unloaders.add(hookEventListeners(this as any));\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 as any;\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 * 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.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,CA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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 descriptionLoc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AAY,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,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}"]}
|
|
@@ -136,6 +136,12 @@ export declare class DBIChatInputOptions {
|
|
|
136
136
|
channelTypes: Discord.ChannelType[];
|
|
137
137
|
required: boolean;
|
|
138
138
|
};
|
|
139
|
+
static role(cfg: TNameDescription): {
|
|
140
|
+
type: Discord.ApplicationCommandOptionType;
|
|
141
|
+
name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
required: boolean;
|
|
144
|
+
};
|
|
139
145
|
static mentionable(cfg: TNameDescription): {
|
|
140
146
|
type: Discord.ApplicationCommandOptionType;
|
|
141
147
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatInputOptions.d.ts","sourceRoot":"","sources":["../../../src/types/ChatInput/ChatInputOptions.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,aAAK,UAAU,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAChD,aAAK,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAElF,aAAK,aAAa,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAChE,aAAK,YAAY,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,C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U,CAAC,MAAM,CAAC,EAAE,CAAA;KAAE;;;;;;;;;IAY7F,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY;;;;;;;;IAWlD,MAAM,CAAC,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY,GAAG;QAAE,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;KAAE;;;;0BAAzD,gBAAgB,MAAM,CAAC,KAAG,QAAQ,WAAW,MAAM,CAAC,EAAE,CAAC;;;;;;IAa3I,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY,GAAG;QAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,CAAA;KAAE;;;;;;;;;IAY9F,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY;;;;;;;;IAWnD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,gBAAgB;;;;;;IASpC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,gBAAgB;;;;;;IASvC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG;QAAE,YAAY,EAAE,OAAO,CAAC,WAAW,EAAE,CAAA;KAAE;;;;;;;IAU9E,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB;;;;;;IASjC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB;;;;;;IASxC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB;;;;;;CAQlC"}
|
|
@@ -128,6 +128,14 @@ class DBIChatInputOptions {
|
|
|
128
128
|
required: cfg.required
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
+
static role(cfg) {
|
|
132
|
+
return {
|
|
133
|
+
type: discord_js_1.default.ApplicationCommandOptionType.Role,
|
|
134
|
+
name: cfg.name,
|
|
135
|
+
description: cfg.description,
|
|
136
|
+
required: cfg.required
|
|
137
|
+
};
|
|
138
|
+
}
|
|
131
139
|
static mentionable(cfg) {
|
|
132
140
|
return {
|
|
133
141
|
type: discord_js_1.default.ApplicationCommandOptionType.Mentionable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatInputOptions.js","sourceRoot":"","sources":["../../../src/types/ChatInput/ChatInputOptions.ts"],"names":[],"mappings":";;;;AAAA,oEAAiC;AAcjC,MAAa,mBAAmB;IAC9B,MAAM,CAAC,kBAAkB,CAAC,GAAmH;QAC3I,OAAO;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,MAAM;YACjD,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,GAAyE;QAC5F,OAAO;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,MAAM;YACjD,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAqC;QACjD,OAAO;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,MAAM;YACjD,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,GAAG,CAAC,SAAS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O;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,IAAI;YAC/C,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAqB;QACtC,OAAO;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,WAAW;YACtD,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAqB;QAC/B,OAAO;YACL,IAAI,EAAE,oBAAO,CAAC,4BAA4B,CAAC,IAAI;YAC/C,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;CACF;AAlKD,kDAkKC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { IDBIBaseExecuteCtx } from \"../Interaction\";\r\n\r\ntype TValueName<T> = { value: T, name: string };\r\ntype TNameDescription = { name: string, description: string, required?: boolean };\r\n\r\ntype TMinMaxLength = { maxLength?: number, minLength?: number };\r\ntype TMinMaxValue = { maxValue?: number, minValue?: number };\r\n\r\nexport interface IDBICompleteCtx<TValueType = string | number> extends IDBIBaseExecuteCtx {\r\n interaction: Discord.AutocompleteInteraction;\r\n value: TValueType;\r\n}\r\n\r\nexport class DBIChatInputOptions {\r\n static stringAutocomplete(cfg: TNameDescription & TMinMaxLength & { onComplete(ctx: IDBICompleteCtx<string>): Promise<TValueName<string>[]> }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.String,\r\n name: cfg.name,\r\n autocomplete: true,\r\n onComplete: cfg.onComplete,\r\n description: cfg.description,\r\n maxLength: cfg.maxLength,\r\n minLength: cfg.minLength,\r\n required: cfg.required\r\n };\r\n }\r\n static stringChoices(cfg: TNameDescription & TMinMaxLength & { choices: TValueName<string>[] }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.String,\r\n name: cfg.name,\r\n choices: cfg.choices,\r\n description: cfg.description,\r\n maxLength: cfg.maxLength,\r\n minLength: cfg.minLength,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static string(cfg: TNameDescription & TMinMaxLength) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.String,\r\n name: cfg.name,\r\n description: cfg.description,\r\n maxLength: cfg.maxLength,\r\n minLength: cfg.minLength,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static numberAutocomplete(cfg: TNameDescription & TMinMaxValue & { onComplete(ctx: IDBICompleteCtx<string>): Promise<TValueName<number>[]> }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Number,\r\n name: cfg.name,\r\n autocomplete: true,\r\n onComplete: cfg.onComplete,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static numberChoices(cfg: TNameDescription & TMinMaxValue & { choices: TValueName<number>[] }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Number,\r\n name: cfg.name,\r\n choices: cfg.choices,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static number(cfg: TNameDescription & TMinMaxValue) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Number,\r\n name: cfg.name,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static integerAutocomplete(cfg: TNameDescription & TMinMaxValue & { onComplete(ctx: IDBICompleteCtx<string>): Promise<TValueName<number>[]> }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Integer,\r\n name: cfg.name,\r\n autocomplete: true,\r\n onComplete: cfg.onComplete,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static integerChoices(cfg: TNameDescription & TMinMaxValue & { choices: TValueName<number>[] }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Integer,\r\n name: cfg.name,\r\n choices: cfg.choices,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static integer(cfg: TNameDescription & TMinMaxValue) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Integer,\r\n name: cfg.name,\r\n description: cfg.description,\r\n maxValue: cfg.maxValue,\r\n minValue: cfg.minValue,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static boolean(cfg: TNameDescription) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Boolean,\r\n name: cfg.name,\r\n description: cfg.description,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static attachment(cfg: TNameDescription) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Attachment,\r\n name: cfg.name,\r\n description: cfg.description,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static channel(cfg: TNameDescription & { channelTypes: Discord.ChannelType[] }) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Channel,\r\n name: cfg.name,\r\n description: cfg.description,\r\n channelTypes: cfg.channelTypes,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static role(cfg: TNameDescription) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Role,\r\n name: cfg.name,\r\n description: cfg.description,\r\n required: cfg.required\r\n }\r\n }\r\n\r\n static mentionable(cfg: TNameDescription) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.Mentionable,\r\n name: cfg.name,\r\n description: cfg.description,\r\n required: cfg.required\r\n };\r\n }\r\n\r\n static user(cfg: TNameDescription) {\r\n return {\r\n type: Discord.ApplicationCommandOptionType.User,\r\n name: cfg.name,\r\n description: cfg.description,\r\n required: cfg.required\r\n };\r\n }\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionLocale.d.ts","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,oBAAY,yBAAyB,GAAG;KACrC,CAAC,IAAI,gBAAgB,CAAC,CAAC,EAAE;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE;YACR,CAAC,CAAC,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"InteractionLocale.d.ts","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,oBAAY,yBAAyB,GAAG;KACrC,CAAC,IAAI,gBAAgB,CAAC,CAAC,EAAE;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE;YACR,CAAC,CAAC,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,EAAE,MAAM,CAAC;gBACpB,OAAO,CAAC,EAAE;oBACR,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;iBACpB,CAAA;aACF,CAAA;SACF,CAAA;KACF;CACF,CAAC;AAEF,oBAAY,4BAA4B,GAAG,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;AAE7E,qBAAa,oBAAoB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,yBAAyB,CAAC;IAChC,GAAG,EAAE,GAAG,CAAC;gBACG,GAAG,KAAA,EAAE,GAAG,EAAE,4BAA4B;CAKnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionLocale.js","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"InteractionLocale.js","sourceRoot":"","sources":["../../src/types/InteractionLocale.ts"],"names":[],"mappings":";;;AAqBA,MAAa,oBAAoB;IAC/B,IAAI,CAAS;IACb,IAAI,CAA4B;IAChC,GAAG,CAAM;IACT,YAAY,GAAG,EAAE,GAAiC;QAChD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AATD,oDASC","sourcesContent":["import { DBI } from \"../DBI\";\r\nimport { TDBILocaleString } from \"./Locale\";\r\n\r\nexport type TDBIInteractionLocaleData = {\r\n [K in TDBILocaleString]?: {\r\n name: string;\r\n description: string;\r\n options?: {\r\n [k: string]: {\r\n name: string;\r\n description: string;\r\n choices?: {\r\n [k: string]: string\r\n }\r\n }\r\n }\r\n };\r\n};\r\n\r\nexport type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, \"dbi\">;\r\n\r\nexport class DBIInteractionLocale {\r\n name: string;\r\n data: TDBIInteractionLocaleData;\r\n dbi: DBI;\r\n constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {\r\n this.dbi = dbi;\r\n this.name = cfg.name;\r\n this.data = cfg.data;\r\n }\r\n}"]}
|
package/dist/types/Locale.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { DBI } from "../DBI";
|
|
2
|
-
export interface
|
|
3
|
-
[property: string]:
|
|
2
|
+
export interface DBILangObject {
|
|
3
|
+
[property: string]: DBILangObject & ((...args: any[]) => string);
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
6
|
-
[property: string]:
|
|
5
|
+
export interface DBILangConstructorObject {
|
|
6
|
+
[property: string]: DBILangConstructorObject | string;
|
|
7
7
|
}
|
|
8
8
|
export declare type TDBILocaleString = "en" | "bg" | "zh" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ro" | "ru" | "es" | "sv" | "th" | "tr" | "uk" | "vi";
|
|
9
9
|
export declare type TDBILocaleConstructor = Omit<DBILocale, "data" | "dbi"> & {
|
|
10
|
-
data:
|
|
10
|
+
data: DBILangConstructorObject;
|
|
11
11
|
};
|
|
12
12
|
export declare class DBILocale {
|
|
13
13
|
name: TDBILocaleString;
|
|
14
|
-
data:
|
|
14
|
+
data: DBILangObject;
|
|
15
15
|
private _data;
|
|
16
16
|
dbi: DBI;
|
|
17
17
|
constructor(dbi: DBI, cfg: TDBILocaleConstructor);
|
|
18
18
|
}
|
|
19
|
-
export declare function convertLang(data:
|
|
19
|
+
export declare function convertLang(data: DBILangConstructorObject): DBILangObject;
|
|
20
20
|
//# sourceMappingURL=Locale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Locale.d.ts","sourceRoot":"","sources":["../../src/types/Locale.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"Locale.d.ts","sourceRoot":"","sources":["../../src/types/Locale.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,MAAM,WAAW,aAAa;IAC5B,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,wBAAwB;IACvC,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,GAAG,MAAM,CAAC;CACvD;AAED,oBAAY,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1N,oBAAY,qBAAqB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,wBAAwB,CAAA;CAAE,CAAC;AAEzG,qBAAa,SAAS;IACpB,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,CAAC,KAAK,CAAC;IACd,GAAG,EAAE,GAAG,CAAC;gBACG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,qBAAqB;CAMjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,wBAAwB,GAAG,aAAa,CAUzE"}
|
package/dist/types/Locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../src/types/Locale.ts"],"names":[],"mappings":";;;;AAAA,aAAa;AACb,uDAAiC;AAejC,MAAa,SAAS;IACpB,IAAI,CAAmB;IACvB,IAAI,
|
|
1
|
+
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../src/types/Locale.ts"],"names":[],"mappings":";;;;AAAA,aAAa;AACb,uDAAiC;AAejC,MAAa,SAAS;IACpB,IAAI,CAAmB;IACvB,IAAI,CAAgB;IACZ,KAAK,CAAC;IACd,GAAG,CAAM;IACT,YAAY,GAAQ,EAAE,GAA0B;QAC9C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,IAAW,CAAC,CAAC;IAC3C,CAAC;CACF;AAXD,8BAWC;AAED,SAAgB,WAAW,CAAC,IAA8B;IACxD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAClE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;oBAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;gBACxF,CAAC,CAAC,CAAA;SACH;aAAM;YACL,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;SAClC;IACH,CAAC,CAAC,CAAC,CAAA;AACL,CAAC;AAVD,kCAUC","sourcesContent":["// @ts-ignore\r\nimport * as stuffs from \"stuffs\";\r\nimport { DBI } from \"../DBI\";\r\n\r\nexport interface DBILangObject {\r\n [property: string]: DBILangObject & ((...args: any[]) => string);\r\n}\r\n\r\nexport interface DBILangConstructorObject {\r\n [property: string]: DBILangConstructorObject | string;\r\n}\r\n\r\nexport type TDBILocaleString = \"en\" | \"bg\" | \"zh\" | \"hr\" | \"cs\" | \"da\" | \"nl\" | \"fi\" | \"fr\" | \"de\" | \"el\" | \"hi\" | \"hu\" | \"it\" | \"ja\" | \"ko\" | \"no\" | \"pl\" | \"pt\" | \"ro\" | \"ru\" | \"es\" | \"sv\" | \"th\" | \"tr\" | \"uk\" | \"vi\";\r\n\r\nexport type TDBILocaleConstructor = Omit<DBILocale, \"data\" | \"dbi\"> & { data: DBILangConstructorObject };\r\n\r\nexport class DBILocale {\r\n name: TDBILocaleString;\r\n data: DBILangObject;\r\n private _data;\r\n dbi: DBI;\r\n constructor(dbi: DBI, cfg: TDBILocaleConstructor) {\r\n this.dbi = dbi;\r\n this.name = cfg.name;\r\n this._data = cfg.data;\r\n this.data = convertLang(cfg.data as any);\r\n }\r\n}\r\n\r\nexport function convertLang(data: DBILangConstructorObject): DBILangObject {\r\n return Object.fromEntries(Object.entries(data).map(([key, value]) => {\r\n if (typeof value === \"string\") {\r\n return [key, (...args: any[]) => {\r\n return stuffs.mapReplace(value, Object.fromEntries(args.map((t, i) => [`{${i}}`, t])))\r\n }]\r\n } else {\r\n return [key, convertLang(value)];\r\n }\r\n }))\r\n}\r\n"]}
|
package/package.json
CHANGED
package/src/DBI.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { DBIEvent, TDBIEventOmitted } from "./types/Event";
|
|
|
6
6
|
import { MemoryStore } from "./utils/MemoryStore";
|
|
7
7
|
import { hookInteractionListeners } from "./methods/hookInteractionListeners";
|
|
8
8
|
import { Events } from "./Events";
|
|
9
|
-
import { DBILocale, TDBILocaleConstructor, TDBILocaleString } from "./types/Locale";
|
|
9
|
+
import { DBILocale, DBILangConstructorObject, TDBILocaleConstructor, TDBILocaleString } from "./types/Locale";
|
|
10
10
|
import { DBIButton, TDBIButtonOmitted } from "./types/Button";
|
|
11
11
|
import { DBISelectMenu, TDBISelectMenuOmitted } from "./types/SelectMenu";
|
|
12
12
|
import { DBIMessageContextMenu, TDBIMessageContextMenuOmitted } from "./types/MessageContextMenu";
|
|
@@ -41,6 +41,8 @@ export interface DBIConfig {
|
|
|
41
41
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
42
42
|
*/
|
|
43
43
|
store: DBIStore;
|
|
44
|
+
|
|
45
|
+
clearRefsAfter?: number;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export interface DBIConfigConstructor {
|
|
@@ -59,6 +61,8 @@ export interface DBIConfigConstructor {
|
|
|
59
61
|
* Persist store. (Default to MemoryStore thats not persis tho.)
|
|
60
62
|
*/
|
|
61
63
|
store?: DBIStore;
|
|
64
|
+
|
|
65
|
+
clearRefsAfter?: number;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
export interface DBIRegisterAPI {
|
|
@@ -75,12 +79,14 @@ export interface DBIRegisterAPI {
|
|
|
75
79
|
onUnload(cb: () => Promise<any> | any): any;
|
|
76
80
|
}
|
|
77
81
|
|
|
82
|
+
export type TDBIInteractions = DBIChatInput | DBIButton | DBISelectMenu | DBIMessageContextMenu | DBIUserContextMenu | DBIModal;
|
|
83
|
+
|
|
78
84
|
export class DBI<TOtherData = Record<string, any>> {
|
|
79
85
|
namespace: string;
|
|
80
86
|
config: DBIConfig;
|
|
81
87
|
client: Discord.Client<true>;
|
|
82
88
|
data: {
|
|
83
|
-
interactions: Discord.Collection<string,
|
|
89
|
+
interactions: Discord.Collection<string, TDBIInteractions>;
|
|
84
90
|
events: Discord.Collection<string, DBIEvent>;
|
|
85
91
|
plugins: Discord.Collection<string, any>;
|
|
86
92
|
locales: Discord.Collection<string, DBILocale>;
|
|
@@ -95,6 +101,7 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
95
101
|
events: Events;
|
|
96
102
|
cluster?: Sharding.Client;
|
|
97
103
|
private _loaded: boolean;
|
|
104
|
+
private _hooked: boolean;
|
|
98
105
|
constructor(namespace: string, config: DBIConfigConstructor) {
|
|
99
106
|
this.namespace = namespace;
|
|
100
107
|
|
|
@@ -124,7 +131,7 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
124
131
|
refs: new Map()
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
this.events = new Events(this);
|
|
134
|
+
this.events = new Events(this as any);
|
|
128
135
|
this.client = new Discord.Client({
|
|
129
136
|
...(config.discord?.options || {}) as any,
|
|
130
137
|
...(config.sharding ? {
|
|
@@ -133,13 +140,37 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
133
140
|
} : {})
|
|
134
141
|
});
|
|
135
142
|
this.cluster = config.sharding ? new Sharding.Client(this.client) : undefined;
|
|
136
|
-
this._hookListeners();
|
|
137
143
|
this._loaded = false;
|
|
144
|
+
this._hooked = false;
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
private async _hookListeners() {
|
|
141
|
-
this.
|
|
142
|
-
this.
|
|
148
|
+
if (this._hooked) return;
|
|
149
|
+
this._hooked = true;
|
|
150
|
+
this.data.unloaders.add(hookInteractionListeners(this as any));
|
|
151
|
+
this.data.unloaders.add(hookEventListeners(this as any));
|
|
152
|
+
if (typeof this.config.clearRefsAfter == "number") {
|
|
153
|
+
this.data.unloaders.add((() => {
|
|
154
|
+
let interval = setInterval(() => {
|
|
155
|
+
this.data.refs.forEach(({ at }, key) => {
|
|
156
|
+
if (Date.now() > (at + this.config.clearRefsAfter)) {
|
|
157
|
+
this.data.refs.delete(key);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}, 60000);
|
|
161
|
+
return () => {
|
|
162
|
+
clearInterval(interval);
|
|
163
|
+
}
|
|
164
|
+
})());
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async _unhookListeners() {
|
|
169
|
+
if (!this._hooked) return;
|
|
170
|
+
this._hooked = false;
|
|
171
|
+
this.data.unloaders.forEach(f => {
|
|
172
|
+
f();
|
|
173
|
+
});
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
private async _unregisterAll() {
|
|
@@ -152,7 +183,7 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
152
183
|
}
|
|
153
184
|
|
|
154
185
|
private async _registerAll() {
|
|
155
|
-
const self = this;
|
|
186
|
+
const self = this as any;
|
|
156
187
|
|
|
157
188
|
for await (const cb of this.data.registers) {
|
|
158
189
|
let ChatInput = function(cfg: DBIChatInput) {
|
|
@@ -245,6 +276,34 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
245
276
|
}
|
|
246
277
|
}
|
|
247
278
|
|
|
279
|
+
/**
|
|
280
|
+
* this.data.interactions.get(name)
|
|
281
|
+
*/
|
|
282
|
+
interaction(name: string): TDBIInteractions {
|
|
283
|
+
return this.data.interactions.get(name);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* this.data.events.get(name)
|
|
288
|
+
*/
|
|
289
|
+
event(name: string): DBIEvent {
|
|
290
|
+
return this.data.events.get(name);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* this.data.locales.get(name)
|
|
295
|
+
*/
|
|
296
|
+
locale(name: string): DBILocale {
|
|
297
|
+
return this.data.locales.get(name);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* this.data.plugins.get(name)
|
|
302
|
+
*/
|
|
303
|
+
plugin(name: string): any {
|
|
304
|
+
return this.data.plugins.get(name);
|
|
305
|
+
}
|
|
306
|
+
|
|
248
307
|
/**
|
|
249
308
|
* Shorthands for modifying `dbi.data.other`
|
|
250
309
|
*/
|
|
@@ -288,6 +347,7 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
288
347
|
async load(): Promise<boolean> {
|
|
289
348
|
if (this._loaded) return false;
|
|
290
349
|
await this._registerAll();
|
|
350
|
+
await this._hookListeners();
|
|
291
351
|
this._loaded = true;
|
|
292
352
|
return true;
|
|
293
353
|
}
|
|
@@ -295,6 +355,7 @@ export class DBI<TOtherData = Record<string, any>> {
|
|
|
295
355
|
async unload(): Promise<boolean> {
|
|
296
356
|
if (!this._loaded) return false;
|
|
297
357
|
await this._unregisterAll();
|
|
358
|
+
await this._unhookListeners();
|
|
298
359
|
this._loaded = false;
|
|
299
360
|
return true;
|
|
300
361
|
}
|
|
@@ -171,8 +171,6 @@ export async function publishInteractions(
|
|
|
171
171
|
return all;
|
|
172
172
|
}, []);
|
|
173
173
|
|
|
174
|
-
body = snakecaseKeys(body);
|
|
175
|
-
|
|
176
174
|
switch (publishType) {
|
|
177
175
|
case "Global": {
|
|
178
176
|
await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body });
|
|
@@ -188,9 +186,16 @@ export async function publishInteractions(
|
|
|
188
186
|
|
|
189
187
|
export function localeifyOptions(options: any[], localeData: any): any[] {
|
|
190
188
|
return options.map(i => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
let optionData = localeData[i.name];
|
|
190
|
+
return optionData ? Object.assign(i, {
|
|
191
|
+
name_localizations: optionData.nameLocales,
|
|
192
|
+
description_localizations: optionData.descriptionLocales,
|
|
193
|
+
choices: i.choices ? i.choices.map((j) => {
|
|
194
|
+
let choiceLocale = optionData.choiceLocales[j.name];
|
|
195
|
+
return choiceLocale ? Object.assign(j, {
|
|
196
|
+
name_localizations: choiceLocale
|
|
197
|
+
}) : j;
|
|
198
|
+
}) : undefined
|
|
194
199
|
}) : i;
|
|
195
200
|
})
|
|
196
201
|
}
|
|
@@ -218,11 +223,21 @@ export function formatLocale(locale: DBIInteractionLocale): any {
|
|
|
218
223
|
descriptionLocales[longLocale] = localeData.description;
|
|
219
224
|
Object.entries(localeData.options || []).forEach(([optionName, optionData]) => {
|
|
220
225
|
if (!optionsLocales[optionName]) optionsLocales[optionName] = {};
|
|
221
|
-
|
|
222
|
-
if (!
|
|
226
|
+
let optionLocale = optionsLocales[optionName];
|
|
227
|
+
if (!optionLocale.nameLocales) optionLocale.nameLocales = {};
|
|
228
|
+
if (!optionLocale.descriptionLocales) optionLocale.descriptionLocales = {};
|
|
229
|
+
if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};
|
|
230
|
+
|
|
231
|
+
Object.entries(optionData.choices).forEach(([choiceOriginalName, choiceName]) => {
|
|
232
|
+
if (!optionLocale.choiceLocales) optionLocale.choiceLocales = {};
|
|
233
|
+
if (!optionLocale.choiceLocales[choiceOriginalName]) optionLocale.choiceLocales[choiceOriginalName] = {};
|
|
234
|
+
let choiceLocale = optionLocale.choiceLocales[choiceOriginalName];
|
|
235
|
+
|
|
236
|
+
choiceLocale[longLocale] = choiceName;
|
|
237
|
+
});
|
|
223
238
|
|
|
224
|
-
|
|
225
|
-
|
|
239
|
+
optionLocale.nameLocales[longLocale] = optionData.name;
|
|
240
|
+
optionLocale.descriptionLocales[longLocale] = optionData.description;
|
|
226
241
|
})
|
|
227
242
|
});
|
|
228
243
|
});
|
|
@@ -148,6 +148,15 @@ export class DBIChatInputOptions {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
static role(cfg: TNameDescription) {
|
|
152
|
+
return {
|
|
153
|
+
type: Discord.ApplicationCommandOptionType.Role,
|
|
154
|
+
name: cfg.name,
|
|
155
|
+
description: cfg.description,
|
|
156
|
+
required: cfg.required
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
151
160
|
static mentionable(cfg: TNameDescription) {
|
|
152
161
|
return {
|
|
153
162
|
type: Discord.ApplicationCommandOptionType.Mentionable,
|
package/src/types/Locale.ts
CHANGED
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
import * as stuffs from "stuffs";
|
|
3
3
|
import { DBI } from "../DBI";
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
[property: string]:
|
|
5
|
+
export interface DBILangObject {
|
|
6
|
+
[property: string]: DBILangObject & ((...args: any[]) => string);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export interface
|
|
10
|
-
[property: string]:
|
|
9
|
+
export interface DBILangConstructorObject {
|
|
10
|
+
[property: string]: DBILangConstructorObject | string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type TDBILocaleString = "en" | "bg" | "zh" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ro" | "ru" | "es" | "sv" | "th" | "tr" | "uk" | "vi";
|
|
14
14
|
|
|
15
|
-
export type TDBILocaleConstructor = Omit<DBILocale, "data" | "dbi"> & { data:
|
|
15
|
+
export type TDBILocaleConstructor = Omit<DBILocale, "data" | "dbi"> & { data: DBILangConstructorObject };
|
|
16
16
|
|
|
17
17
|
export class DBILocale {
|
|
18
18
|
name: TDBILocaleString;
|
|
19
|
-
data:
|
|
20
|
-
private _data
|
|
19
|
+
data: DBILangObject;
|
|
20
|
+
private _data;
|
|
21
21
|
dbi: DBI;
|
|
22
22
|
constructor(dbi: DBI, cfg: TDBILocaleConstructor) {
|
|
23
23
|
this.dbi = dbi;
|
|
24
24
|
this.name = cfg.name;
|
|
25
25
|
this._data = cfg.data;
|
|
26
|
-
this.data = convertLang(cfg.data);
|
|
26
|
+
this.data = convertLang(cfg.data as any);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function convertLang(data:
|
|
30
|
+
export function convertLang(data: DBILangConstructorObject): DBILangObject {
|
|
31
31
|
return Object.fromEntries(Object.entries(data).map(([key, value]) => {
|
|
32
32
|
if (typeof value === "string") {
|
|
33
33
|
return [key, (...args: any[]) => {
|