woomy-v2/bot/util/handlers/eventHandler.js

68 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-10-20 08:30:46 +00:00
/* eslint-disable indent */
2020-10-20 05:47:05 +00:00
class EventHandler {
constructor (client) {
this.client = client;
}
2020-10-20 08:30:46 +00:00
handle (wsEvent, param_1, param_2) {
switch (wsEvent) {
case 'ready': {
2020-10-20 12:34:38 +00:00
const readyModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'ready');
2020-10-20 08:30:46 +00:00
readyModules.forEach(module => module.run(this.client));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - error message
case 'error': {
2020-10-20 12:34:38 +00:00
const errorModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'error');
2020-10-20 08:30:46 +00:00
errorModules.forEach(module => module.run(this.client, param_1));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - message object
case 'messageCreate': {
2020-10-20 12:34:38 +00:00
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'messageCreate');
2020-10-20 08:30:46 +00:00
mCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - guild object
case 'guildCreate': {
2020-10-20 12:34:38 +00:00
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildCreate');
2020-10-20 08:30:46 +00:00
gCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - guild object
case 'guildDelete': {
2020-10-20 12:34:38 +00:00
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildDelete');
2020-10-20 08:30:46 +00:00
gDeleteModules.forEach(module => module.run(this.client, param_1));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - guild object | param_2 - member object
case 'guildMemberAdd': {
2020-10-20 12:34:38 +00:00
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildMemberAdd');
2020-10-20 08:30:46 +00:00
gMemberAddModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - guild object | param_2 - member object
case 'guildMemberRemove': {
2020-10-20 12:34:38 +00:00
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'guildMemberRemove');
2020-10-20 08:30:46 +00:00
gMemberRemoveModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
2020-10-20 05:47:05 +00:00
2020-10-20 08:30:46 +00:00
// param_1 - old voice state | param_2 - new voice state
case 'voiceStateUpdate': {
2020-10-20 12:34:38 +00:00
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent[0] === 'voiceStateUpdate');
2020-10-20 08:30:46 +00:00
vStateUpdateModules.forEach(module => module.run(this.client));
break;
}
}
2020-10-20 05:47:05 +00:00
}
}
module.exports = EventHandler;