command/event hot-reloading
This commit is contained in:
parent
677a84e88c
commit
99e859dd48
1 changed files with 15 additions and 8 deletions
23
bot/index.js
23
bot/index.js
|
@ -61,13 +61,16 @@ class WoomyClient extends Eris.Client {
|
|||
}
|
||||
|
||||
reloadCommands () {
|
||||
for (const cmd of this.commands) {
|
||||
this.commands.forEach(cmd => {
|
||||
try {
|
||||
|
||||
delete require.cache[require.resolve(`${this.path}/commands/${cmd.category}/${cmd.name}.js`)];
|
||||
this.commands.delete(cmd.name);
|
||||
} catch (error) {
|
||||
|
||||
this.logger.error('COMMAND_LOADER_ERROR', `Failed to unload ${cmd}: ${error}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.loadCommands();
|
||||
}
|
||||
|
||||
loadEventModules () {
|
||||
|
@ -81,17 +84,21 @@ class WoomyClient extends Eris.Client {
|
|||
this.logger.error('EVENT_LOADER_ERROR', `Failed to load ${file}: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.success('EVENT_LOADER_SUCCESS', `Loaded ${this.eventModules.size}/${this.eventFiles.length} event modules.`);
|
||||
}
|
||||
|
||||
reloadEventModules () {
|
||||
for (const file of this.eventFiles) {
|
||||
this.eventModules.forEach((props, event) => {
|
||||
try {
|
||||
|
||||
delete require.cache[require.resolve(`${this.path}/event_modules/${props.wsEvent}/${event}.js`)];
|
||||
this.eventModules.delete(event);
|
||||
} catch (error) {
|
||||
|
||||
this.logger.error('EVENT_LOADER_ERROR', `Failed to unload ${event}: ${error}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.loadEventModules();
|
||||
}
|
||||
|
||||
mainEventListener (wsEvent, param_1, param_2) {
|
||||
|
|
Loading…
Reference in a new issue