@mostfeatured/dbi 0.1.6 → 0.1.8
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 +1 -1
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +37 -21
- package/dist/DBI.js.map +1 -1
- package/dist/methods/publishInteractions.js +9 -9
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/Event.d.ts +1 -0
- package/dist/types/Event.d.ts.map +1 -1
- package/dist/types/Event.js +2 -0
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +4 -8
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js +3 -8
- package/dist/types/Interaction.js.map +1 -1
- package/dist/types/other/FakeMessageInteraction.js +1 -1
- package/dist/types/other/FakeMessageInteraction.js.map +1 -1
- package/dist/types/other/InteractionLocale.d.ts +1 -0
- package/dist/types/other/InteractionLocale.d.ts.map +1 -1
- package/dist/types/other/InteractionLocale.js +2 -0
- package/dist/types/other/InteractionLocale.js.map +1 -1
- package/dist/types/other/Locale.d.ts +1 -0
- package/dist/types/other/Locale.d.ts.map +1 -1
- package/dist/types/other/Locale.js +2 -0
- package/dist/types/other/Locale.js.map +1 -1
- package/package.json +1 -1
- package/src/DBI.ts +73 -56
- package/src/methods/publishInteractions.ts +8 -8
- package/src/types/Event.ts +2 -0
- package/src/types/Interaction.ts +6 -21
- package/src/types/other/FakeMessageInteraction.ts +1 -1
- package/src/types/other/InteractionLocale.ts +2 -0
- package/src/types/other/Locale.ts +2 -0
- package/tsconfig.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../../src/types/other/Locale.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAiB5B,MAAa,SAAS;IACpB,IAAI,CAAmB;IACvB,IAAI,CAA6C;IACzC,KAAK,CAA2B;IACxC,GAAG,CAAsB;IACzB,YAAY,GAAwB,EAAE,GAAsC;QAC1E,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,CAAa,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,WAAW,CAAC,MAA6B;QACvC,IAAI,CAAC,KAAK,GAAG,gBAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAQ,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,WAAW,CAAa,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAE1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../../src/types/other/Locale.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAiB5B,MAAa,SAAS;IACpB,IAAI,CAAmB;IACvB,IAAI,CAA6C;IACzC,KAAK,CAA2B;IACxC,GAAG,CAAsB;IACzB,IAAI,CAAoB;IACxB,YAAY,GAAwB,EAAE,GAAsC;QAC1E,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAa,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,WAAW,CAAC,MAA6B;QACvC,IAAI,CAAC,KAAK,GAAG,gBAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAQ,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,WAAW,CAAa,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAE1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtBD,8BAsBC;AAED,SAAgB,WAAW,CAAoC,IAA8B;IAC3F,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,gBAAM,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;gBAClG,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;SAClC;IACH,CAAC,CAAC,CAAC,CAAA;AACL,CAAC;AAVD,kCAUC","sourcesContent":["import stuffs from \"stuffs\";\r\nimport { NamespaceData, NamespaceEnums } from \"../../../generated/namespaceData\";\r\nimport { DBI } from \"../../DBI\";\r\n\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<TNamespace extends NamespaceEnums> = Omit<DBILocale<TNamespace>, \"data\" | \"dbi\" | \"mergeLocale\"> & { data: DBILangConstructorObject };\r\n\r\nexport class DBILocale<TNamespace extends NamespaceEnums> {\r\n name: TDBILocaleString;\r\n data: NamespaceData[TNamespace][\"contentLocale\"];\r\n private _data: DBILangConstructorObject;\r\n dbi: DBI<TNamespace, {}>;\r\n flag: string | undefined\r\n constructor(dbi: DBI<TNamespace, {}>, cfg: TDBILocaleConstructor<TNamespace>) {\r\n this.dbi = dbi;\r\n this.name = cfg.name;\r\n this.flag = cfg.flag;\r\n this._data = cfg.data;\r\n this.data = convertLang<TNamespace>(cfg.data);\r\n }\r\n mergeLocale(locale: DBILocale<TNamespace>): DBILocale<TNamespace> {\r\n this._data = stuffs.defaultify(locale._data, this._data, true) as any;\r\n this.data = convertLang<TNamespace>(this._data);\r\n\r\n locale.data = this.data;\r\n locale._data = this._data;\r\n\r\n return this;\r\n }\r\n}\r\n\r\nexport function convertLang<TNamespace extends NamespaceEnums>(data: DBILangConstructorObject): NamespaceData[TNamespace][\"contentLocale\"] {\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, args.map((t, i) => [new RegExp(`\\\\{${i}(;[^}]+)?\\\\}`, \"g\"), 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
|
@@ -111,15 +111,15 @@ export interface DBIConfig {
|
|
|
111
111
|
|
|
112
112
|
export interface DBIConfigConstructor {
|
|
113
113
|
discord:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
| {
|
|
115
|
+
token: string;
|
|
116
|
+
options: Discord.ClientOptions;
|
|
117
|
+
}
|
|
118
|
+
| {
|
|
119
|
+
namespace: string;
|
|
120
|
+
token: string;
|
|
121
|
+
options: Discord.ClientOptions;
|
|
122
|
+
}[];
|
|
123
123
|
|
|
124
124
|
defaults?: {
|
|
125
125
|
locale?: TDBILocaleString;
|
|
@@ -313,12 +313,12 @@ export class DBI<
|
|
|
313
313
|
config.discord = Array.isArray(config.discord)
|
|
314
314
|
? config.discord
|
|
315
315
|
: [
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
{
|
|
317
|
+
token: config.discord.token,
|
|
318
|
+
options: config.discord.options,
|
|
319
|
+
namespace: "default",
|
|
320
|
+
},
|
|
321
|
+
];
|
|
322
322
|
|
|
323
323
|
this.data.clients.push(...(config.discord as any));
|
|
324
324
|
for (let clientContext of this.data.clients) {
|
|
@@ -326,9 +326,9 @@ export class DBI<
|
|
|
326
326
|
...((clientContext.options || {}) as any),
|
|
327
327
|
...(config.sharding == "hybrid"
|
|
328
328
|
? {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
329
|
+
shards: Sharding.getInfo().SHARD_LIST,
|
|
330
|
+
shardCount: Sharding.getInfo().TOTAL_SHARDS,
|
|
331
|
+
}
|
|
332
332
|
: {}),
|
|
333
333
|
});
|
|
334
334
|
clientContext.client = client as Discord.Client<true>;
|
|
@@ -398,6 +398,7 @@ export class DBI<
|
|
|
398
398
|
this.data.unloaders.forEach((f) => {
|
|
399
399
|
f();
|
|
400
400
|
});
|
|
401
|
+
this.data.unloaders.clear();
|
|
401
402
|
}
|
|
402
403
|
|
|
403
404
|
private async _unregisterAll() {
|
|
@@ -406,13 +407,18 @@ export class DBI<
|
|
|
406
407
|
}
|
|
407
408
|
this.data.events.clear();
|
|
408
409
|
this.data.interactions.clear();
|
|
410
|
+
this.data.interactionLocales.clear();
|
|
411
|
+
this.data.locales.clear();
|
|
412
|
+
this.data.registerUnloaders.clear();
|
|
413
|
+
this.data.refs.clear();
|
|
414
|
+
|
|
409
415
|
this.data.customEventNames.forEach((value) => {
|
|
410
416
|
delete this.data.eventMap[value];
|
|
411
417
|
});
|
|
412
418
|
this.data.customEventNames.clear();
|
|
413
419
|
}
|
|
414
420
|
|
|
415
|
-
private async _registerAll() {
|
|
421
|
+
private async _registerAll(flags: string[] = []) {
|
|
416
422
|
const self = this;
|
|
417
423
|
const ChatInputOptions = new DBIChatInputOptions(self);
|
|
418
424
|
|
|
@@ -421,10 +427,11 @@ export class DBI<
|
|
|
421
427
|
let dbiChatInput = new DBIChatInput(self, cfg);
|
|
422
428
|
if (self.data.interactions.has(dbiChatInput.name))
|
|
423
429
|
throw new Error(
|
|
424
|
-
`DBIChatInput "${dbiChatInput.name}" already loaded as "${
|
|
430
|
+
`DBIChatInput "${dbiChatInput.name}" already loaded as "${
|
|
431
|
+
self.data.interactions.get(dbiChatInput.name)?.type
|
|
425
432
|
}"!`
|
|
426
433
|
);
|
|
427
|
-
self.data.interactions.set(dbiChatInput.name, dbiChatInput);
|
|
434
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiChatInput.name, dbiChatInput);
|
|
428
435
|
return dbiChatInput;
|
|
429
436
|
};
|
|
430
437
|
ChatInput = Object.assign(
|
|
@@ -445,7 +452,7 @@ export class DBI<
|
|
|
445
452
|
throw new Error(
|
|
446
453
|
`DBIEvent "${dbiEvent.id || dbiEvent.name}" already loaded!`
|
|
447
454
|
);
|
|
448
|
-
|
|
455
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.events.set(dbiEvent.id || dbiEvent.name, dbiEvent);
|
|
449
456
|
return dbiEvent;
|
|
450
457
|
};
|
|
451
458
|
Event = Object.assign(
|
|
@@ -461,10 +468,11 @@ export class DBI<
|
|
|
461
468
|
let dbiButton = new DBIButton(self as any, cfg);
|
|
462
469
|
if (self.config.strict && self.data.interactions.has(dbiButton.name))
|
|
463
470
|
throw new Error(
|
|
464
|
-
`DBIButton "${dbiButton.name}" already loaded as "${
|
|
471
|
+
`DBIButton "${dbiButton.name}" already loaded as "${
|
|
472
|
+
self.data.interactions.get(dbiButton.name)?.type
|
|
465
473
|
}"!`
|
|
466
474
|
);
|
|
467
|
-
|
|
475
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiButton.name, dbiButton as any);
|
|
468
476
|
return dbiButton;
|
|
469
477
|
};
|
|
470
478
|
Button = Object.assign(
|
|
@@ -485,11 +493,13 @@ export class DBI<
|
|
|
485
493
|
self.data.interactions.has(dbiStringSelectMenu.name)
|
|
486
494
|
)
|
|
487
495
|
throw new Error(
|
|
488
|
-
`DBIStringSelectMenu "${
|
|
489
|
-
|
|
496
|
+
`DBIStringSelectMenu "${
|
|
497
|
+
dbiStringSelectMenu.name
|
|
498
|
+
}" already loaded as "${
|
|
499
|
+
self.data.interactions.get(dbiStringSelectMenu.name)?.type
|
|
490
500
|
}"!`
|
|
491
501
|
);
|
|
492
|
-
self.data.interactions.set(
|
|
502
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
493
503
|
dbiStringSelectMenu.name,
|
|
494
504
|
dbiStringSelectMenu as any
|
|
495
505
|
);
|
|
@@ -513,10 +523,11 @@ export class DBI<
|
|
|
513
523
|
self.data.interactions.has(dbiUserSelectMenu.name)
|
|
514
524
|
)
|
|
515
525
|
throw new Error(
|
|
516
|
-
`DBIUserSelectMenu "${dbiUserSelectMenu.name}" already loaded as "${
|
|
526
|
+
`DBIUserSelectMenu "${dbiUserSelectMenu.name}" already loaded as "${
|
|
527
|
+
self.data.interactions.get(dbiUserSelectMenu.name)?.type
|
|
517
528
|
}"!`
|
|
518
529
|
);
|
|
519
|
-
self.data.interactions.set(
|
|
530
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
520
531
|
dbiUserSelectMenu.name,
|
|
521
532
|
dbiUserSelectMenu as any
|
|
522
533
|
);
|
|
@@ -540,10 +551,11 @@ export class DBI<
|
|
|
540
551
|
self.data.interactions.has(dbiRoleSelectMenu.name)
|
|
541
552
|
)
|
|
542
553
|
throw new Error(
|
|
543
|
-
`DBIRoleSelectMenu "${dbiRoleSelectMenu.name}" already loaded as "${
|
|
554
|
+
`DBIRoleSelectMenu "${dbiRoleSelectMenu.name}" already loaded as "${
|
|
555
|
+
self.data.interactions.get(dbiRoleSelectMenu.name)?.type
|
|
544
556
|
}"!`
|
|
545
557
|
);
|
|
546
|
-
self.data.interactions.set(
|
|
558
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
547
559
|
dbiRoleSelectMenu.name,
|
|
548
560
|
dbiRoleSelectMenu as any
|
|
549
561
|
);
|
|
@@ -567,11 +579,13 @@ export class DBI<
|
|
|
567
579
|
self.data.interactions.has(dbiChannelSelectMenu.name)
|
|
568
580
|
)
|
|
569
581
|
throw new Error(
|
|
570
|
-
`DBIChannelSelectMenu "${
|
|
571
|
-
|
|
582
|
+
`DBIChannelSelectMenu "${
|
|
583
|
+
dbiChannelSelectMenu.name
|
|
584
|
+
}" already loaded as "${
|
|
585
|
+
self.data.interactions.get(dbiChannelSelectMenu.name)?.type
|
|
572
586
|
}"!`
|
|
573
587
|
);
|
|
574
|
-
self.data.interactions.set(
|
|
588
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
575
589
|
dbiChannelSelectMenu.name,
|
|
576
590
|
dbiChannelSelectMenu as any
|
|
577
591
|
);
|
|
@@ -598,11 +612,13 @@ export class DBI<
|
|
|
598
612
|
self.data.interactions.has(dbiMentionableSelectMenu.name)
|
|
599
613
|
)
|
|
600
614
|
throw new Error(
|
|
601
|
-
`DBIMentionableSelectMenu "${
|
|
602
|
-
|
|
615
|
+
`DBIMentionableSelectMenu "${
|
|
616
|
+
dbiMentionableSelectMenu.name
|
|
617
|
+
}" already loaded as "${
|
|
618
|
+
self.data.interactions.get(dbiMentionableSelectMenu.name)?.type
|
|
603
619
|
}"!`
|
|
604
620
|
);
|
|
605
|
-
self.data.interactions.set(
|
|
621
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
606
622
|
dbiMentionableSelectMenu.name,
|
|
607
623
|
dbiMentionableSelectMenu as any
|
|
608
624
|
);
|
|
@@ -626,11 +642,13 @@ export class DBI<
|
|
|
626
642
|
self.data.interactions.has(dbiMessageContextMenu.name)
|
|
627
643
|
)
|
|
628
644
|
throw new Error(
|
|
629
|
-
`DBIMessageContextMenu "${
|
|
630
|
-
|
|
645
|
+
`DBIMessageContextMenu "${
|
|
646
|
+
dbiMessageContextMenu.name
|
|
647
|
+
}" already loaded as "${
|
|
648
|
+
self.data.interactions.get(dbiMessageContextMenu.name)?.type
|
|
631
649
|
}"!`
|
|
632
650
|
);
|
|
633
|
-
self.data.interactions.set(
|
|
651
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
634
652
|
dbiMessageContextMenu.name,
|
|
635
653
|
dbiMessageContextMenu as any
|
|
636
654
|
);
|
|
@@ -654,11 +672,13 @@ export class DBI<
|
|
|
654
672
|
self.data.interactions.has(dbiUserContextMenu.name)
|
|
655
673
|
)
|
|
656
674
|
throw new Error(
|
|
657
|
-
`DBIUserContextMenu "${
|
|
658
|
-
|
|
675
|
+
`DBIUserContextMenu "${
|
|
676
|
+
dbiUserContextMenu.name
|
|
677
|
+
}" already loaded as "${
|
|
678
|
+
self.data.interactions.get(dbiUserContextMenu.name)?.type
|
|
659
679
|
}"!`
|
|
660
680
|
);
|
|
661
|
-
self.data.interactions.set(
|
|
681
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(
|
|
662
682
|
dbiUserContextMenu.name,
|
|
663
683
|
dbiUserContextMenu as any
|
|
664
684
|
);
|
|
@@ -677,10 +697,11 @@ export class DBI<
|
|
|
677
697
|
let dbiModal = new DBIModal(self as any, cfg);
|
|
678
698
|
if (self.config.strict && self.data.interactions.has(dbiModal.name))
|
|
679
699
|
throw new Error(
|
|
680
|
-
`DBIModal "${dbiModal.name}" already loaded as "${
|
|
700
|
+
`DBIModal "${dbiModal.name}" already loaded as "${
|
|
701
|
+
self.data.interactions.get(dbiModal.name)?.type
|
|
681
702
|
}"!`
|
|
682
703
|
);
|
|
683
|
-
self.data.interactions.set(dbiModal.name, dbiModal as any);
|
|
704
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactions.set(dbiModal.name, dbiModal as any);
|
|
684
705
|
return dbiModal;
|
|
685
706
|
};
|
|
686
707
|
Modal = Object.assign(
|
|
@@ -701,7 +722,7 @@ export class DBI<
|
|
|
701
722
|
throw new Error(`DBILocale "${dbiLocale.name}" already loaded!`);
|
|
702
723
|
if (self.data.locales.has(dbiLocale.name))
|
|
703
724
|
dbiLocale.mergeLocale(self.data.locales.get(dbiLocale.name));
|
|
704
|
-
self.data.locales.set(dbiLocale.name, dbiLocale);
|
|
725
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.locales.set(dbiLocale.name, dbiLocale);
|
|
705
726
|
return dbiLocale;
|
|
706
727
|
};
|
|
707
728
|
Locale = Object.assign(
|
|
@@ -741,7 +762,7 @@ export class DBI<
|
|
|
741
762
|
throw new Error(
|
|
742
763
|
`DBIInteractionLocale "${dbiInteractionLocale.name}" already loaded!`
|
|
743
764
|
);
|
|
744
|
-
self.data.interactionLocales.set(
|
|
765
|
+
if (!cfg.flag || flags.includes("all") || flags.includes(cfg.flag)) self.data.interactionLocales.set(
|
|
745
766
|
dbiInteractionLocale.name,
|
|
746
767
|
dbiInteractionLocale
|
|
747
768
|
);
|
|
@@ -873,9 +894,9 @@ export class DBI<
|
|
|
873
894
|
this.data.registers.add(cb);
|
|
874
895
|
}
|
|
875
896
|
|
|
876
|
-
async load(): Promise<boolean> {
|
|
897
|
+
async load(...flags: string[]): Promise<boolean> {
|
|
877
898
|
if (this._loaded) return false;
|
|
878
|
-
await this._registerAll();
|
|
899
|
+
await this._registerAll(flags);
|
|
879
900
|
await this._hookListeners();
|
|
880
901
|
this._loaded = true;
|
|
881
902
|
return true;
|
|
@@ -899,13 +920,9 @@ export class DBI<
|
|
|
899
920
|
async publish(...args: any[]) {
|
|
900
921
|
let interactions = this.data.interactions.filter(
|
|
901
922
|
(i) =>
|
|
902
|
-
i.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
i.type == "ChatInput" ||
|
|
906
|
-
i.type == "MessageContextMenu" ||
|
|
907
|
-
i.type == "UserContextMenu"
|
|
908
|
-
)
|
|
923
|
+
i.type == "ChatInput" ||
|
|
924
|
+
i.type == "MessageContextMenu" ||
|
|
925
|
+
i.type == "UserContextMenu"
|
|
909
926
|
) as any;
|
|
910
927
|
switch (args[0]) {
|
|
911
928
|
case "Global": {
|
|
@@ -24,14 +24,14 @@ export async function publishInteractions(
|
|
|
24
24
|
|
|
25
25
|
let body: {[k: string]: RESTPutAPIApplicationCommandsJSONBody} =
|
|
26
26
|
interactions.reduce((all, current) => {
|
|
27
|
-
if (current.publish && !all[current.publish
|
|
27
|
+
if (current.publish && !all[current.publish]) all[current.publish] = [];
|
|
28
28
|
switch (current.type) {
|
|
29
29
|
case "ChatInput": {
|
|
30
30
|
let nameSplitted = current.name.split(" ");
|
|
31
31
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
32
32
|
switch (nameSplitted.length) {
|
|
33
33
|
case 1: {
|
|
34
|
-
all[current.publish
|
|
34
|
+
all[current.publish].push({
|
|
35
35
|
type: ApplicationCommandType.ChatInput,
|
|
36
36
|
description: current.description,
|
|
37
37
|
name: nameSplitted[0],
|
|
@@ -44,7 +44,7 @@ export async function publishInteractions(
|
|
|
44
44
|
break;
|
|
45
45
|
}
|
|
46
46
|
case 2: {
|
|
47
|
-
let baseItem = all[current.publish
|
|
47
|
+
let baseItem = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
48
48
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
49
49
|
let option = {
|
|
50
50
|
type: ApplicationCommandOptionType.Subcommand,
|
|
@@ -56,7 +56,7 @@ export async function publishInteractions(
|
|
|
56
56
|
description_localizations: localeData.descriptionLocales,
|
|
57
57
|
};
|
|
58
58
|
if (!baseItem) {
|
|
59
|
-
all[current.publish
|
|
59
|
+
all[current.publish].push({
|
|
60
60
|
type: ApplicationCommandType.ChatInput,
|
|
61
61
|
name: nameSplitted[0],
|
|
62
62
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
@@ -72,10 +72,10 @@ export async function publishInteractions(
|
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
case 3: {
|
|
75
|
-
let level1Item = all[current.publish
|
|
75
|
+
let level1Item = all[current.publish].find(i => i.name == current.name.split(" ")[0] && i.type == ApplicationCommandType.ChatInput);
|
|
76
76
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
77
77
|
if (!level1Item) {
|
|
78
|
-
all[current.publish
|
|
78
|
+
all[current.publish].push({
|
|
79
79
|
type: ApplicationCommandType.ChatInput,
|
|
80
80
|
name: nameSplitted[0],
|
|
81
81
|
name_localizations: localeData.nameLocales(0),
|
|
@@ -140,7 +140,7 @@ export async function publishInteractions(
|
|
|
140
140
|
}
|
|
141
141
|
case "MessageContextMenu": {
|
|
142
142
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
143
|
-
all[current.publish
|
|
143
|
+
all[current.publish].push({
|
|
144
144
|
type: ApplicationCommandType.Message,
|
|
145
145
|
name: current.name,
|
|
146
146
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
|
@@ -152,7 +152,7 @@ export async function publishInteractions(
|
|
|
152
152
|
}
|
|
153
153
|
case "UserContextMenu": {
|
|
154
154
|
let localeData = formatLocale(interactionsLocales.get(current.name) ?? {} as any);
|
|
155
|
-
all[current.publish
|
|
155
|
+
all[current.publish].push({
|
|
156
156
|
type: ApplicationCommandType.User,
|
|
157
157
|
name: current.name,
|
|
158
158
|
default_member_permissions: reducePermissions(current.defaultMemberPermissions).toString(),
|
package/src/types/Event.ts
CHANGED
|
@@ -112,6 +112,7 @@ export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
|
112
112
|
ordered?: boolean;
|
|
113
113
|
dbi: DBI<TNamespace>;
|
|
114
114
|
disabled: boolean = false;
|
|
115
|
+
flag: string | undefined;
|
|
115
116
|
constructor(dbi: DBI<TNamespace>, cfg: TDBIEventOmitted<TNamespace>) {
|
|
116
117
|
this.dbi = dbi;
|
|
117
118
|
this.type = "Event";
|
|
@@ -122,6 +123,7 @@ export class DBIEvent<TNamespace extends NamespaceEnums> {
|
|
|
122
123
|
this.ordered = cfg.ordered ?? false;
|
|
123
124
|
this.triggerType = cfg.triggerType ?? "OneByOneGlobal";
|
|
124
125
|
this.disabled ??= cfg.disabled;
|
|
126
|
+
this.flag = cfg.flag;
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
toggle(disabled?: boolean) {
|
package/src/types/Interaction.ts
CHANGED
|
@@ -54,7 +54,7 @@ export type TDBIRateLimitTypes =
|
|
|
54
54
|
| "Message";
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
export type
|
|
57
|
+
export type DBIRateLimit = {
|
|
58
58
|
type: TDBIRateLimitTypes;
|
|
59
59
|
/**
|
|
60
60
|
* Duration in milliseconds.
|
|
@@ -62,18 +62,6 @@ export type TDBIRateLimit = {
|
|
|
62
62
|
duration: number;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export type TDBIPublishTypes =
|
|
66
|
-
| "Guild"
|
|
67
|
-
| "Global"
|
|
68
|
-
| "None"
|
|
69
|
-
| "All";
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export type TDBIPublish = {
|
|
73
|
-
type: TDBIPublishTypes;
|
|
74
|
-
to: NamespaceData[NamespaceEnums]["clientNamespaces"];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
65
|
export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
78
66
|
constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, "dbi">) {
|
|
79
67
|
this.dbi = dbi;
|
|
@@ -83,23 +71,20 @@ export class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
|
83
71
|
this.type = cfg.type;
|
|
84
72
|
this.options = cfg.options;
|
|
85
73
|
this.other = cfg.other;
|
|
86
|
-
this.publish = cfg.publish ??
|
|
87
|
-
to: dbi.data.clients.first()?.namespace,
|
|
88
|
-
type: "All"
|
|
89
|
-
};
|
|
90
|
-
if (!this.publish.to) this.publish.to = dbi.data.clients.first()?.namespace;
|
|
91
|
-
if (!this.publish.type) this.publish.type = "All";
|
|
74
|
+
this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;
|
|
92
75
|
this.rateLimits = cfg.rateLimits ?? [];
|
|
76
|
+
this.flag = cfg.flag;
|
|
93
77
|
}
|
|
94
78
|
|
|
95
|
-
publish?:
|
|
79
|
+
publish?: NamespaceData[TNamespace]["clientNamespaces"];
|
|
96
80
|
dbi: DBI<TNamespace>;
|
|
97
81
|
name: string;
|
|
98
82
|
description: string;
|
|
99
83
|
readonly type: TDBIInteractionTypes;
|
|
100
84
|
options?: any | any[];
|
|
101
85
|
other?: Record<string, any> & { messageCommand?: { aliases?: string[] } };
|
|
102
|
-
rateLimits?:
|
|
86
|
+
rateLimits?: DBIRateLimit[];
|
|
87
|
+
flag: string | undefined;
|
|
103
88
|
toJSON(overrides: any): any { }
|
|
104
89
|
|
|
105
90
|
onExecute(ctx: IDBIBaseExecuteCtx<TNamespace>): Promise<void> | void {
|
|
@@ -131,7 +131,7 @@ export class FakeMessageInteraction /* implements ChatInputCommandInteraction */
|
|
|
131
131
|
};
|
|
132
132
|
},
|
|
133
133
|
get _hoistedOptions() {
|
|
134
|
-
return
|
|
134
|
+
return self._hoistedOptions;
|
|
135
135
|
},
|
|
136
136
|
getSubcommand() {
|
|
137
137
|
let splitted = self.fullCommandName.split(" ");
|
|
@@ -24,9 +24,11 @@ export class DBIInteractionLocale {
|
|
|
24
24
|
name: string;
|
|
25
25
|
data: TDBIInteractionLocaleData;
|
|
26
26
|
dbi: DBI<NamespaceEnums>;
|
|
27
|
+
flag: string | undefined;
|
|
27
28
|
constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {
|
|
28
29
|
this.dbi = dbi;
|
|
29
30
|
this.name = cfg.name;
|
|
30
31
|
this.data = cfg.data;
|
|
32
|
+
this.flag = cfg.flag;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -20,9 +20,11 @@ export class DBILocale<TNamespace extends NamespaceEnums> {
|
|
|
20
20
|
data: NamespaceData[TNamespace]["contentLocale"];
|
|
21
21
|
private _data: DBILangConstructorObject;
|
|
22
22
|
dbi: DBI<TNamespace, {}>;
|
|
23
|
+
flag: string | undefined
|
|
23
24
|
constructor(dbi: DBI<TNamespace, {}>, cfg: TDBILocaleConstructor<TNamespace>) {
|
|
24
25
|
this.dbi = dbi;
|
|
25
26
|
this.name = cfg.name;
|
|
27
|
+
this.flag = cfg.flag;
|
|
26
28
|
this._data = cfg.data;
|
|
27
29
|
this.data = convertLang<TNamespace>(cfg.data);
|
|
28
30
|
}
|