clean up module loaders

This commit is contained in:
Emily 2020-10-21 11:23:23 +11:00
parent 85d0255ccc
commit a5c7aaef5f
3 changed files with 22 additions and 27 deletions

View file

@ -41,19 +41,16 @@ class WoomyClient extends Eris.Client {
}
loadCommands () {
const nameRegexp = /[^/]*$/;
const catRegexp = /.+?(?=\/)/;
for (const file of this.commandFiles) {
try {
const props = new (require(this.path + '/commands/' + file))(this);
props.help.name = nameRegexp.exec(file);
props.help.category = catRegexp.exec(file);
const name = file.substr(file.indexOf('/') + 1).slice(0, -3);
const category = file.substr(0, file.indexOf('/'));
const command = new (require(this.path + '/commands/' + file))(name, category);
this.commands.set(props.help.name, props);
this.cooldowns.set(props.help.name, new Map());
props.conf.aliases.forEach(alias => {
this.aliases.set(alias, props.help.name);
this.commands.set(command.name, command);
this.cooldowns.set(command.name, new Map());
command.aliases.forEach(alias => {
this.aliases.set(alias, command.name);
});
} catch (error) {
this.logger.error('COMMAND_LOADER_ERROR', `Failed to load ${file}: ${error}`);
@ -64,9 +61,9 @@ class WoomyClient extends Eris.Client {
}
reloadCommands () {
for (const file of this.commandFiles) {
for (const cmd of this.commands) {
try {
} catch (error) {
}
@ -74,25 +71,23 @@ class WoomyClient extends Eris.Client {
}
loadEventModules () {
const nameRegexp = /[^/]*$/;
const catRegexp = /.+?(?=\/)/;
for (const file of this.eventFiles) {
try {
const event = new (require(this.path + '/event_modules/' + file))(catRegexp.exec(file));
this.eventModules.set(nameRegexp.exec(file), event);
const name = file.substr(file.indexOf('/') + 1).slice(0, -3);
const category = file.substr(0, file.indexOf('/'));
const event = new (require(this.path + '/event_modules/' + file))(category);
this.eventModules.set(name, event);
} catch (error) {
this.logger.error('EVENT_LOADER_ERROR', `Failed to load ${file}: ${error}`);
}
}
console.log(this.eventModules)
this.logger.success('EVENT_LOADER_SUCCESS', `Loaded ${this.eventModules.size}/${this.eventFiles.length} event modules.`);
}
reloadEventModules () {
for (const file of this.eventFiles) {
try {
} catch (error) {
}

View file

@ -8,56 +8,56 @@ class EventHandler {
handle (wsEvent, param_1, param_2) {
switch (wsEvent) {
case 'ready': {
const readyModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'ready');
const readyModules = this.client.eventModules.filter(module => module.wsEvent === 'ready');
readyModules.forEach(module => module.run(this.client));
break;
}
// param_1 - error message
case 'error': {
const errorModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'error');
const errorModules = this.client.eventModules.filter(module => module.wsEvent === 'error');
errorModules.forEach(module => module.run(this.client, param_1));
break;
}
// param_1 - message object
case 'messageCreate': {
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'messageCreate');
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'messageCreate');
mCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
// param_1 - guild object
case 'guildCreate': {
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildCreate');
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'guildCreate');
gCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
// param_1 - guild object
case 'guildDelete': {
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildDelete');
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent === 'guildDelete');
gDeleteModules.forEach(module => module.run(this.client, param_1));
break;
}
// param_1 - guild object | param_2 - member object
case 'guildMemberAdd': {
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildMemberAdd');
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberAdd');
gMemberAddModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
// param_1 - guild object | param_2 - member object
case 'guildMemberRemove': {
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildMemberRemove');
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberRemove');
gMemberRemoveModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
// param_1 - old voice state | param_2 - new voice state
case 'voiceStateUpdate': {
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'voiceStateUpdate');
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent === 'voiceStateUpdate');
vStateUpdateModules.forEach(module => module.run(this.client));
break;
}