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.
@@ -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;
@@ -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
- mongoose.connect(settings.mongoQueryString, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
59
- console.log('[✅] DB connection successful');
58
+ this.initialize().then(() => {
59
+ if (callback)
60
+ callback();
60
61
  }).catch(err => {
61
- console.error("Database connection error:", err.message);
62
- process.exit(1);
62
+ console.error(err);
63
63
  });
64
- this.database = mongoose.connection;
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();
@@ -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>;
@@ -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(...args, this.framework.client)); // Run the event using the above defined emitter (client)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.19",
3
+ "version": "1.1.22",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",