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-21 00:23:23 +00:00
|
|
|
const readyModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const errorModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent === '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-21 00:23:23 +00:00
|
|
|
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent === '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;
|