zumito-framework 1.0.26 → 1.1.1
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 +1 -1
- package/dist/ZumitoFramework.js +10 -105
- package/dist/baseModule/events/discord/messageCreate.d.ts +6 -0
- package/dist/baseModule/events/discord/messageCreate.js +106 -0
- package/dist/types/FrameworkEvent.d.ts +1 -1
- package/dist/types/Module.d.ts +4 -0
- package/dist/types/Module.js +29 -0
- package/dist/types/Translation.d.ts +9 -0
- package/dist/types/Translation.js +28 -0
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ export declare class ZumitoFramework {
|
|
|
18
18
|
modules: Map<String, Module>;
|
|
19
19
|
commands: Map<String, Command>;
|
|
20
20
|
events: Map<String, FrameworkEvent>;
|
|
21
|
+
translations: Map<String, String>;
|
|
21
22
|
routes: any;
|
|
22
23
|
models: any;
|
|
23
24
|
database: any;
|
|
@@ -41,7 +42,6 @@ export declare class ZumitoFramework {
|
|
|
41
42
|
private registerModules;
|
|
42
43
|
private registerModule;
|
|
43
44
|
private initializeDiscordClient;
|
|
44
|
-
private commandHandler;
|
|
45
45
|
static splitCommandLine(commandLine: any): any;
|
|
46
46
|
memberHasPermission(member: GuildMember, channel: TextChannel, permission: bigint): Promise<boolean>;
|
|
47
47
|
}
|
package/dist/ZumitoFramework.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZumitoFramework = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
4
|
const Module_1 = require("./types/Module");
|
|
6
|
-
const express_1 = require("express");
|
|
7
5
|
const ApiResponse_1 = require("./definitions/ApiResponse");
|
|
6
|
+
const express = require("express");
|
|
8
7
|
const fs = require('fs');
|
|
9
8
|
const path = require('path');
|
|
10
9
|
const { Collection, Client } = require('discord.js');
|
|
@@ -29,7 +28,8 @@ class ZumitoFramework {
|
|
|
29
28
|
settings;
|
|
30
29
|
modules;
|
|
31
30
|
commands;
|
|
32
|
-
events
|
|
31
|
+
events;
|
|
32
|
+
translations;
|
|
33
33
|
routes;
|
|
34
34
|
models;
|
|
35
35
|
database;
|
|
@@ -52,6 +52,8 @@ class ZumitoFramework {
|
|
|
52
52
|
this.settings = settings;
|
|
53
53
|
this.modules = new Map();
|
|
54
54
|
this.commands = new Map();
|
|
55
|
+
this.events = new Map();
|
|
56
|
+
this.translations = new Map();
|
|
55
57
|
mongoose.connect(settings.mongoQueryString, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
|
|
56
58
|
console.log('[✅] DB connection successful');
|
|
57
59
|
}).catch(err => {
|
|
@@ -62,10 +64,9 @@ class ZumitoFramework {
|
|
|
62
64
|
this.startApiServer();
|
|
63
65
|
this.registerModules();
|
|
64
66
|
this.initializeDiscordClient();
|
|
65
|
-
this.commandHandler();
|
|
66
67
|
}
|
|
67
68
|
startApiServer() {
|
|
68
|
-
this.app =
|
|
69
|
+
this.app = express();
|
|
69
70
|
let port = process.env.PORT || '80';
|
|
70
71
|
this.app.set('port', port);
|
|
71
72
|
var server = http.createServer(this.app);
|
|
@@ -76,8 +77,8 @@ class ZumitoFramework {
|
|
|
76
77
|
server.on('listening', () => {
|
|
77
78
|
console.log('[✅] API web server listening on port ' + port);
|
|
78
79
|
});
|
|
79
|
-
this.app.use(
|
|
80
|
-
this.app.use(
|
|
80
|
+
this.app.use(express.json());
|
|
81
|
+
this.app.use(express.urlencoded({ extended: false }));
|
|
81
82
|
this.app.use(cookieParser());
|
|
82
83
|
//this.app.use(express.static(path.join(__dirname, "public")));
|
|
83
84
|
//To allow cross-origin requests
|
|
@@ -132,6 +133,8 @@ class ZumitoFramework {
|
|
|
132
133
|
this.commands = new Map([...this.commands, ...moduleInstance.getCommands()]);
|
|
133
134
|
// Register module events
|
|
134
135
|
this.events = new Map([...this.events, ...moduleInstance.getEvents()]);
|
|
136
|
+
// Register translations
|
|
137
|
+
this.translations = new Map([...this.translations, ...moduleInstance.getTranslations()]);
|
|
135
138
|
/*
|
|
136
139
|
|
|
137
140
|
// Register module routes
|
|
@@ -148,104 +151,6 @@ class ZumitoFramework {
|
|
|
148
151
|
});
|
|
149
152
|
this.client.login(this.settings.discordClientOptions.token);
|
|
150
153
|
}
|
|
151
|
-
commandHandler() {
|
|
152
|
-
this.client.on('messageCreate', async (message) => {
|
|
153
|
-
let channel = message.channel;
|
|
154
|
-
let prefix = this.settings.defaultPrefix;
|
|
155
|
-
const args = ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
|
|
156
|
-
const command = args.shift().toLowerCase();
|
|
157
|
-
let commandInstance;
|
|
158
|
-
if (message.content.startsWith(prefix)) {
|
|
159
|
-
if (!this.commands.has(command)) {
|
|
160
|
-
let commandNames = Array.from(this.commands.keys());
|
|
161
|
-
var autocorrect = require('autocorrect')({ words: commandNames });
|
|
162
|
-
var correctedCommand = autocorrect(command);
|
|
163
|
-
if (this.commands.has(correctedCommand)) {
|
|
164
|
-
commandInstance = this.commands.get(correctedCommand);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return; // Command not found
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
commandInstance = this.commands.get(command);
|
|
172
|
-
}
|
|
173
|
-
if (message.guild == null && commandInstance.dm == false)
|
|
174
|
-
return;
|
|
175
|
-
if (commandInstance.adminOnly || commandInstance.permissions.length > 0) {
|
|
176
|
-
let denied = false;
|
|
177
|
-
if (this.memberHasPermission(message.member, message.channel, discord_js_1.PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
|
|
178
|
-
if (commandInstance.permissions.length > 0) {
|
|
179
|
-
commandInstance.permissions.forEach(permission => {
|
|
180
|
-
if (!this.memberHasPermission(message.member, message.channel, permission)) {
|
|
181
|
-
denied = true;
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (denied) {
|
|
187
|
-
return message.reply({
|
|
188
|
-
content: 'You do not have permission to use this command.',
|
|
189
|
-
allowedMentions: {
|
|
190
|
-
repliedUser: false,
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (message.channel.isTextBased) {
|
|
196
|
-
let channel = message.channel;
|
|
197
|
-
// Check command is nsfw and if channel is allowed
|
|
198
|
-
if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(discord_js_1.PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
|
|
199
|
-
return message.reply({
|
|
200
|
-
content: 'This command is nsfw and this channel is not nsfw.',
|
|
201
|
-
allowedMentions: {
|
|
202
|
-
repliedUser: false,
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
try {
|
|
208
|
-
let parsedArgs = new Map();
|
|
209
|
-
args.forEach(function (arg, index) {
|
|
210
|
-
parsedArgs.set(commandInstance.args?.[index]?.name || index, {
|
|
211
|
-
name: commandInstance.args?.[index]?.name || index,
|
|
212
|
-
value: arg
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
await commandInstance.execute({
|
|
216
|
-
message,
|
|
217
|
-
args: parsedArgs,
|
|
218
|
-
client: this.client,
|
|
219
|
-
});
|
|
220
|
-
if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
|
|
221
|
-
try {
|
|
222
|
-
message.delete().catch(function () {
|
|
223
|
-
console.error('can\'t delete user command');
|
|
224
|
-
});
|
|
225
|
-
const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then(res => res.json());
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
console.error(err.name, err.message);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
// let content = await getErrorEmbed({
|
|
234
|
-
// name: error.name,
|
|
235
|
-
// message: error.message,
|
|
236
|
-
// comid: com,
|
|
237
|
-
// args: args,
|
|
238
|
-
// stack: error.stack,
|
|
239
|
-
// }, true);
|
|
240
|
-
// try {
|
|
241
|
-
// message.reply(content);
|
|
242
|
-
// } catch (e) {
|
|
243
|
-
// channel.send(content);
|
|
244
|
-
// }
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
154
|
static splitCommandLine(commandLine) {
|
|
250
155
|
//log( 'commandLine', commandLine ) ;
|
|
251
156
|
// Find a unique marker for the space character.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EventParameters } from "../../../types/EventParameters";
|
|
2
|
+
import { FrameworkEvent } from "../../../types/FrameworkEvent";
|
|
3
|
+
export declare abstract class InteractionCreate extends FrameworkEvent {
|
|
4
|
+
once: boolean;
|
|
5
|
+
execute({ message, client, framework }: EventParameters): Promise<import("discord.js").Message<boolean>>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionCreate = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const FrameworkEvent_1 = require("../../../types/FrameworkEvent");
|
|
6
|
+
const ZumitoFramework_1 = require("../../../ZumitoFramework");
|
|
7
|
+
class InteractionCreate extends FrameworkEvent_1.FrameworkEvent {
|
|
8
|
+
once = false;
|
|
9
|
+
async execute({ message, client, framework }) {
|
|
10
|
+
let channel = message.channel;
|
|
11
|
+
let prefix = framework.settings.defaultPrefix;
|
|
12
|
+
const args = ZumitoFramework_1.ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
|
|
13
|
+
const command = args.shift().toLowerCase();
|
|
14
|
+
let commandInstance;
|
|
15
|
+
if (message.content.startsWith(prefix)) {
|
|
16
|
+
if (!framework.commands.has(command)) {
|
|
17
|
+
let commandNames = Array.from(framework.commands.keys());
|
|
18
|
+
var autocorrect = require('autocorrect')({ words: commandNames });
|
|
19
|
+
var correctedCommand = autocorrect(command);
|
|
20
|
+
if (framework.commands.has(correctedCommand)) {
|
|
21
|
+
commandInstance = framework.commands.get(correctedCommand);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return; // Command not found
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
commandInstance = framework.commands.get(command);
|
|
29
|
+
}
|
|
30
|
+
if (message.guild == null && commandInstance.dm == false)
|
|
31
|
+
return;
|
|
32
|
+
if (commandInstance.adminOnly || commandInstance.permissions.length > 0) {
|
|
33
|
+
let denied = false;
|
|
34
|
+
if (framework.memberHasPermission(message.member, message.channel, discord_js_1.PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
|
|
35
|
+
if (commandInstance.permissions.length > 0) {
|
|
36
|
+
commandInstance.permissions.forEach(permission => {
|
|
37
|
+
if (!framework.memberHasPermission(message.member, message.channel, permission)) {
|
|
38
|
+
denied = true;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (denied) {
|
|
44
|
+
return message.reply({
|
|
45
|
+
content: 'You do not have permission to use this command.',
|
|
46
|
+
allowedMentions: {
|
|
47
|
+
repliedUser: false,
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (message.channel.isTextBased) {
|
|
53
|
+
let channel = message.channel;
|
|
54
|
+
// Check command is nsfw and if channel is allowed
|
|
55
|
+
if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(discord_js_1.PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
|
|
56
|
+
return message.reply({
|
|
57
|
+
content: 'This command is nsfw and this channel is not nsfw.',
|
|
58
|
+
allowedMentions: {
|
|
59
|
+
repliedUser: false,
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
let parsedArgs = new Map();
|
|
66
|
+
args.forEach(function (arg, index) {
|
|
67
|
+
parsedArgs.set(commandInstance.args?.[index]?.name || index, {
|
|
68
|
+
name: commandInstance.args?.[index]?.name || index,
|
|
69
|
+
value: arg
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
await commandInstance.execute({
|
|
73
|
+
message,
|
|
74
|
+
args: parsedArgs,
|
|
75
|
+
client: framework.client,
|
|
76
|
+
});
|
|
77
|
+
if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
|
|
78
|
+
try {
|
|
79
|
+
message.delete().catch(function () {
|
|
80
|
+
console.error('can\'t delete user command');
|
|
81
|
+
});
|
|
82
|
+
const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then(res => res.json());
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error(err.name, err.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// let content = await getErrorEmbed({
|
|
91
|
+
// name: error.name,
|
|
92
|
+
// message: error.message,
|
|
93
|
+
// comid: com,
|
|
94
|
+
// args: args,
|
|
95
|
+
// stack: error.stack,
|
|
96
|
+
// }, true);
|
|
97
|
+
// try {
|
|
98
|
+
// message.reply(content);
|
|
99
|
+
// } catch (e) {
|
|
100
|
+
// channel.send(content);
|
|
101
|
+
// }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.InteractionCreate = InteractionCreate;
|
package/dist/types/Module.d.ts
CHANGED
|
@@ -4,9 +4,13 @@ export declare abstract class Module {
|
|
|
4
4
|
protected path: string;
|
|
5
5
|
protected commands: Map<String, Command>;
|
|
6
6
|
protected events: Map<String, FrameworkEvent>;
|
|
7
|
+
protected translations: Map<String, String>;
|
|
7
8
|
constructor(path: any);
|
|
8
9
|
registerCommands(): void;
|
|
9
10
|
getCommands(): Map<String, Command>;
|
|
10
11
|
registerEvents(): void;
|
|
11
12
|
getEvents(): Map<String, FrameworkEvent>;
|
|
13
|
+
registerTranslations(): void;
|
|
14
|
+
getTranslations(): Map<String, String>;
|
|
15
|
+
parseTranslation(path: String, json: any): any;
|
|
12
16
|
}
|
package/dist/types/Module.js
CHANGED
|
@@ -7,12 +7,16 @@ class Module {
|
|
|
7
7
|
path;
|
|
8
8
|
commands = new Map();
|
|
9
9
|
events = new Map();
|
|
10
|
+
translations = new Map();
|
|
10
11
|
constructor(path) {
|
|
11
12
|
this.path = path;
|
|
12
13
|
this.registerCommands();
|
|
13
14
|
this.registerEvents();
|
|
15
|
+
this.registerTranslations();
|
|
14
16
|
}
|
|
15
17
|
registerCommands() {
|
|
18
|
+
if (!fs.existsSync(path.join(this.path, 'commands')))
|
|
19
|
+
return;
|
|
16
20
|
fs.readdirSync(path.join(this.path, 'commands')).forEach(file => {
|
|
17
21
|
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
18
22
|
let command = require(`${this.path}/commands/${file}`);
|
|
@@ -26,6 +30,8 @@ class Module {
|
|
|
26
30
|
return this.commands;
|
|
27
31
|
}
|
|
28
32
|
registerEvents() {
|
|
33
|
+
if (!fs.existsSync(path.join(this.path, 'events')))
|
|
34
|
+
return;
|
|
29
35
|
fs.readdirSync(path.join(this.path, 'events')).forEach(file => {
|
|
30
36
|
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
31
37
|
let event = require(`${this.path}/events/${file}`);
|
|
@@ -38,5 +44,28 @@ class Module {
|
|
|
38
44
|
getEvents() {
|
|
39
45
|
return this.events;
|
|
40
46
|
}
|
|
47
|
+
registerTranslations() {
|
|
48
|
+
if (!fs.existsSync(path.join(this.path, 'translations')))
|
|
49
|
+
return;
|
|
50
|
+
fs.readdirSync(path.join(this.path, 'translations')).forEach(file => {
|
|
51
|
+
if (file.endsWith('.json')) {
|
|
52
|
+
let json = require(`${this.path}/translations/${file}`);
|
|
53
|
+
this.parseTranslation('', json);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getTranslations() {
|
|
58
|
+
return this.translations;
|
|
59
|
+
}
|
|
60
|
+
parseTranslation(path, json) {
|
|
61
|
+
if (typeof json === 'object') {
|
|
62
|
+
for (let key in json) {
|
|
63
|
+
this.parseTranslation(path + key + '.', json[key]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.translations.set(path, json);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
41
70
|
}
|
|
42
71
|
exports.Module = Module;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Translation {
|
|
2
|
+
text: Map<String, String>;
|
|
3
|
+
constructor();
|
|
4
|
+
get(language: string): String;
|
|
5
|
+
set(language: string, text: string): void;
|
|
6
|
+
has(language: string): boolean;
|
|
7
|
+
getAll(): Map<String, String>;
|
|
8
|
+
setAll(text: Map<String, String>): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Translation = void 0;
|
|
4
|
+
class Translation {
|
|
5
|
+
text = new Map();
|
|
6
|
+
constructor() { }
|
|
7
|
+
get(language) {
|
|
8
|
+
if (this.has(language)) {
|
|
9
|
+
return this.text.get(language);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return this.text.get('en');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
set(language, text) {
|
|
16
|
+
this.text.set(language, text);
|
|
17
|
+
}
|
|
18
|
+
has(language) {
|
|
19
|
+
return this.text.has(language);
|
|
20
|
+
}
|
|
21
|
+
getAll() {
|
|
22
|
+
return this.text;
|
|
23
|
+
}
|
|
24
|
+
setAll(text) {
|
|
25
|
+
this.text = text;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Translation = Translation;
|