Tracking of GUILD_ROLE_CREATE/UPDATE/DELETE events

This commit is contained in:
hydrabolt
2016-04-17 15:17:18 +01:00
parent 4de1f4ce99
commit bbf7be7dfa
6 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
'use strict';
const AbstractHandler = require('./AbstractHandler');
const Structure = name => require(`../../../../structures/${name}`);
const Constants = require('../../../../util/Constants');
const CloneObject = require('../../../../util/CloneObject');
const Role = Structure('Role');
const Guild = Structure('Guild');
class GuildRoleUpdateHandler extends AbstractHandler {
constructor(packetManager) {
super(packetManager);
}
handle(packet) {
let data = packet.d;
let client = this.packetManager.client;
let guild = client.store.get('guilds', data.guild_id);
if (guild) {
let existingRole = guild.store.get('roles', data.role.id);
if (existingRole) {
let oldRole = CloneObject(existingRole);
existingRole.setup(data.role);
client.emit(Constants.Events.GUILD_ROLE_UPDATE, guild, oldRole, existingRole);
}
}
}
};
module.exports = GuildRoleUpdateHandler;