command/event hot-reloading

This commit is contained in:
Emily 2020-10-21 13:30:26 +11:00
parent 677a84e88c
commit 99e859dd48

View file

@ -61,13 +61,16 @@ class WoomyClient extends Eris.Client {
} }
reloadCommands () { reloadCommands () {
for (const cmd of this.commands) { this.commands.forEach(cmd => {
try { try {
delete require.cache[require.resolve(`${this.path}/commands/${cmd.category}/${cmd.name}.js`)];
this.commands.delete(cmd.name);
} catch (error) { } catch (error) {
this.logger.error('COMMAND_LOADER_ERROR', `Failed to unload ${cmd}: ${error}`);
}
});
} this.loadCommands();
}
} }
loadEventModules () { loadEventModules () {
@ -81,17 +84,21 @@ class WoomyClient extends Eris.Client {
this.logger.error('EVENT_LOADER_ERROR', `Failed to load ${file}: ${error}`); 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.`); this.logger.success('EVENT_LOADER_SUCCESS', `Loaded ${this.eventModules.size}/${this.eventFiles.length} event modules.`);
} }
reloadEventModules () { reloadEventModules () {
for (const file of this.eventFiles) { this.eventModules.forEach((props, event) => {
try { try {
delete require.cache[require.resolve(`${this.path}/event_modules/${props.wsEvent}/${event}.js`)];
this.eventModules.delete(event);
} catch (error) { } catch (error) {
this.logger.error('EVENT_LOADER_ERROR', `Failed to unload ${event}: ${error}`);
}
});
} this.loadEventModules();
}
} }
mainEventListener (wsEvent, param_1, param_2) { mainEventListener (wsEvent, param_1, param_2) {