zumito-framework 1.2.5 → 1.2.6
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/ZumitoFramework.js
CHANGED
|
@@ -18,6 +18,7 @@ import path from 'path';
|
|
|
18
18
|
import { EventManager } from './services/EventManager.js';
|
|
19
19
|
import { CommandManager } from './services/CommandManager.js';
|
|
20
20
|
import { ModuleManager } from './services/ModuleManager.js';
|
|
21
|
+
import { ServiceContainer } from './services/ServiceContainer.js';
|
|
21
22
|
// import better-logging
|
|
22
23
|
betterLogging(console);
|
|
23
24
|
/**
|
|
@@ -135,6 +136,9 @@ export class ZumitoFramework {
|
|
|
135
136
|
if (settings.logLevel) {
|
|
136
137
|
console.logLevel = settings.logLevel;
|
|
137
138
|
}
|
|
139
|
+
// Register this class instance to service container
|
|
140
|
+
ServiceContainer.addService(ZumitoFramework, [], true, this);
|
|
141
|
+
ServiceContainer.addService(TranslationManager, [], true, this.translations);
|
|
138
142
|
this.initialize()
|
|
139
143
|
.then(() => {
|
|
140
144
|
if (callback)
|
|
@@ -278,6 +282,7 @@ export class ZumitoFramework {
|
|
|
278
282
|
intents: this.settings.discordClientOptions.intents,
|
|
279
283
|
});
|
|
280
284
|
this.client.login(this.settings.discordClientOptions.token);
|
|
285
|
+
ServiceContainer.addService(Client, [], true, this.client);
|
|
281
286
|
await new Promise((resolve) => {
|
|
282
287
|
this.client.on('ready', () => {
|
|
283
288
|
// Bot emoji
|
|
@@ -12,7 +12,13 @@ export interface CommandParameters {
|
|
|
12
12
|
message?: Message;
|
|
13
13
|
interaction?: CommandInteraction;
|
|
14
14
|
args: Map<string, any>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated The client should be obtained from `ServiceContainer.get(Client);`
|
|
17
|
+
*/
|
|
15
18
|
client: Client;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated The frameworkInstance should be obtained from `ServiceContainer.get(ZumitoFramework);`
|
|
21
|
+
*/
|
|
16
22
|
framework: ZumitoFramework;
|
|
17
23
|
guildSettings?: any;
|
|
18
24
|
trans: (key: string, params?: any) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ import { TranslationManager } from './services/TranslationManager.js';
|
|
|
21
21
|
import { ZumitoFramework } from './ZumitoFramework.js';
|
|
22
22
|
import * as discord from 'discord.js';
|
|
23
23
|
import { EventParameters } from './definitions/parameters/EventParameters.js';
|
|
24
|
-
|
|
24
|
+
import { ServiceContainer } from './services/ServiceContainer.js';
|
|
25
|
+
export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, DatabaseConfigLoader, DatabaseModel, PresenceDataRule, RuledPresenceData, StatusManagerOptions, discord, EventParameters, ServiceContainer };
|
package/dist/index.js
CHANGED
|
@@ -13,4 +13,7 @@ import { Translation } from './definitions/Translation.js';
|
|
|
13
13
|
import { TranslationManager } from './services/TranslationManager.js';
|
|
14
14
|
import { ZumitoFramework } from './ZumitoFramework.js';
|
|
15
15
|
import * as discord from 'discord.js';
|
|
16
|
-
|
|
16
|
+
import { ServiceContainer } from './services/ServiceContainer.js';
|
|
17
|
+
ServiceContainer.addService(TextFormatter, []);
|
|
18
|
+
ServiceContainer.addService(EmojiFallback, []);
|
|
19
|
+
export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, DatabaseModel, discord, ServiceContainer };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare class ServiceContainerManager {
|
|
2
|
+
private services;
|
|
3
|
+
addService(serviceClass: any, dependencies: string[], singleton?: boolean, instance?: any): void;
|
|
4
|
+
getService(serviceClass: any): any;
|
|
5
|
+
addInstance(serviceClass: any, instance: any): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const ServiceContainer: ServiceContainerManager;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class ServiceContainerManager {
|
|
2
|
+
services = new Map();
|
|
3
|
+
addService(serviceClass, dependencies, singleton = false, instance) {
|
|
4
|
+
this.services.set(serviceClass.name, {
|
|
5
|
+
class: serviceClass,
|
|
6
|
+
dependencies,
|
|
7
|
+
singleton,
|
|
8
|
+
instance
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
getService(serviceClass) {
|
|
12
|
+
const service = this.services.get(serviceClass.name);
|
|
13
|
+
if (!service)
|
|
14
|
+
throw new Error(`Service ${serviceClass.name} not found`);
|
|
15
|
+
if (service.singleton && service.instance)
|
|
16
|
+
return service.instance;
|
|
17
|
+
const dependencies = service.dependencies.map(dependency => this.getService(dependency));
|
|
18
|
+
const instance = new service.class(...dependencies);
|
|
19
|
+
if (service.singleton)
|
|
20
|
+
service.instance = instance;
|
|
21
|
+
return instance;
|
|
22
|
+
}
|
|
23
|
+
addInstance(serviceClass, instance) {
|
|
24
|
+
if (!this.services.has(serviceClass.name))
|
|
25
|
+
return;
|
|
26
|
+
this.services.get(serviceClass.name).instance = instance;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const ServiceContainer = new ServiceContainerManager();
|