zumito-framework 1.1.81 → 1.1.83
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 +13 -14
- package/dist/ZumitoFramework.js +18 -57
- package/dist/{types → definitions}/Module.d.ts +4 -7
- package/dist/definitions/Module.js +129 -0
- package/dist/{types → definitions}/Translation.d.ts +0 -1
- package/dist/{types → definitions}/Translation.js +0 -1
- package/dist/{types → definitions/commands}/Command.d.ts +1 -1
- package/dist/{types → definitions/commands}/CommandParameters.d.ts +1 -1
- package/dist/{types → definitions/parameters}/EventParameters.d.ts +1 -1
- package/dist/{types/Commands → definitions/parameters}/SelectMenu.d.ts +1 -1
- package/dist/{types → definitions/parameters}/SelectMenuParameters.d.ts +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.js +13 -13
- package/dist/{baseModule → modules/core/baseModule}/events/discord/InteractionCreate.d.ts +3 -3
- package/dist/{baseModule → modules/core/baseModule}/events/discord/InteractionCreate.js +3 -3
- package/dist/{baseModule → modules/core/baseModule}/events/discord/MessageCreate.d.ts +2 -2
- package/dist/{baseModule → modules/core/baseModule}/events/discord/MessageCreate.js +6 -6
- package/dist/{baseModule → modules/core/baseModule}/models/Guild.d.ts +1 -1
- package/dist/{baseModule → modules/core/baseModule}/models/Guild.js +1 -1
- package/dist/services/CommandManager.d.ts +40 -0
- package/dist/services/CommandManager.js +160 -0
- package/dist/services/ModuleManager.d.ts +17 -0
- package/dist/services/ModuleManager.js +78 -0
- package/dist/{managers → services}/StatusManager.d.ts +1 -1
- package/dist/services/TranslationManager.d.ts +34 -0
- package/dist/services/TranslationManager.js +123 -0
- package/package.json +4 -4
- package/dist/TranslationManager.d.ts +0 -15
- package/dist/TranslationManager.js +0 -41
- package/dist/baseModule/index.d.ts +0 -7
- package/dist/baseModule/index.js +0 -20
- package/dist/types/Module.js +0 -210
- /package/dist/{types → definitions}/DatabaseModel.d.ts +0 -0
- /package/dist/{types → definitions}/DatabaseModel.js +0 -0
- /package/dist/{types → definitions}/FrameworkEvent.d.ts +0 -0
- /package/dist/{types → definitions}/FrameworkEvent.js +0 -0
- /package/dist/{types → definitions}/FrameworkSettings.d.ts +0 -0
- /package/dist/{types → definitions}/FrameworkSettings.js +0 -0
- /package/dist/{types → definitions}/StatusManagerOptions.d.ts +0 -0
- /package/dist/{types → definitions}/StatusManagerOptions.js +0 -0
- /package/dist/definitions/{ApiResponse.d.ts → api/ApiResponse.d.ts} +0 -0
- /package/dist/definitions/{ApiResponse.js → api/ApiResponse.js} +0 -0
- /package/dist/{types → definitions/commands}/Command.js +0 -0
- /package/dist/{types → definitions/commands}/CommandArgDefinition.d.ts +0 -0
- /package/dist/{types → definitions/commands}/CommandArgDefinition.js +0 -0
- /package/dist/{types → definitions/commands}/CommandArguments.d.ts +0 -0
- /package/dist/{types → definitions/commands}/CommandArguments.js +0 -0
- /package/dist/{types → definitions/commands}/CommandChoiceDefinition.d.ts +0 -0
- /package/dist/{types → definitions/commands}/CommandChoiceDefinition.js +0 -0
- /package/dist/{types → definitions/commands}/CommandParameters.js +0 -0
- /package/dist/{types → definitions/commands}/CommandType.d.ts +0 -0
- /package/dist/{types → definitions/commands}/CommandType.js +0 -0
- /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.d.ts +0 -0
- /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.js +0 -0
- /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.d.ts +0 -0
- /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.js +0 -0
- /package/dist/{types → definitions/parameters}/EventParameters.js +0 -0
- /package/dist/{types/Commands → definitions/parameters}/SelectMenu.js +0 -0
- /package/dist/{types → definitions/parameters}/SelectMenuParameters.js +0 -0
- /package/dist/{utils → services}/DatabaseConfigLoader.d.ts +0 -0
- /package/dist/{utils → services}/DatabaseConfigLoader.js +0 -0
- /package/dist/{utils → services}/EmojiFallback.d.ts +0 -0
- /package/dist/{utils → services}/EmojiFallback.js +0 -0
- /package/dist/{managers → services}/EmojiManager.d.ts +0 -0
- /package/dist/{managers → services}/EmojiManager.js +0 -0
- /package/dist/{managers → services}/EventManager.d.ts +0 -0
- /package/dist/{managers → services}/EventManager.js +0 -0
- /package/dist/{utils → services}/InteractionIdGenerator.d.ts +0 -0
- /package/dist/{utils → services}/InteractionIdGenerator.js +0 -0
- /package/dist/{managers → services}/StatusManager.js +0 -0
- /package/dist/{utils → services}/TextFormatter.d.ts +0 -0
- /package/dist/{utils → services}/TextFormatter.js +0 -0
package/dist/types/Module.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
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 { ButtonInteraction, CommandInteraction, ModalSubmitInteraction, StringSelectMenuInteraction, } from 'discord.js';
|
|
7
|
-
export class Module {
|
|
8
|
-
path;
|
|
9
|
-
framework;
|
|
10
|
-
commands = new Map();
|
|
11
|
-
events = new Map();
|
|
12
|
-
models = [];
|
|
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
|
-
}
|
|
23
|
-
async registerCommands() {
|
|
24
|
-
if (fs.existsSync(path.join(this.path, 'commands'))) {
|
|
25
|
-
const files = fs.readdirSync(path.join(this.path, 'commands'));
|
|
26
|
-
for (const file of files) {
|
|
27
|
-
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
28
|
-
let command = await import('file://' + path.join(this.path, 'commands', file)).catch((e) => {
|
|
29
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} command on module ${this.constructor.name}`);
|
|
30
|
-
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
31
|
-
});
|
|
32
|
-
command = Object.values(command)[0];
|
|
33
|
-
command = new command();
|
|
34
|
-
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// register watcher
|
|
38
|
-
if (process.env.DEBUG) {
|
|
39
|
-
/*
|
|
40
|
-
Debug only cause in prod environment commands should't be changed.
|
|
41
|
-
Appart from that, esm module cache invalidation is not working properly
|
|
42
|
-
and can cause memory leaks and crashes.
|
|
43
|
-
*/
|
|
44
|
-
chokidar
|
|
45
|
-
.watch(path.resolve(path.join(this.path, 'commands')), {
|
|
46
|
-
ignored: /^\./,
|
|
47
|
-
persistent: true,
|
|
48
|
-
ignoreInitial: true,
|
|
49
|
-
})
|
|
50
|
-
.on('add', this.onCommandCreated.bind(this))
|
|
51
|
-
.on('change', this.onCommandChanged.bind(this))
|
|
52
|
-
//.on('unlink', function(path) {console.log('File', path, 'has been removed');})
|
|
53
|
-
.on('error', this.onErrorLoadingCommand.bind(this));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async onCommandCreated(filePath) {
|
|
58
|
-
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
59
|
-
let command = await import('file://' + filePath).catch(e => {
|
|
60
|
-
console.error('[🆕🔴 ] Error loading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
61
|
-
console.log(e + '\n' + e.name + '\n' + e.stack);
|
|
62
|
-
});
|
|
63
|
-
command = Object.values(command)[0];
|
|
64
|
-
command = new command();
|
|
65
|
-
this.framework.commands.set(command.constructor.name.toLowerCase(), command);
|
|
66
|
-
console.debug('[🆕🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' loaded');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async onCommandChanged(filePath) {
|
|
70
|
-
if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
71
|
-
let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch(e => {
|
|
72
|
-
console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
|
|
73
|
-
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
74
|
-
});
|
|
75
|
-
command = Object.values(command)[0];
|
|
76
|
-
command = new command();
|
|
77
|
-
this.framework.commands.set(command.constructor.name.toLowerCase(), command);
|
|
78
|
-
console.debug('[🔄🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
onErrorLoadingCommand(error) {
|
|
82
|
-
console.error('[🔄🔴 ] Error reloading command');
|
|
83
|
-
console.log(boxen(error + '\n' + error.stack, { padding: 1 }));
|
|
84
|
-
}
|
|
85
|
-
getCommands() {
|
|
86
|
-
return this.commands;
|
|
87
|
-
}
|
|
88
|
-
async registerEvents() {
|
|
89
|
-
if (!fs.existsSync(path.join(this.path, 'events')))
|
|
90
|
-
return;
|
|
91
|
-
const files = fs.readdirSync(path.join(this.path, 'events'));
|
|
92
|
-
for (const file of files) {
|
|
93
|
-
// if file is folder
|
|
94
|
-
if (fs.lstatSync(path.join(this.path, 'events', file)).isDirectory()) {
|
|
95
|
-
console.log('registering events folder ' + file);
|
|
96
|
-
this.registerEventsFolder(file);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async registerEventsFolder(folder) {
|
|
101
|
-
const folderPath = path.join(this.path, 'events', folder);
|
|
102
|
-
if (!fs.existsSync(folderPath))
|
|
103
|
-
throw new Error(`Folder ${folder} doesn't exist`);
|
|
104
|
-
const files = fs.readdirSync(folderPath);
|
|
105
|
-
for (const file of files) {
|
|
106
|
-
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
107
|
-
let event = await import('file://' + path.join(folderPath, file)).catch((e) => {
|
|
108
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} event on module ${this.constructor.name}`);
|
|
109
|
-
});
|
|
110
|
-
event = Object.values(event)[0];
|
|
111
|
-
event = new event();
|
|
112
|
-
this.events.set(event.constructor.name.toLowerCase(), event);
|
|
113
|
-
this.registerEvent(event, folder);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
registerEvent(frameworkEvent, emitterName) {
|
|
118
|
-
if (frameworkEvent.disabled)
|
|
119
|
-
return;
|
|
120
|
-
const once = frameworkEvent.once;
|
|
121
|
-
const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() +
|
|
122
|
-
frameworkEvent.constructor.name.slice(1);
|
|
123
|
-
this.framework.eventManager.addEventListener(emitterName, eventName, (...args) => {
|
|
124
|
-
const finalArgs = this.parseEventArgs(args);
|
|
125
|
-
frameworkEvent.execute(finalArgs);
|
|
126
|
-
}, { once });
|
|
127
|
-
}
|
|
128
|
-
parseEventArgs(args) {
|
|
129
|
-
const finalArgs = {
|
|
130
|
-
framework: this.framework,
|
|
131
|
-
client: this.framework.client,
|
|
132
|
-
};
|
|
133
|
-
args.forEach((arg) => {
|
|
134
|
-
finalArgs[arg.constructor.name.toLowerCase()] = arg;
|
|
135
|
-
});
|
|
136
|
-
const interaction = args.find((arg) => arg instanceof StringSelectMenuInteraction ||
|
|
137
|
-
arg instanceof CommandInteraction ||
|
|
138
|
-
arg instanceof ButtonInteraction ||
|
|
139
|
-
arg instanceof ModalSubmitInteraction);
|
|
140
|
-
if (interaction) {
|
|
141
|
-
finalArgs['interaction'] = interaction;
|
|
142
|
-
}
|
|
143
|
-
return finalArgs;
|
|
144
|
-
}
|
|
145
|
-
getEvents() {
|
|
146
|
-
return this.events;
|
|
147
|
-
}
|
|
148
|
-
async registerTranslations(subpath = '') {
|
|
149
|
-
if (!fs.existsSync(path.join(this.path, 'translations', subpath)))
|
|
150
|
-
return;
|
|
151
|
-
const files = fs.readdirSync(path.join(this.path, 'translations', subpath));
|
|
152
|
-
for (const file of files) {
|
|
153
|
-
if (file.endsWith('.json')) {
|
|
154
|
-
const json = await this.loadTranslationFile(subpath, file);
|
|
155
|
-
const lang = file.slice(0, -5);
|
|
156
|
-
const baseKey = subpath
|
|
157
|
-
? subpath.replaceAll('/', '.').replaceAll('\\', '.') + '.'
|
|
158
|
-
: '';
|
|
159
|
-
this.parseTranslation(baseKey, lang, json);
|
|
160
|
-
}
|
|
161
|
-
else if (fs
|
|
162
|
-
.lstatSync(path.join(this.path, 'translations', subpath, file))
|
|
163
|
-
.isDirectory()) {
|
|
164
|
-
await this.registerTranslations(path.join(subpath, file));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async loadTranslationFile(subpath, file) {
|
|
169
|
-
if (subpath)
|
|
170
|
-
subpath = subpath + '/';
|
|
171
|
-
const json = await import('file://' + `${this.path}/translations/${subpath}${file}`, {
|
|
172
|
-
assert: {
|
|
173
|
-
type: 'json',
|
|
174
|
-
},
|
|
175
|
-
}).catch((e) => {
|
|
176
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
|
|
177
|
-
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
178
|
-
});
|
|
179
|
-
return json.default;
|
|
180
|
-
}
|
|
181
|
-
parseTranslation(path, lang, json) {
|
|
182
|
-
if (typeof json === 'object') {
|
|
183
|
-
for (const key in json) {
|
|
184
|
-
this.parseTranslation(path + key + '.', lang, json[key]);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
this.framework.translations.set(path.slice(0, -1), lang, json);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
async registerModels() {
|
|
192
|
-
if (!fs.existsSync(path.join(this.path, 'models')))
|
|
193
|
-
return;
|
|
194
|
-
const files = fs.readdirSync(path.join(this.path, 'models'));
|
|
195
|
-
for (const file of files) {
|
|
196
|
-
if (file.endsWith('.ts') || file.endsWith('.js')) {
|
|
197
|
-
let model = await import('file://' + `${this.path}/models/${file}`).catch((e) => {
|
|
198
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} model on module ${this.constructor.name}`);
|
|
199
|
-
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
200
|
-
});
|
|
201
|
-
model = Object.values(model)[0];
|
|
202
|
-
model = new model();
|
|
203
|
-
this.models.push(model);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
getModels() {
|
|
208
|
-
return this.models;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|