zumito-framework 1.1.19 → 1.1.22
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.d.ts +2 -1
- package/dist/ZumitoFramework.js +19 -7
- package/dist/types/Module.d.ts +1 -0
- package/dist/types/Module.js +12 -2
- package/package.json +1 -1
|
@@ -37,7 +37,8 @@ export declare class ZumitoFramework {
|
|
|
37
37
|
* });
|
|
38
38
|
* @public
|
|
39
39
|
*/
|
|
40
|
-
constructor(settings: FrameworkSettings);
|
|
40
|
+
constructor(settings: FrameworkSettings, callback?: Function);
|
|
41
|
+
initialize(): Promise<void>;
|
|
41
42
|
startApiServer(): void;
|
|
42
43
|
private registerModules;
|
|
43
44
|
private registerModule;
|
package/dist/ZumitoFramework.js
CHANGED
|
@@ -49,22 +49,34 @@ class ZumitoFramework {
|
|
|
49
49
|
* });
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
|
-
constructor(settings) {
|
|
52
|
+
constructor(settings, callback) {
|
|
53
53
|
this.settings = settings;
|
|
54
54
|
this.modules = new Map();
|
|
55
55
|
this.commands = new Map();
|
|
56
56
|
this.events = new Map();
|
|
57
57
|
this.translations = new Map();
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
this.initialize().then(() => {
|
|
59
|
+
if (callback)
|
|
60
|
+
callback();
|
|
60
61
|
}).catch(err => {
|
|
61
|
-
console.error(
|
|
62
|
-
process.exit(1);
|
|
62
|
+
console.error(err);
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
}
|
|
65
|
+
async initialize() {
|
|
66
|
+
try {
|
|
67
|
+
await mongoose.connect(this.settings.mongoQueryString, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.error("[❎] Database connection error:", err.message);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
console.log('[✅] Database connection successful');
|
|
75
|
+
this.database = mongoose.connection;
|
|
76
|
+
}
|
|
77
|
+
this.initializeDiscordClient();
|
|
65
78
|
this.startApiServer();
|
|
66
79
|
this.registerModules();
|
|
67
|
-
this.initializeDiscordClient();
|
|
68
80
|
}
|
|
69
81
|
startApiServer() {
|
|
70
82
|
this.app = express();
|
package/dist/types/Module.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare abstract class Module {
|
|
|
12
12
|
getCommands(): Map<string, Command>;
|
|
13
13
|
registerEvents(): void;
|
|
14
14
|
registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
|
|
15
|
+
parseEventArgs(args: any[]): any;
|
|
15
16
|
getEvents(): Map<string, FrameworkEvent>;
|
|
16
17
|
registerTranslations(): void;
|
|
17
18
|
getTranslations(): Map<string, string>;
|
package/dist/types/Module.js
CHANGED
|
@@ -51,17 +51,27 @@ class Module {
|
|
|
51
51
|
registerDiscordEvent(frameworkEvent) {
|
|
52
52
|
if (frameworkEvent.disabled)
|
|
53
53
|
return;
|
|
54
|
-
const eventName = frameworkEvent.constructor.name.toLowerCase();
|
|
54
|
+
const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() + frameworkEvent.constructor.name.slice(1);
|
|
55
55
|
const emitter = this.framework.client;
|
|
56
56
|
const once = frameworkEvent.once; // A simple variable which returns if the event should run once
|
|
57
57
|
// Try catch block to throw an error if the code in try{} doesn't work
|
|
58
58
|
try {
|
|
59
|
-
emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(
|
|
59
|
+
emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(this.parseEventArgs(args))); // Run the event using the above defined emitter (client)
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
console.error(error.stack); // If there is an error, console log the error stack message
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
parseEventArgs(args) {
|
|
66
|
+
let finalArgs = {
|
|
67
|
+
framework: this.framework,
|
|
68
|
+
client: this.framework.client,
|
|
69
|
+
};
|
|
70
|
+
args.forEach(arg => {
|
|
71
|
+
finalArgs[arg.constructor.name] = arg;
|
|
72
|
+
});
|
|
73
|
+
return finalArgs;
|
|
74
|
+
}
|
|
65
75
|
getEvents() {
|
|
66
76
|
return this.events;
|
|
67
77
|
}
|