zumito-framework 1.1.44 → 1.1.46
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/TranslationManager.d.ts +15 -15
- package/dist/TranslationManager.js +41 -41
- package/dist/ZumitoFramework.d.ts +51 -51
- package/dist/ZumitoFramework.js +312 -312
- package/dist/baseModule/BaseModule.d.ts +6 -6
- package/dist/baseModule/BaseModule.js +16 -16
- package/dist/baseModule/events/discord/interactionCreate.d.ts +6 -6
- package/dist/baseModule/events/discord/interactionCreate.js +50 -50
- package/dist/baseModule/events/discord/messageCreate.d.ts +16 -16
- package/dist/baseModule/events/discord/messageCreate.js +233 -233
- package/dist/baseModule/index.d.ts +6 -6
- package/dist/baseModule/index.js +15 -15
- package/dist/baseModule/models/errors.json +13 -13
- package/dist/baseModule/models/guild.json +22 -22
- package/dist/definitions/ApiResponse.d.ts +4 -4
- package/dist/definitions/ApiResponse.js +16 -16
- package/dist/index.d.ts +17 -17
- package/dist/index.js +12 -12
- package/dist/managers/EmojiManager.d.ts +11 -11
- package/dist/managers/EmojiManager.js +32 -32
- package/dist/types/Command.d.ts +24 -24
- package/dist/types/Command.js +25 -25
- package/dist/types/CommandArgDefinition.d.ts +7 -7
- package/dist/types/CommandArgDefinition.js +1 -1
- package/dist/types/CommandArguments.d.ts +8 -8
- package/dist/types/CommandArguments.js +15 -15
- package/dist/types/CommandChoiceDefinition.d.ts +4 -4
- package/dist/types/CommandChoiceDefinition.js +1 -1
- package/dist/types/CommandParameters.d.ts +18 -18
- package/dist/types/CommandParameters.js +1 -1
- package/dist/types/CommandType.d.ts +6 -6
- package/dist/types/CommandType.js +6 -6
- package/dist/types/Commands.d.ts +23 -23
- package/dist/types/Commands.js +26 -26
- package/dist/types/EventParameters.d.ts +8 -8
- package/dist/types/EventParameters.js +1 -1
- package/dist/types/FrameworkEvent.d.ts +5 -5
- package/dist/types/FrameworkEvent.js +4 -4
- package/dist/types/FrameworkSettings.d.ts +11 -11
- package/dist/types/FrameworkSettings.js +1 -1
- package/dist/types/Module.d.ts +25 -25
- package/dist/types/Module.js +191 -191
- package/dist/types/SelectMenuParameters.d.ts +9 -9
- package/dist/types/SelectMenuParameters.js +1 -1
- package/dist/types/Translation.d.ts +9 -9
- package/dist/types/Translation.js +31 -31
- package/dist/utils/EmojiFallback.d.ts +6 -4
- package/dist/utils/EmojiFallback.js +14 -6
- package/dist/utils/TextFormatter.d.ts +26 -26
- package/dist/utils/TextFormatter.js +82 -82
- package/package.json +1 -1
- package/plop-templates/command.js.hbs +16 -16
- package/plop-templates/translation.json.hbs +7 -7
- package/plopfile.js +88 -88
- package/templateGenerator.mjs +25 -25
package/dist/types/Commands.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { CommandType } from "./CommandType.js";
|
|
2
|
-
export class Command {
|
|
3
|
-
name = this.constructor.name.toLowerCase();
|
|
4
|
-
categories = [];
|
|
5
|
-
aliases = [];
|
|
6
|
-
examples = [];
|
|
7
|
-
permissions = [];
|
|
8
|
-
botPermissions = [];
|
|
9
|
-
hidden = false;
|
|
10
|
-
adminOnly = false;
|
|
11
|
-
nsfw = false;
|
|
12
|
-
cooldown = 0;
|
|
13
|
-
slashCommand = false;
|
|
14
|
-
dm = false;
|
|
15
|
-
args = [];
|
|
16
|
-
type = CommandType.prefix;
|
|
17
|
-
constructor() {
|
|
18
|
-
}
|
|
19
|
-
executePrefixCommand({ message, interaction, args, client, framework }) {
|
|
20
|
-
this.execute({ message, interaction, args, client, framework });
|
|
21
|
-
}
|
|
22
|
-
executeSlashCommand({ message, interaction, args, client, framework }) {
|
|
23
|
-
this.execute({ message, interaction, args, client, framework });
|
|
24
|
-
}
|
|
25
|
-
selectMenu({ path, interaction, client, framework }) { }
|
|
26
|
-
}
|
|
1
|
+
import { CommandType } from "./CommandType.js";
|
|
2
|
+
export class Command {
|
|
3
|
+
name = this.constructor.name.toLowerCase();
|
|
4
|
+
categories = [];
|
|
5
|
+
aliases = [];
|
|
6
|
+
examples = [];
|
|
7
|
+
permissions = [];
|
|
8
|
+
botPermissions = [];
|
|
9
|
+
hidden = false;
|
|
10
|
+
adminOnly = false;
|
|
11
|
+
nsfw = false;
|
|
12
|
+
cooldown = 0;
|
|
13
|
+
slashCommand = false;
|
|
14
|
+
dm = false;
|
|
15
|
+
args = [];
|
|
16
|
+
type = CommandType.prefix;
|
|
17
|
+
constructor() {
|
|
18
|
+
}
|
|
19
|
+
executePrefixCommand({ message, interaction, args, client, framework }) {
|
|
20
|
+
this.execute({ message, interaction, args, client, framework });
|
|
21
|
+
}
|
|
22
|
+
executeSlashCommand({ message, interaction, args, client, framework }) {
|
|
23
|
+
this.execute({ message, interaction, args, client, framework });
|
|
24
|
+
}
|
|
25
|
+
selectMenu({ path, interaction, client, framework }) { }
|
|
26
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Client, Interaction, Message } from "discord.js";
|
|
2
|
-
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
3
|
-
export interface EventParameters {
|
|
4
|
-
message?: Message;
|
|
5
|
-
interaction?: Interaction;
|
|
6
|
-
client?: Client;
|
|
7
|
-
framework: ZumitoFramework;
|
|
8
|
-
}
|
|
1
|
+
import { Client, Interaction, Message } from "discord.js";
|
|
2
|
+
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
3
|
+
export interface EventParameters {
|
|
4
|
+
message?: Message;
|
|
5
|
+
interaction?: Interaction;
|
|
6
|
+
client?: Client;
|
|
7
|
+
framework: ZumitoFramework;
|
|
8
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare abstract class FrameworkEvent {
|
|
2
|
-
once: boolean;
|
|
3
|
-
disabled: boolean;
|
|
4
|
-
abstract execute(...args: any[]): any;
|
|
5
|
-
}
|
|
1
|
+
export declare abstract class FrameworkEvent {
|
|
2
|
+
once: boolean;
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
abstract execute(...args: any[]): any;
|
|
5
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class FrameworkEvent {
|
|
2
|
-
once = false;
|
|
3
|
-
disabled = false;
|
|
4
|
-
}
|
|
1
|
+
export class FrameworkEvent {
|
|
2
|
+
once = false;
|
|
3
|
+
disabled = false;
|
|
4
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface FrameworkSettings {
|
|
2
|
-
logLevel?: number;
|
|
3
|
-
debug?: boolean;
|
|
4
|
-
discordClientOptions: {
|
|
5
|
-
intents?: number;
|
|
6
|
-
token: string;
|
|
7
|
-
clientId: string;
|
|
8
|
-
};
|
|
9
|
-
defaultPrefix?: string;
|
|
10
|
-
mongoQueryString: string;
|
|
11
|
-
}
|
|
1
|
+
export interface FrameworkSettings {
|
|
2
|
+
logLevel?: number;
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
discordClientOptions: {
|
|
5
|
+
intents?: number;
|
|
6
|
+
token: string;
|
|
7
|
+
clientId: string;
|
|
8
|
+
};
|
|
9
|
+
defaultPrefix?: string;
|
|
10
|
+
mongoQueryString: string;
|
|
11
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/types/Module.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
2
|
-
import { Command } from "./Command.js";
|
|
3
|
-
import { FrameworkEvent } from "./FrameworkEvent.js";
|
|
4
|
-
export declare abstract class Module {
|
|
5
|
-
protected path: string;
|
|
6
|
-
protected framework: ZumitoFramework;
|
|
7
|
-
protected commands: Map<string, Command>;
|
|
8
|
-
protected events: Map<string, FrameworkEvent>;
|
|
9
|
-
protected models: Map<string, any>;
|
|
10
|
-
constructor(path: any, framework: any);
|
|
11
|
-
initialize(): Promise<void>;
|
|
12
|
-
registerCommands(): Promise<void>;
|
|
13
|
-
onCommandCreated(filePath: string): Promise<void>;
|
|
14
|
-
onCommandChanged(filePath: string): Promise<void>;
|
|
15
|
-
onErrorLoadingCommand(error: Error): void;
|
|
16
|
-
getCommands(): Map<string, Command>;
|
|
17
|
-
registerEvents(): Promise<void>;
|
|
18
|
-
registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
|
|
19
|
-
parseEventArgs(args: any[]): any;
|
|
20
|
-
getEvents(): Map<string, FrameworkEvent>;
|
|
21
|
-
registerTranslations(): Promise<void>;
|
|
22
|
-
parseTranslation(path: string, lang: string, json: any): any;
|
|
23
|
-
registerModels(): Promise<void>;
|
|
24
|
-
getModels(): Map<string, any>;
|
|
25
|
-
}
|
|
1
|
+
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
2
|
+
import { Command } from "./Command.js";
|
|
3
|
+
import { FrameworkEvent } from "./FrameworkEvent.js";
|
|
4
|
+
export declare abstract class Module {
|
|
5
|
+
protected path: string;
|
|
6
|
+
protected framework: ZumitoFramework;
|
|
7
|
+
protected commands: Map<string, Command>;
|
|
8
|
+
protected events: Map<string, FrameworkEvent>;
|
|
9
|
+
protected models: Map<string, any>;
|
|
10
|
+
constructor(path: any, framework: any);
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
registerCommands(): Promise<void>;
|
|
13
|
+
onCommandCreated(filePath: string): Promise<void>;
|
|
14
|
+
onCommandChanged(filePath: string): Promise<void>;
|
|
15
|
+
onErrorLoadingCommand(error: Error): void;
|
|
16
|
+
getCommands(): Map<string, Command>;
|
|
17
|
+
registerEvents(): Promise<void>;
|
|
18
|
+
registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
|
|
19
|
+
parseEventArgs(args: any[]): any;
|
|
20
|
+
getEvents(): Map<string, FrameworkEvent>;
|
|
21
|
+
registerTranslations(): Promise<void>;
|
|
22
|
+
parseTranslation(path: string, lang: string, json: any): any;
|
|
23
|
+
registerModels(): Promise<void>;
|
|
24
|
+
getModels(): Map<string, any>;
|
|
25
|
+
}
|
package/dist/types/Module.js
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import * as chokidar from 'chokidar';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import boxen from "boxen";
|
|
4
|
-
import * as fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { CommandInteraction, SelectMenuInteraction } from "discord.js";
|
|
7
|
-
export class Module {
|
|
8
|
-
path;
|
|
9
|
-
framework;
|
|
10
|
-
commands = new Map();
|
|
11
|
-
events = new Map();
|
|
12
|
-
models = new Map();
|
|
13
|
-
constructor(path, framework) {
|
|
14
|
-
this.path = path;
|
|
15
|
-
this.framework = framework;
|
|
16
|
-
}
|
|
17
|
-
async initialize() {
|
|
18
|
-
await this.registerCommands();
|
|
19
|
-
await this.registerEvents();
|
|
20
|
-
await this.registerTranslations();
|
|
21
|
-
await this.registerModels();
|
|
22
|
-
// console.error('[🔄🔴 ] Error initializing module ' + this.constructor.name);
|
|
23
|
-
// console.log(boxen(e + '\n' + e.stack, { padding: 1 }));
|
|
24
|
-
}
|
|
25
|
-
async registerCommands() {
|
|
26
|
-
if (fs.existsSync(path.join(this.path, 'commands'))) {
|
|
27
|
-
let files = fs.readdirSync(path.join(this.path, 'commands'));
|
|
28
|
-
for (let file of files) {
|
|
29
|
-
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
30
|
-
let command = await import('file://' + path.join(this.path, 'commands', file)).catch(e => {
|
|
31
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} command on module ${this.constructor.name}`);
|
|
32
|
-
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
33
|
-
});
|
|
34
|
-
command = Object.values(command)[0];
|
|
35
|
-
command = new command();
|
|
36
|
-
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
;
|
|
40
|
-
// register watcher
|
|
41
|
-
if (process.env.DEBUG) {
|
|
42
|
-
/*
|
|
43
|
-
Debug only cause in prod environment commands should't be changed.
|
|
44
|
-
Appart from that, esm module cache invalidation is not working properly
|
|
45
|
-
and can cause memory leaks and crashes.
|
|
46
|
-
*/
|
|
47
|
-
chokidar.watch(path.resolve(path.join(this.path, 'commands')), { ignored: /^\./, persistent: true, ignoreInitial: true })
|
|
48
|
-
.on('add', this.onCommandCreated.bind(this))
|
|
49
|
-
.on('change', this.onCommandChanged.bind(this))
|
|
50
|
-
//.on('unlink', function(path) {console.log('File', path, 'has been removed');})
|
|
51
|
-
.on('error', this.onErrorLoadingCommand.bind(this));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async onCommandCreated(filePath) {
|
|
56
|
-
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
57
|
-
let command = await import('file://' + filePath).catch(e => {
|
|
58
|
-
console.error('[🆕🔴 ] Error loading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
59
|
-
console.log(e + '\n' + e.name + '\n' + e.stack);
|
|
60
|
-
});
|
|
61
|
-
command = Object.values(command)[0];
|
|
62
|
-
command = new command();
|
|
63
|
-
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
64
|
-
console.debug('[🆕🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' loaded');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async onCommandChanged(filePath) {
|
|
68
|
-
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
69
|
-
let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch(e => {
|
|
70
|
-
console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
71
|
-
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
72
|
-
});
|
|
73
|
-
command = Object.values(command)[0];
|
|
74
|
-
command = new command();
|
|
75
|
-
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
76
|
-
console.debug('[🔄🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
onErrorLoadingCommand(error) {
|
|
80
|
-
console.error('[🔄🔴 ] Error reloading command');
|
|
81
|
-
console.log(boxen(error + '\n' + error.stack, { padding: 1 }));
|
|
82
|
-
}
|
|
83
|
-
getCommands() {
|
|
84
|
-
return this.commands;
|
|
85
|
-
}
|
|
86
|
-
async registerEvents() {
|
|
87
|
-
if (!fs.existsSync(path.join(this.path, 'events')))
|
|
88
|
-
return;
|
|
89
|
-
let files = fs.readdirSync(path.join(this.path, 'events'));
|
|
90
|
-
for (let file of files) {
|
|
91
|
-
if (file == 'discord') {
|
|
92
|
-
let moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
|
|
93
|
-
for (let moduleFileName of moduleFileNames) {
|
|
94
|
-
if (moduleFileName.endsWith('.js') || moduleFileName.endsWith('.ts')) {
|
|
95
|
-
let event = await import('file://' + path.join(this.path, 'events', 'discord', moduleFileName)).catch(e => {
|
|
96
|
-
console.error(`[🔄🔴 ] Error loading ${moduleFileName.slice(0, -3)} event on module ${this.constructor.name}`);
|
|
97
|
-
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
98
|
-
});
|
|
99
|
-
event = Object.values(event)[0];
|
|
100
|
-
event = new event();
|
|
101
|
-
this.events.set(event.constructor.name.toLowerCase(), event);
|
|
102
|
-
this.registerDiscordEvent(event);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
registerDiscordEvent(frameworkEvent) {
|
|
109
|
-
if (frameworkEvent.disabled)
|
|
110
|
-
return;
|
|
111
|
-
const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() + frameworkEvent.constructor.name.slice(1);
|
|
112
|
-
const emitter = this.framework.client;
|
|
113
|
-
const once = frameworkEvent.once; // A simple variable which returns if the event should run once
|
|
114
|
-
// Try catch block to throw an error if the code in try{} doesn't work
|
|
115
|
-
try {
|
|
116
|
-
emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(this.parseEventArgs(args))); // Run the event using the above defined emitter (client)
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.log(error, error.message, error, name);
|
|
120
|
-
console.error(error.stack); // If there is an error, console log the error stack message
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
parseEventArgs(args) {
|
|
124
|
-
let finalArgs = {
|
|
125
|
-
framework: this.framework,
|
|
126
|
-
client: this.framework.client,
|
|
127
|
-
};
|
|
128
|
-
args.forEach(arg => {
|
|
129
|
-
finalArgs[arg.constructor.name.toLowerCase()] = arg;
|
|
130
|
-
});
|
|
131
|
-
let interaction = args.find((arg) => arg instanceof SelectMenuInteraction || arg instanceof CommandInteraction);
|
|
132
|
-
if (interaction) {
|
|
133
|
-
finalArgs['interaction'] = interaction;
|
|
134
|
-
}
|
|
135
|
-
return finalArgs;
|
|
136
|
-
}
|
|
137
|
-
getEvents() {
|
|
138
|
-
return this.events;
|
|
139
|
-
}
|
|
140
|
-
async registerTranslations() {
|
|
141
|
-
if (!fs.existsSync(path.join(this.path, 'translations')))
|
|
142
|
-
return;
|
|
143
|
-
let files = fs.readdirSync(path.join(this.path, 'translations'));
|
|
144
|
-
for (let file of files) {
|
|
145
|
-
if (file.endsWith('.json')) {
|
|
146
|
-
let json = await import('file://' + `${this.path}/translations/${file}`, {
|
|
147
|
-
assert: {
|
|
148
|
-
type: "json",
|
|
149
|
-
},
|
|
150
|
-
}).catch(e => {
|
|
151
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
|
|
152
|
-
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
153
|
-
});
|
|
154
|
-
let lang = file.slice(0, -5);
|
|
155
|
-
this.parseTranslation('', lang, json.default);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
parseTranslation(path, lang, json) {
|
|
160
|
-
if (typeof json === 'object') {
|
|
161
|
-
for (let key in json) {
|
|
162
|
-
this.parseTranslation(path + key + '.', lang, json[key]);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
this.framework.translations.set(path.slice(0, -1), lang, json);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async registerModels() {
|
|
170
|
-
if (!fs.existsSync(path.join(this.path, 'models')))
|
|
171
|
-
return;
|
|
172
|
-
let files = fs.readdirSync(path.join(this.path, 'models'));
|
|
173
|
-
for (let file of files) {
|
|
174
|
-
if (file.endsWith('.json')) {
|
|
175
|
-
let modelName = file.slice(0, -5).charAt(0).toUpperCase() + file.slice(0, -5).slice(1);
|
|
176
|
-
let modelDefiniton = await import('file://' + `${this.path}/models/${file}`, {
|
|
177
|
-
assert: {
|
|
178
|
-
type: "json",
|
|
179
|
-
},
|
|
180
|
-
}).catch(e => {
|
|
181
|
-
console.error(`[🔄🔴 ] Error loading model ${modelName} on module ${this.constructor.name}`);
|
|
182
|
-
console.error(e, e.name, e.stack);
|
|
183
|
-
});
|
|
184
|
-
this.models.set(modelName, modelDefiniton.default);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
getModels() {
|
|
189
|
-
return this.models;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
1
|
+
import * as chokidar from 'chokidar';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import boxen from "boxen";
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { CommandInteraction, SelectMenuInteraction } from "discord.js";
|
|
7
|
+
export class Module {
|
|
8
|
+
path;
|
|
9
|
+
framework;
|
|
10
|
+
commands = new Map();
|
|
11
|
+
events = new Map();
|
|
12
|
+
models = new Map();
|
|
13
|
+
constructor(path, framework) {
|
|
14
|
+
this.path = path;
|
|
15
|
+
this.framework = framework;
|
|
16
|
+
}
|
|
17
|
+
async initialize() {
|
|
18
|
+
await this.registerCommands();
|
|
19
|
+
await this.registerEvents();
|
|
20
|
+
await this.registerTranslations();
|
|
21
|
+
await this.registerModels();
|
|
22
|
+
// console.error('[🔄🔴 ] Error initializing module ' + this.constructor.name);
|
|
23
|
+
// console.log(boxen(e + '\n' + e.stack, { padding: 1 }));
|
|
24
|
+
}
|
|
25
|
+
async registerCommands() {
|
|
26
|
+
if (fs.existsSync(path.join(this.path, 'commands'))) {
|
|
27
|
+
let files = fs.readdirSync(path.join(this.path, 'commands'));
|
|
28
|
+
for (let file of files) {
|
|
29
|
+
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
30
|
+
let command = await import('file://' + path.join(this.path, 'commands', file)).catch(e => {
|
|
31
|
+
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} command on module ${this.constructor.name}`);
|
|
32
|
+
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
33
|
+
});
|
|
34
|
+
command = Object.values(command)[0];
|
|
35
|
+
command = new command();
|
|
36
|
+
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
// register watcher
|
|
41
|
+
if (process.env.DEBUG) {
|
|
42
|
+
/*
|
|
43
|
+
Debug only cause in prod environment commands should't be changed.
|
|
44
|
+
Appart from that, esm module cache invalidation is not working properly
|
|
45
|
+
and can cause memory leaks and crashes.
|
|
46
|
+
*/
|
|
47
|
+
chokidar.watch(path.resolve(path.join(this.path, 'commands')), { ignored: /^\./, persistent: true, ignoreInitial: true })
|
|
48
|
+
.on('add', this.onCommandCreated.bind(this))
|
|
49
|
+
.on('change', this.onCommandChanged.bind(this))
|
|
50
|
+
//.on('unlink', function(path) {console.log('File', path, 'has been removed');})
|
|
51
|
+
.on('error', this.onErrorLoadingCommand.bind(this));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async onCommandCreated(filePath) {
|
|
56
|
+
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
57
|
+
let command = await import('file://' + filePath).catch(e => {
|
|
58
|
+
console.error('[🆕🔴 ] Error loading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
59
|
+
console.log(e + '\n' + e.name + '\n' + e.stack);
|
|
60
|
+
});
|
|
61
|
+
command = Object.values(command)[0];
|
|
62
|
+
command = new command();
|
|
63
|
+
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
64
|
+
console.debug('[🆕🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' loaded');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async onCommandChanged(filePath) {
|
|
68
|
+
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
69
|
+
let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch(e => {
|
|
70
|
+
console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
71
|
+
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
72
|
+
});
|
|
73
|
+
command = Object.values(command)[0];
|
|
74
|
+
command = new command();
|
|
75
|
+
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
76
|
+
console.debug('[🔄🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
onErrorLoadingCommand(error) {
|
|
80
|
+
console.error('[🔄🔴 ] Error reloading command');
|
|
81
|
+
console.log(boxen(error + '\n' + error.stack, { padding: 1 }));
|
|
82
|
+
}
|
|
83
|
+
getCommands() {
|
|
84
|
+
return this.commands;
|
|
85
|
+
}
|
|
86
|
+
async registerEvents() {
|
|
87
|
+
if (!fs.existsSync(path.join(this.path, 'events')))
|
|
88
|
+
return;
|
|
89
|
+
let files = fs.readdirSync(path.join(this.path, 'events'));
|
|
90
|
+
for (let file of files) {
|
|
91
|
+
if (file == 'discord') {
|
|
92
|
+
let moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
|
|
93
|
+
for (let moduleFileName of moduleFileNames) {
|
|
94
|
+
if (moduleFileName.endsWith('.js') || moduleFileName.endsWith('.ts')) {
|
|
95
|
+
let event = await import('file://' + path.join(this.path, 'events', 'discord', moduleFileName)).catch(e => {
|
|
96
|
+
console.error(`[🔄🔴 ] Error loading ${moduleFileName.slice(0, -3)} event on module ${this.constructor.name}`);
|
|
97
|
+
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
98
|
+
});
|
|
99
|
+
event = Object.values(event)[0];
|
|
100
|
+
event = new event();
|
|
101
|
+
this.events.set(event.constructor.name.toLowerCase(), event);
|
|
102
|
+
this.registerDiscordEvent(event);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
registerDiscordEvent(frameworkEvent) {
|
|
109
|
+
if (frameworkEvent.disabled)
|
|
110
|
+
return;
|
|
111
|
+
const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() + frameworkEvent.constructor.name.slice(1);
|
|
112
|
+
const emitter = this.framework.client;
|
|
113
|
+
const once = frameworkEvent.once; // A simple variable which returns if the event should run once
|
|
114
|
+
// Try catch block to throw an error if the code in try{} doesn't work
|
|
115
|
+
try {
|
|
116
|
+
emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(this.parseEventArgs(args))); // Run the event using the above defined emitter (client)
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.log(error, error.message, error, name);
|
|
120
|
+
console.error(error.stack); // If there is an error, console log the error stack message
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
parseEventArgs(args) {
|
|
124
|
+
let finalArgs = {
|
|
125
|
+
framework: this.framework,
|
|
126
|
+
client: this.framework.client,
|
|
127
|
+
};
|
|
128
|
+
args.forEach(arg => {
|
|
129
|
+
finalArgs[arg.constructor.name.toLowerCase()] = arg;
|
|
130
|
+
});
|
|
131
|
+
let interaction = args.find((arg) => arg instanceof SelectMenuInteraction || arg instanceof CommandInteraction);
|
|
132
|
+
if (interaction) {
|
|
133
|
+
finalArgs['interaction'] = interaction;
|
|
134
|
+
}
|
|
135
|
+
return finalArgs;
|
|
136
|
+
}
|
|
137
|
+
getEvents() {
|
|
138
|
+
return this.events;
|
|
139
|
+
}
|
|
140
|
+
async registerTranslations() {
|
|
141
|
+
if (!fs.existsSync(path.join(this.path, 'translations')))
|
|
142
|
+
return;
|
|
143
|
+
let files = fs.readdirSync(path.join(this.path, 'translations'));
|
|
144
|
+
for (let file of files) {
|
|
145
|
+
if (file.endsWith('.json')) {
|
|
146
|
+
let json = await import('file://' + `${this.path}/translations/${file}`, {
|
|
147
|
+
assert: {
|
|
148
|
+
type: "json",
|
|
149
|
+
},
|
|
150
|
+
}).catch(e => {
|
|
151
|
+
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
|
|
152
|
+
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
153
|
+
});
|
|
154
|
+
let lang = file.slice(0, -5);
|
|
155
|
+
this.parseTranslation('', lang, json.default);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
parseTranslation(path, lang, json) {
|
|
160
|
+
if (typeof json === 'object') {
|
|
161
|
+
for (let key in json) {
|
|
162
|
+
this.parseTranslation(path + key + '.', lang, json[key]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.framework.translations.set(path.slice(0, -1), lang, json);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async registerModels() {
|
|
170
|
+
if (!fs.existsSync(path.join(this.path, 'models')))
|
|
171
|
+
return;
|
|
172
|
+
let files = fs.readdirSync(path.join(this.path, 'models'));
|
|
173
|
+
for (let file of files) {
|
|
174
|
+
if (file.endsWith('.json')) {
|
|
175
|
+
let modelName = file.slice(0, -5).charAt(0).toUpperCase() + file.slice(0, -5).slice(1);
|
|
176
|
+
let modelDefiniton = await import('file://' + `${this.path}/models/${file}`, {
|
|
177
|
+
assert: {
|
|
178
|
+
type: "json",
|
|
179
|
+
},
|
|
180
|
+
}).catch(e => {
|
|
181
|
+
console.error(`[🔄🔴 ] Error loading model ${modelName} on module ${this.constructor.name}`);
|
|
182
|
+
console.error(e, e.name, e.stack);
|
|
183
|
+
});
|
|
184
|
+
this.models.set(modelName, modelDefiniton.default);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
getModels() {
|
|
189
|
+
return this.models;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Client, SelectMenuInteraction } from "discord.js";
|
|
2
|
-
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
3
|
-
export interface SelectMenuParameters {
|
|
4
|
-
path: string[];
|
|
5
|
-
interaction: SelectMenuInteraction;
|
|
6
|
-
client: Client;
|
|
7
|
-
framework: ZumitoFramework;
|
|
8
|
-
guildSettings?: any;
|
|
9
|
-
}
|
|
1
|
+
import { Client, SelectMenuInteraction } from "discord.js";
|
|
2
|
+
import { ZumitoFramework } from "../ZumitoFramework.js";
|
|
3
|
+
export interface SelectMenuParameters {
|
|
4
|
+
path: string[];
|
|
5
|
+
interaction: SelectMenuInteraction;
|
|
6
|
+
client: Client;
|
|
7
|
+
framework: ZumitoFramework;
|
|
8
|
+
guildSettings?: any;
|
|
9
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare class Translation {
|
|
2
|
-
text: Map<string, string>;
|
|
3
|
-
constructor();
|
|
4
|
-
get(language: string, params?: any): 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
|
-
}
|
|
1
|
+
export declare class Translation {
|
|
2
|
+
text: Map<string, string>;
|
|
3
|
+
constructor();
|
|
4
|
+
get(language: string, params?: any): 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
|
+
}
|