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:47:14 +00:00
|
|
|
/**
|
|
|
|
* doesnt work because array
|
|
|
|
* Collection [Map] {
|
|
|
|
* [ 'ready.js', index: 6, input: 'ready/ready.js', groups: undefined ] => Ready {
|
|
|
|
* wsEvent: [ 'ready', index: 0, input: 'ready/ready.js', groups: undefined ]
|
|
|
|
* },
|
|
|
|
* baseObject: undefined,
|
|
|
|
* limit: undefined
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2020-10-20 08:30:46 +00:00
|
|
|
handle (wsEvent, param_1, param_2) {
|
|
|
|
switch (wsEvent) {
|
|
|
|
case 'ready': {
|
|
|
|
const readyModules = this.client.eventModules.filter(module => module.wsEvent === 'ready');
|
|
|
|
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': {
|
|
|
|
const errorModules = this.client.eventModules.filter(module => module.wsEvent === 'error');
|
|
|
|
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': {
|
|
|
|
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'messageCreate');
|
|
|
|
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': {
|
|
|
|
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'guildCreate');
|
|
|
|
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': {
|
|
|
|
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent === 'guildDelete');
|
|
|
|
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': {
|
|
|
|
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberAdd');
|
|
|
|
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': {
|
|
|
|
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberRemove');
|
|
|
|
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': {
|
|
|
|
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent === 'voiceStateUpdate');
|
|
|
|
vStateUpdateModules.forEach(module => module.run(this.client));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 05:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = EventHandler;
|