zumito-framework 1.15.1 → 1.16.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.
@@ -1,6 +1,8 @@
1
1
  import { ModalSubmitParameters } from '../../definitions/parameters/ModalSubmitParameters.js';
2
+ import { ButtonPressedParams } from '../../index.js';
2
3
  import { SelectMenuParameters } from '../parameters/SelectMenuParameters.js';
3
4
  export type CommandBinds = {
4
5
  selectMenu?: (params: SelectMenuParameters) => Promise<void>;
5
6
  modalSubmit?: (params: ModalSubmitParameters) => Promise<void>;
7
+ buttonClick?: (params: ButtonPressedParams) => Promise<void>;
6
8
  };
@@ -9,10 +9,29 @@ class ServiceContainerManager {
9
9
  });
10
10
  }
11
11
  getService(serviceClass) {
12
+ const serviceType = typeof serviceClass === 'string' ? 'name' : 'class';
12
13
  const serviceName = typeof serviceClass === 'string' ? serviceClass : serviceClass.name;
13
14
  const service = this.services.get(serviceName);
14
- if (!service)
15
- throw new Error(`Service ${serviceName} not found`);
15
+ if (!service) {
16
+ if (serviceType === 'class') {
17
+ const constructor = serviceClass.prototype.constructor;
18
+ if (constructor.length === 0) {
19
+ try {
20
+ const instance = new serviceClass();
21
+ return instance;
22
+ }
23
+ catch (error) {
24
+ throw new Error(`Service ${serviceName} not found. tried to instance with error: ${error}`);
25
+ }
26
+ }
27
+ else {
28
+ throw new Error(`Service ${serviceName} not found`);
29
+ }
30
+ }
31
+ else {
32
+ throw new Error(`Service ${serviceName} not found`);
33
+ }
34
+ }
16
35
  if (service.singleton && service.instance)
17
36
  return service.instance;
18
37
  const dependencies = service.dependencies.map(dependency => this.getServiceByName(dependency));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.15.1",
3
+ "version": "1.16.0",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",