zumito-framework 1.1.1 → 1.1.4
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 +1 -1
- package/dist/types/FrameworkEvent.d.ts +1 -0
- package/dist/types/FrameworkEvent.js +1 -0
- package/dist/types/Module.d.ts +4 -1
- package/dist/types/Module.js +18 -1
- package/package.json +3 -3
- package/plop-templates/translation.json.hbs +8 -0
- package/plopfile.js +66 -0
package/dist/ZumitoFramework.js
CHANGED
|
@@ -127,7 +127,7 @@ class ZumitoFramework {
|
|
|
127
127
|
}
|
|
128
128
|
;
|
|
129
129
|
// Create module instance
|
|
130
|
-
let moduleInstance = new module(path.join(modulesFolder, moduleName));
|
|
130
|
+
let moduleInstance = new module(path.join(modulesFolder, moduleName), this);
|
|
131
131
|
this.modules.set(moduleInstance.constructor.name, moduleInstance);
|
|
132
132
|
// Register module commands
|
|
133
133
|
this.commands = new Map([...this.commands, ...moduleInstance.getCommands()]);
|
package/dist/types/Module.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { ZumitoFramework } from "../ZumitoFramework";
|
|
1
2
|
import { Command } from "./Commands";
|
|
2
3
|
import { FrameworkEvent } from "./FrameworkEvent";
|
|
3
4
|
export declare abstract class Module {
|
|
4
5
|
protected path: string;
|
|
6
|
+
protected framework: ZumitoFramework;
|
|
5
7
|
protected commands: Map<String, Command>;
|
|
6
8
|
protected events: Map<String, FrameworkEvent>;
|
|
7
9
|
protected translations: Map<String, String>;
|
|
8
|
-
constructor(path: any);
|
|
10
|
+
constructor(path: any, framework: any);
|
|
9
11
|
registerCommands(): void;
|
|
10
12
|
getCommands(): Map<String, Command>;
|
|
11
13
|
registerEvents(): void;
|
|
14
|
+
registerEvent(frameworkEvent: FrameworkEvent): void;
|
|
12
15
|
getEvents(): Map<String, FrameworkEvent>;
|
|
13
16
|
registerTranslations(): void;
|
|
14
17
|
getTranslations(): Map<String, String>;
|
package/dist/types/Module.js
CHANGED
|
@@ -5,11 +5,13 @@ const fs = require('fs');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
class Module {
|
|
7
7
|
path;
|
|
8
|
+
framework;
|
|
8
9
|
commands = new Map();
|
|
9
10
|
events = new Map();
|
|
10
11
|
translations = new Map();
|
|
11
|
-
constructor(path) {
|
|
12
|
+
constructor(path, framework) {
|
|
12
13
|
this.path = path;
|
|
14
|
+
this.framework = framework;
|
|
13
15
|
this.registerCommands();
|
|
14
16
|
this.registerEvents();
|
|
15
17
|
this.registerTranslations();
|
|
@@ -38,9 +40,24 @@ class Module {
|
|
|
38
40
|
event = Object.values(event)[0];
|
|
39
41
|
event = new event();
|
|
40
42
|
this.events.set(event.constructor.name.toLowerCase(), event);
|
|
43
|
+
this.registerEvent(event);
|
|
41
44
|
}
|
|
42
45
|
});
|
|
43
46
|
}
|
|
47
|
+
registerEvent(frameworkEvent) {
|
|
48
|
+
if (frameworkEvent.disabled)
|
|
49
|
+
return;
|
|
50
|
+
const eventName = frameworkEvent.constructor.name.toLowerCase();
|
|
51
|
+
const emitter = this.framework.client;
|
|
52
|
+
const once = frameworkEvent.once; // A simple variable which returns if the event should run once
|
|
53
|
+
// Try catch block to throw an error if the code in try{} doesn't work
|
|
54
|
+
try {
|
|
55
|
+
emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(...args, this.framework.client)); // Run the event using the above defined emitter (client)
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(error.stack); // If there is an error, console log the error stack message
|
|
59
|
+
}
|
|
60
|
+
}
|
|
44
61
|
getEvents() {
|
|
45
62
|
return this.events;
|
|
46
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zumito-framework",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Discord.js bot framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"author": "fernandomema",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@types/express": "^4.17.13",
|
|
25
26
|
"better-logging": "^5.0.0",
|
|
26
27
|
"discord.js": "^14.2.0",
|
|
27
28
|
"express": "^4.18.1",
|
|
28
29
|
"mongoose": "^6.5.2",
|
|
29
|
-
"plop": "^3.1.1"
|
|
30
|
-
"@types/express": "^4.17.13"
|
|
30
|
+
"plop": "^3.1.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typedoc": "^0.23.10",
|
package/plopfile.js
CHANGED
|
@@ -17,4 +17,70 @@ module.exports = function (plop) {
|
|
|
17
17
|
templateFile: 'plop-templates/command.js.hbs',
|
|
18
18
|
}],
|
|
19
19
|
});
|
|
20
|
+
plop.setGenerator('translation', {
|
|
21
|
+
description: 'This generate translation file for a module',
|
|
22
|
+
prompts: [{
|
|
23
|
+
type: 'input',
|
|
24
|
+
name: 'module',
|
|
25
|
+
message: 'Name of the module',
|
|
26
|
+
}, {
|
|
27
|
+
type: 'choice',
|
|
28
|
+
name: 'language',
|
|
29
|
+
message: 'Language of the translations',
|
|
30
|
+
choices: [{
|
|
31
|
+
name: 'English',
|
|
32
|
+
value: 'en',
|
|
33
|
+
}, {
|
|
34
|
+
name: 'Spanish',
|
|
35
|
+
value: 'es',
|
|
36
|
+
}, {
|
|
37
|
+
name: 'French',
|
|
38
|
+
value: 'fr',
|
|
39
|
+
}, {
|
|
40
|
+
name: 'German',
|
|
41
|
+
value: 'de',
|
|
42
|
+
}, {
|
|
43
|
+
name: 'Italian',
|
|
44
|
+
value: 'it',
|
|
45
|
+
}, {
|
|
46
|
+
name: 'Portuguese',
|
|
47
|
+
value: 'pt',
|
|
48
|
+
}, {
|
|
49
|
+
name: 'Russian',
|
|
50
|
+
value: 'ru',
|
|
51
|
+
}, {
|
|
52
|
+
name: 'Turkish',
|
|
53
|
+
value: 'tr',
|
|
54
|
+
}, {
|
|
55
|
+
name: 'Chinese',
|
|
56
|
+
value: 'zh',
|
|
57
|
+
}, {
|
|
58
|
+
name: 'Japanese',
|
|
59
|
+
value: 'ja',
|
|
60
|
+
}, {
|
|
61
|
+
name: 'Korean',
|
|
62
|
+
value: 'ko',
|
|
63
|
+
}, {
|
|
64
|
+
name: 'Polish',
|
|
65
|
+
value: 'pl',
|
|
66
|
+
}, {
|
|
67
|
+
name: 'Romanian',
|
|
68
|
+
value: 'ro',
|
|
69
|
+
}, {
|
|
70
|
+
name: 'Russian',
|
|
71
|
+
value: 'ru',
|
|
72
|
+
}, {
|
|
73
|
+
name: 'Ukrainian',
|
|
74
|
+
value: 'uk',
|
|
75
|
+
}, {
|
|
76
|
+
name: 'Vietnamese',
|
|
77
|
+
value: 'vi',
|
|
78
|
+
}],
|
|
79
|
+
}],
|
|
80
|
+
actions: [{
|
|
81
|
+
type: 'add',
|
|
82
|
+
path: 'src/modules/{{module}}/translations/{{language}}.json',
|
|
83
|
+
templateFile: 'plop-templates/translation.json.hbs',
|
|
84
|
+
}],
|
|
85
|
+
});
|
|
20
86
|
};
|