commandkit 0.1.3-dev.20231002193305 → 0.1.3-dev.20231003081511

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/README.md CHANGED
@@ -51,7 +51,7 @@ pnpm add commandkit
51
51
  To install the development version of CommandKit, run the following command:
52
52
 
53
53
  ```bash
54
- npm install underctrl-io/commandkit#dev-build
54
+ npm install commandkit@dev
55
55
  ```
56
56
 
57
57
  > ⚠️ The development version is likely to have bugs.
package/dist/index.d.mts CHANGED
@@ -34,10 +34,9 @@ interface CommandKitOptions {
34
34
  */
35
35
  skipBuiltInValidations?: boolean;
36
36
  /**
37
- * Uses discordjs/rest to register application commands.
38
- * @experimental
37
+ * Bulk register application commands instead of one-by-one.
39
38
  */
40
- useRest?: boolean;
39
+ bulkRegister?: boolean;
41
40
  }
42
41
  interface CommandFileObject {
43
42
  data: CommandData;
@@ -117,9 +116,16 @@ declare class CommandKit {
117
116
  constructor(options: CommandKitOptions);
118
117
  /**
119
118
  * Updates application commands with the latest from "commandsPath".
120
- * @experimental
121
119
  */
122
120
  reloadCommands(type?: ReloadOptions): Promise<void>;
121
+ /**
122
+ * Updates application events with the latest from "eventsPath".
123
+ */
124
+ reloadEvents(): Promise<void>;
125
+ /**
126
+ * Updates application command validations with the latest from "validationsPath".
127
+ */
128
+ reloadValidations(): Promise<void>;
123
129
  /**
124
130
  * @returns An array of objects of all the commands that CommandKit is handling.
125
131
  */
package/dist/index.d.ts CHANGED
@@ -34,10 +34,9 @@ interface CommandKitOptions {
34
34
  */
35
35
  skipBuiltInValidations?: boolean;
36
36
  /**
37
- * Uses discordjs/rest to register application commands.
38
- * @experimental
37
+ * Bulk register application commands instead of one-by-one.
39
38
  */
40
- useRest?: boolean;
39
+ bulkRegister?: boolean;
41
40
  }
42
41
  interface CommandFileObject {
43
42
  data: CommandData;
@@ -117,9 +116,16 @@ declare class CommandKit {
117
116
  constructor(options: CommandKitOptions);
118
117
  /**
119
118
  * Updates application commands with the latest from "commandsPath".
120
- * @experimental
121
119
  */
122
120
  reloadCommands(type?: ReloadOptions): Promise<void>;
121
+ /**
122
+ * Updates application events with the latest from "eventsPath".
123
+ */
124
+ reloadEvents(): Promise<void>;
125
+ /**
126
+ * Updates application command validations with the latest from "validationsPath".
127
+ */
128
+ reloadValidations(): Promise<void>;
123
129
  /**
124
130
  * @returns An array of objects of all the commands that CommandKit is handling.
125
131
  */
package/dist/index.js CHANGED
@@ -487,7 +487,7 @@ var CommandHandler = class {
487
487
  )
488
488
  );
489
489
  }
490
- if (this.#data.useRest) {
490
+ if (this.#data.bulkRegister) {
491
491
  await loadCommandsWithRest({
492
492
  client: this.#data.client,
493
493
  devGuildIds: this.#data.devGuildIds,
@@ -622,7 +622,7 @@ var CommandHandler = class {
622
622
  async reloadCommands(type) {
623
623
  this.#data.commands = [];
624
624
  await this.#buildCommands();
625
- if (this.#data.useRest) {
625
+ if (this.#data.bulkRegister) {
626
626
  await loadCommandsWithRest({
627
627
  client: this.#data.client,
628
628
  devGuildIds: this.#data.devGuildIds,
@@ -643,6 +643,8 @@ var CommandHandler = class {
643
643
  };
644
644
 
645
645
  // src/handlers/event-handler/EventHandler.ts
646
+ var import_rfdc2 = __toESM(require("rfdc"));
647
+ var clone2 = (0, import_rfdc2.default)();
646
648
  var EventHandler = class {
647
649
  #data;
648
650
  constructor({ ...options }) {
@@ -659,8 +661,9 @@ var EventHandler = class {
659
661
  const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
660
662
  for (const eventFolderPath of eventFolderPaths) {
661
663
  const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
664
+ const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
662
665
  const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
663
- (path3) => path3.endsWith(".js") || path3.endsWith(".ts")
666
+ (path3) => allowedExtensions.test(path3)
664
667
  );
665
668
  const eventObj = {
666
669
  name: eventName,
@@ -669,7 +672,11 @@ var EventHandler = class {
669
672
  this.#data.events.push(eventObj);
670
673
  for (const eventFilePath of eventFilePaths) {
671
674
  const modulePath = toFileURL(eventFilePath);
672
- let eventFunction = (await import(modulePath)).default;
675
+ let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
676
+ let eventFunction = clone2(importedFunction);
677
+ if (typeof module !== "undefined" && typeof require !== "undefined") {
678
+ delete require.cache[require.resolve(eventFilePath)];
679
+ }
673
680
  if (eventFunction?.default) {
674
681
  eventFunction = eventFunction.default;
675
682
  }
@@ -703,9 +710,17 @@ var EventHandler = class {
703
710
  get events() {
704
711
  return this.#data.events;
705
712
  }
713
+ async reloadEvents() {
714
+ await this.#buildEvents();
715
+ this.#data.events = [];
716
+ this.#data.client.removeAllListeners();
717
+ this.#registerEvents();
718
+ }
706
719
  };
707
720
 
708
721
  // src/handlers/validation-handler/ValidationHandler.ts
722
+ var import_rfdc3 = __toESM(require("rfdc"));
723
+ var clone3 = (0, import_rfdc3.default)();
709
724
  var ValidationHandler = class {
710
725
  #data;
711
726
  constructor({ ...options }) {
@@ -718,12 +733,17 @@ var ValidationHandler = class {
718
733
  await this.#buildValidations();
719
734
  }
720
735
  async #buildValidations() {
736
+ const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
721
737
  const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
722
- (path3) => path3.endsWith(".js") || path3.endsWith(".ts")
738
+ (path3) => allowedExtensions.test(path3)
723
739
  );
724
740
  for (const validationFilePath of validationFilePaths) {
725
741
  const modulePath = toFileURL(validationFilePath);
726
- let validationFunction = (await import(modulePath)).default;
742
+ let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
743
+ let validationFunction = clone3(importedFunction);
744
+ if (typeof module !== "undefined" && typeof require !== "undefined") {
745
+ delete require.cache[require.resolve(validationFilePath)];
746
+ }
727
747
  if (validationFunction?.default) {
728
748
  validationFunction = validationFunction.default;
729
749
  }
@@ -742,6 +762,10 @@ var ValidationHandler = class {
742
762
  get validations() {
743
763
  return this.#data.validations;
744
764
  }
765
+ async reloadValidations() {
766
+ this.#data.validations = [];
767
+ await this.#buildValidations();
768
+ }
745
769
  };
746
770
 
747
771
  // src/CommandKit.ts
@@ -788,7 +812,7 @@ var CommandKit = class {
788
812
  customValidations: validationFunctions,
789
813
  skipBuiltInValidations: this.#data.skipBuiltInValidations || false,
790
814
  handler: this,
791
- useRest: this.#data.useRest || false
815
+ bulkRegister: this.#data.bulkRegister || false
792
816
  });
793
817
  await commandHandler.init();
794
818
  this.#data.commandHandler = commandHandler;
@@ -796,13 +820,28 @@ var CommandKit = class {
796
820
  }
797
821
  /**
798
822
  * Updates application commands with the latest from "commandsPath".
799
- * @experimental
800
823
  */
801
824
  async reloadCommands(type) {
802
825
  if (!this.#data.commandHandler)
803
826
  return;
804
827
  await this.#data.commandHandler.reloadCommands(type);
805
828
  }
829
+ /**
830
+ * Updates application events with the latest from "eventsPath".
831
+ */
832
+ async reloadEvents() {
833
+ if (!this.#data.eventHandler)
834
+ return;
835
+ await this.#data.eventHandler.reloadEvents();
836
+ }
837
+ /**
838
+ * Updates application command validations with the latest from "validationsPath".
839
+ */
840
+ async reloadValidations() {
841
+ if (!this.#data.validationHandler)
842
+ return;
843
+ await this.#data.validationHandler.reloadValidations();
844
+ }
806
845
  /**
807
846
  * @returns An array of objects of all the commands that CommandKit is handling.
808
847
  */
package/dist/index.mjs CHANGED
@@ -457,7 +457,7 @@ var CommandHandler = class {
457
457
  )
458
458
  );
459
459
  }
460
- if (this.#data.useRest) {
460
+ if (this.#data.bulkRegister) {
461
461
  await loadCommandsWithRest({
462
462
  client: this.#data.client,
463
463
  devGuildIds: this.#data.devGuildIds,
@@ -592,7 +592,7 @@ var CommandHandler = class {
592
592
  async reloadCommands(type) {
593
593
  this.#data.commands = [];
594
594
  await this.#buildCommands();
595
- if (this.#data.useRest) {
595
+ if (this.#data.bulkRegister) {
596
596
  await loadCommandsWithRest({
597
597
  client: this.#data.client,
598
598
  devGuildIds: this.#data.devGuildIds,
@@ -613,6 +613,8 @@ var CommandHandler = class {
613
613
  };
614
614
 
615
615
  // src/handlers/event-handler/EventHandler.ts
616
+ import rdfc2 from "rfdc";
617
+ var clone2 = rdfc2();
616
618
  var EventHandler = class {
617
619
  #data;
618
620
  constructor({ ...options }) {
@@ -629,8 +631,9 @@ var EventHandler = class {
629
631
  const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
630
632
  for (const eventFolderPath of eventFolderPaths) {
631
633
  const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
634
+ const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
632
635
  const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
633
- (path3) => path3.endsWith(".js") || path3.endsWith(".ts")
636
+ (path3) => allowedExtensions.test(path3)
634
637
  );
635
638
  const eventObj = {
636
639
  name: eventName,
@@ -639,7 +642,11 @@ var EventHandler = class {
639
642
  this.#data.events.push(eventObj);
640
643
  for (const eventFilePath of eventFilePaths) {
641
644
  const modulePath = toFileURL(eventFilePath);
642
- let eventFunction = (await import(modulePath)).default;
645
+ let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
646
+ let eventFunction = clone2(importedFunction);
647
+ if (typeof module !== "undefined" && typeof __require !== "undefined") {
648
+ delete __require.cache[__require.resolve(eventFilePath)];
649
+ }
643
650
  if (eventFunction?.default) {
644
651
  eventFunction = eventFunction.default;
645
652
  }
@@ -673,9 +680,17 @@ var EventHandler = class {
673
680
  get events() {
674
681
  return this.#data.events;
675
682
  }
683
+ async reloadEvents() {
684
+ await this.#buildEvents();
685
+ this.#data.events = [];
686
+ this.#data.client.removeAllListeners();
687
+ this.#registerEvents();
688
+ }
676
689
  };
677
690
 
678
691
  // src/handlers/validation-handler/ValidationHandler.ts
692
+ import rdfc3 from "rfdc";
693
+ var clone3 = rdfc3();
679
694
  var ValidationHandler = class {
680
695
  #data;
681
696
  constructor({ ...options }) {
@@ -688,12 +703,17 @@ var ValidationHandler = class {
688
703
  await this.#buildValidations();
689
704
  }
690
705
  async #buildValidations() {
706
+ const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
691
707
  const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
692
- (path3) => path3.endsWith(".js") || path3.endsWith(".ts")
708
+ (path3) => allowedExtensions.test(path3)
693
709
  );
694
710
  for (const validationFilePath of validationFilePaths) {
695
711
  const modulePath = toFileURL(validationFilePath);
696
- let validationFunction = (await import(modulePath)).default;
712
+ let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
713
+ let validationFunction = clone3(importedFunction);
714
+ if (typeof module !== "undefined" && typeof __require !== "undefined") {
715
+ delete __require.cache[__require.resolve(validationFilePath)];
716
+ }
697
717
  if (validationFunction?.default) {
698
718
  validationFunction = validationFunction.default;
699
719
  }
@@ -712,6 +732,10 @@ var ValidationHandler = class {
712
732
  get validations() {
713
733
  return this.#data.validations;
714
734
  }
735
+ async reloadValidations() {
736
+ this.#data.validations = [];
737
+ await this.#buildValidations();
738
+ }
715
739
  };
716
740
 
717
741
  // src/CommandKit.ts
@@ -758,7 +782,7 @@ var CommandKit = class {
758
782
  customValidations: validationFunctions,
759
783
  skipBuiltInValidations: this.#data.skipBuiltInValidations || false,
760
784
  handler: this,
761
- useRest: this.#data.useRest || false
785
+ bulkRegister: this.#data.bulkRegister || false
762
786
  });
763
787
  await commandHandler.init();
764
788
  this.#data.commandHandler = commandHandler;
@@ -766,13 +790,28 @@ var CommandKit = class {
766
790
  }
767
791
  /**
768
792
  * Updates application commands with the latest from "commandsPath".
769
- * @experimental
770
793
  */
771
794
  async reloadCommands(type) {
772
795
  if (!this.#data.commandHandler)
773
796
  return;
774
797
  await this.#data.commandHandler.reloadCommands(type);
775
798
  }
799
+ /**
800
+ * Updates application events with the latest from "eventsPath".
801
+ */
802
+ async reloadEvents() {
803
+ if (!this.#data.eventHandler)
804
+ return;
805
+ await this.#data.eventHandler.reloadEvents();
806
+ }
807
+ /**
808
+ * Updates application command validations with the latest from "validationsPath".
809
+ */
810
+ async reloadValidations() {
811
+ if (!this.#data.validationHandler)
812
+ return;
813
+ await this.#data.validationHandler.reloadValidations();
814
+ }
776
815
  /**
777
816
  * @returns An array of objects of all the commands that CommandKit is handling.
778
817
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "commandkit",
3
3
  "description": "Beginner friendly command & event handler for Discord.js",
4
- "version": "0.1.3-dev.20231002193305",
4
+ "version": "0.1.3-dev.20231003081511",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -35,7 +35,6 @@
35
35
  "rfdc": "^1.3.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/lodash": "^4.14.199",
39
38
  "@types/node": "^20.5.9",
40
39
  "discord.js": "^14.13.0",
41
40
  "dotenv": "^16.3.1",