zumito-framework 1.1.18 → 1.1.21

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();
@@ -11,6 +11,9 @@ class baseModule extends Module_1.Module {
11
11
  registerEvents() {
12
12
  this.events.set('interactionCreate', new interactionCreate_1.InteractionCreate());
13
13
  this.events.set('messageCreate', new messageCreate_1.MessageCreate());
14
+ this.events.forEach(event => {
15
+ this.registerDiscordEvent(event);
16
+ });
14
17
  }
15
18
  }
16
19
  exports.baseModule = baseModule;
@@ -51,7 +51,7 @@ 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.18",
3
+ "version": "1.1.21",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",