@spatulox/discord-module 0.3.0 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  Date format : dd/mm/yyy
3
3
 
4
+ ### 13/04/2026 - 0.4.0
5
+ - Introduce a ModuleRegistry to get Module instance
6
+
7
+ ### 13/04/2026 - 0.3.1
8
+ - Update README.md : Add explanation for InteractionManager when passing class method when registering interactions
9
+
4
10
  ### 13/04/2026 - 0.3.0
5
11
  - InteractionManager : adds support for prefix and suffix identifier matching
6
12
 
package/README.md CHANGED
@@ -64,6 +64,14 @@ client.once(Events.ClientReady, () => {
64
64
 
65
65
  // Register commands
66
66
  interactionManager.registerSlash("ping", PongModule.pong_interaction)
67
+
68
+ // If you want to link a Method of a class
69
+ // This will crash because you only pass the method of the class, not the full class instance, so "randomBoolean" is undefined
70
+ interactionManager.registerButton("btn_randombool_accessor", new BtnModuleTest().testAccessor) // This test is here to try to acces a var in an instance of a class wich is undefined
71
+ // With a method of a class (which require a this.method() of this.var, you need to do it this way :
72
+ const classInstance = new BtnModuleTest() // Create the instance
73
+ interactionManager.registerButton("btn_randombool_accessor", (interaction: ButtonInteraction) => { return classInstance.testAccessor(interaction) }) // Pass an unknow func which call the class method with the instance
74
+ interactionManager.registerButton("btn_randombool_accessor", () => { return classInstance.testAccessorWithoutInteraction() })
67
75
  });
68
76
  ```
69
77
 
package/dist/index.d.mts CHANGED
@@ -8,6 +8,7 @@ declare abstract class Module {
8
8
  abstract description: string;
9
9
  private _enabled;
10
10
  abstract get events(): ModuleEventsMap;
11
+ get instance(): Module | undefined;
11
12
  setParent(parent: string): void;
12
13
  get parent(): string | "root";
13
14
  createModuleUI(namePrefix?: string): SectionBuilder;
@@ -65,6 +66,17 @@ declare class ModuleManager {
65
66
  updateMultiModuleUI(interaction: ButtonInteraction, module: Module): void;
66
67
  }
67
68
 
69
+ /**
70
+ * This class is present only to avoid circular dependencies with the "module instance nightmare"
71
+ * Idk why I can't directly ue the Manager.getInstance?.getMdule(this.name) dans Module, but I can't and need to do thing like that ?
72
+ */
73
+ declare class ModuleRegistry {
74
+ private static _manager;
75
+ static setModuleManager(m: ModuleManager): void;
76
+ static getModule(name: string): Module | undefined;
77
+ static get manager(): ModuleManager | null;
78
+ }
79
+
68
80
  declare enum InteractionType {
69
81
  AUTOCOMPLETE = "AUTOCOMPLETE",
70
82
  BUTTON = "BUTTON",
@@ -109,4 +121,4 @@ declare class InteractionsManager {
109
121
  registerSlash(name: string, func: (...args: any[]) => any, matchType?: InteractionMatchType): boolean;
110
122
  }
111
123
 
112
- export { InteractionMatchType, InteractionType, InteractionsManager, Module, type ModuleEventsMap, ModuleManager, MultiModule };
124
+ export { InteractionMatchType, InteractionType, InteractionsManager, Module, type ModuleEventsMap, ModuleManager, ModuleRegistry, MultiModule };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare abstract class Module {
8
8
  abstract description: string;
9
9
  private _enabled;
10
10
  abstract get events(): ModuleEventsMap;
11
+ get instance(): Module | undefined;
11
12
  setParent(parent: string): void;
12
13
  get parent(): string | "root";
13
14
  createModuleUI(namePrefix?: string): SectionBuilder;
@@ -65,6 +66,17 @@ declare class ModuleManager {
65
66
  updateMultiModuleUI(interaction: ButtonInteraction, module: Module): void;
66
67
  }
67
68
 
69
+ /**
70
+ * This class is present only to avoid circular dependencies with the "module instance nightmare"
71
+ * Idk why I can't directly ue the Manager.getInstance?.getMdule(this.name) dans Module, but I can't and need to do thing like that ?
72
+ */
73
+ declare class ModuleRegistry {
74
+ private static _manager;
75
+ static setModuleManager(m: ModuleManager): void;
76
+ static getModule(name: string): Module | undefined;
77
+ static get manager(): ModuleManager | null;
78
+ }
79
+
68
80
  declare enum InteractionType {
69
81
  AUTOCOMPLETE = "AUTOCOMPLETE",
70
82
  BUTTON = "BUTTON",
@@ -109,4 +121,4 @@ declare class InteractionsManager {
109
121
  registerSlash(name: string, func: (...args: any[]) => any, matchType?: InteractionMatchType): boolean;
110
122
  }
111
123
 
112
- export { InteractionMatchType, InteractionType, InteractionsManager, Module, type ModuleEventsMap, ModuleManager, MultiModule };
124
+ export { InteractionMatchType, InteractionType, InteractionsManager, Module, type ModuleEventsMap, ModuleManager, ModuleRegistry, MultiModule };
package/dist/index.js CHANGED
@@ -25,15 +25,35 @@ __export(index_exports, {
25
25
  InteractionsManager: () => InteractionsManager,
26
26
  Module: () => Module,
27
27
  ModuleManager: () => ModuleManager,
28
+ ModuleRegistry: () => ModuleRegistry,
28
29
  MultiModule: () => MultiModule
29
30
  });
30
31
  module.exports = __toCommonJS(index_exports);
31
32
 
32
33
  // src/code/Module.ts
33
34
  var import_discord = require("discord.js");
35
+
36
+ // src/code/ModuleRegistry.ts
37
+ var ModuleRegistry = class _ModuleRegistry {
38
+ static _manager = null;
39
+ static setModuleManager(m) {
40
+ _ModuleRegistry._manager = m;
41
+ }
42
+ static getModule(name) {
43
+ return this._manager?.getModule(name);
44
+ }
45
+ static get manager() {
46
+ return this._manager;
47
+ }
48
+ };
49
+
50
+ // src/code/Module.ts
34
51
  var Module = class {
35
52
  _parent = "root";
36
53
  _enabled = false;
54
+ get instance() {
55
+ return ModuleRegistry.manager?.getModule(this.name);
56
+ }
37
57
  setParent(parent) {
38
58
  this._parent = parent;
39
59
  }
@@ -80,6 +100,7 @@ var ModuleManager = class _ModuleManager {
80
100
  }
81
101
  static createInstance(client) {
82
102
  _ModuleManager.instance = new _ModuleManager(client);
103
+ ModuleRegistry.setModuleManager(_ModuleManager.instance);
83
104
  this.initClient(client);
84
105
  return _ModuleManager.instance;
85
106
  }
@@ -180,9 +201,7 @@ var ModuleManager = class _ModuleManager {
180
201
  }
181
202
  getModule(name) {
182
203
  for (const parentModules of Object.values(this._modules)) {
183
- const found = parentModules.find(
184
- (m) => m.name.toLowerCase() === name.toLowerCase()
185
- );
204
+ const found = parentModules.find((m) => m.name.toLowerCase() === name.toLowerCase());
186
205
  if (found) return found;
187
206
  }
188
207
  }
@@ -458,5 +477,6 @@ var InteractionsManager = class _InteractionsManager {
458
477
  InteractionsManager,
459
478
  Module,
460
479
  ModuleManager,
480
+ ModuleRegistry,
461
481
  MultiModule
462
482
  });
package/dist/index.mjs CHANGED
@@ -7,9 +7,28 @@ import {
7
7
  SectionBuilder,
8
8
  TextDisplayBuilder
9
9
  } from "discord.js";
10
+
11
+ // src/code/ModuleRegistry.ts
12
+ var ModuleRegistry = class _ModuleRegistry {
13
+ static _manager = null;
14
+ static setModuleManager(m) {
15
+ _ModuleRegistry._manager = m;
16
+ }
17
+ static getModule(name) {
18
+ return this._manager?.getModule(name);
19
+ }
20
+ static get manager() {
21
+ return this._manager;
22
+ }
23
+ };
24
+
25
+ // src/code/Module.ts
10
26
  var Module = class {
11
27
  _parent = "root";
12
28
  _enabled = false;
29
+ get instance() {
30
+ return ModuleRegistry.manager?.getModule(this.name);
31
+ }
13
32
  setParent(parent) {
14
33
  this._parent = parent;
15
34
  }
@@ -63,6 +82,7 @@ var ModuleManager = class _ModuleManager {
63
82
  }
64
83
  static createInstance(client) {
65
84
  _ModuleManager.instance = new _ModuleManager(client);
85
+ ModuleRegistry.setModuleManager(_ModuleManager.instance);
66
86
  this.initClient(client);
67
87
  return _ModuleManager.instance;
68
88
  }
@@ -163,9 +183,7 @@ var ModuleManager = class _ModuleManager {
163
183
  }
164
184
  getModule(name) {
165
185
  for (const parentModules of Object.values(this._modules)) {
166
- const found = parentModules.find(
167
- (m) => m.name.toLowerCase() === name.toLowerCase()
168
- );
186
+ const found = parentModules.find((m) => m.name.toLowerCase() === name.toLowerCase());
169
187
  if (found) return found;
170
188
  }
171
189
  }
@@ -445,5 +463,6 @@ export {
445
463
  InteractionsManager,
446
464
  Module,
447
465
  ModuleManager,
466
+ ModuleRegistry,
448
467
  MultiModule
449
468
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spatulox/discord-module",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Automatic Module Manager for Discordjs",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -14,8 +14,8 @@
14
14
  "pub:minor": "npm run minor && npm publish --access public",
15
15
  "pub:major": "npm run major && npm publish --access public"
16
16
  },
17
- "dependencies": {
18
- "discord.js": "^14.25.1"
17
+ "peerDependencies": {
18
+ "discord.js": "^14.26.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^25.3.0",