mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
Tracking of GUILD_ROLE_CREATE/UPDATE/DELETE events
This commit is contained in:
@@ -17,6 +17,9 @@ class WebSocketPacketManager {
|
|||||||
this.register(Constants.WSEvents.GUILD_MEMBER_ADD, 'GuildMemberAdd');
|
this.register(Constants.WSEvents.GUILD_MEMBER_ADD, 'GuildMemberAdd');
|
||||||
this.register(Constants.WSEvents.GUILD_MEMBER_REMOVE, 'GuildMemberRemove');
|
this.register(Constants.WSEvents.GUILD_MEMBER_REMOVE, 'GuildMemberRemove');
|
||||||
this.register(Constants.WSEvents.GUILD_MEMBER_UPDATE, 'GuildMemberUpdate');
|
this.register(Constants.WSEvents.GUILD_MEMBER_UPDATE, 'GuildMemberUpdate');
|
||||||
|
this.register(Constants.WSEvents.GUILD_ROLE_CREATE, 'GuildRoleCreate');
|
||||||
|
this.register(Constants.WSEvents.GUILD_ROLE_DELETE, 'GuildRoleDelete');
|
||||||
|
this.register(Constants.WSEvents.GUILD_ROLE_UPDATE, 'GuildRoleUpdate');
|
||||||
this.register(Constants.WSEvents.CHANNEL_CREATE, 'ChannelCreate');
|
this.register(Constants.WSEvents.CHANNEL_CREATE, 'ChannelCreate');
|
||||||
this.register(Constants.WSEvents.CHANNEL_DELETE, 'ChannelDelete');
|
this.register(Constants.WSEvents.CHANNEL_DELETE, 'ChannelDelete');
|
||||||
this.register(Constants.WSEvents.CHANNEL_UPDATE, 'ChannelUpdate');
|
this.register(Constants.WSEvents.CHANNEL_UPDATE, 'ChannelUpdate');
|
||||||
|
|||||||
36
src/client/websocket/packets/handlers/GuildRoleCreate.js
Normal file
36
src/client/websocket/packets/handlers/GuildRoleCreate.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const AbstractHandler = require('./AbstractHandler');
|
||||||
|
const Structure = name => require(`../../../../structures/${name}`);
|
||||||
|
const Constants = require('../../../../util/Constants');
|
||||||
|
|
||||||
|
const Role = Structure('Role');
|
||||||
|
const Guild = Structure('Guild');
|
||||||
|
|
||||||
|
class GuildRoleCreateHandler 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 already = guild.store.get('roles', data.role.id);
|
||||||
|
let role = new Role(guild, data.role);
|
||||||
|
guild.store.add('roles', role);
|
||||||
|
|
||||||
|
if (!already) {
|
||||||
|
client.emit(Constants.Events.GUILD_ROLE_CREATE, guild, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GuildRoleCreateHandler;
|
||||||
34
src/client/websocket/packets/handlers/GuildRoleDelete.js
Normal file
34
src/client/websocket/packets/handlers/GuildRoleDelete.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const AbstractHandler = require('./AbstractHandler');
|
||||||
|
const Structure = name => require(`../../../../structures/${name}`);
|
||||||
|
const Constants = require('../../../../util/Constants');
|
||||||
|
|
||||||
|
const Role = Structure('Role');
|
||||||
|
const Guild = Structure('Guild');
|
||||||
|
|
||||||
|
class GuildRoleDeleteHandler 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 exists = guild.store.get('roles', data.role_id);
|
||||||
|
if (exists) {
|
||||||
|
guild.store.remove('roles', data.role_id);
|
||||||
|
client.emit(Constants.Events.GUILD_ROLE_DELETE, guild, exists);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GuildRoleDeleteHandler;
|
||||||
36
src/client/websocket/packets/handlers/GuildRoleUpdate.js
Normal file
36
src/client/websocket/packets/handlers/GuildRoleUpdate.js
Normal 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;
|
||||||
@@ -84,6 +84,9 @@ const Events = exports.Events = {
|
|||||||
GUILD_MEMBER_ADD: 'guildMemberAdd',
|
GUILD_MEMBER_ADD: 'guildMemberAdd',
|
||||||
GUILD_MEMBER_REMOVE: 'guildMemberRemove',
|
GUILD_MEMBER_REMOVE: 'guildMemberRemove',
|
||||||
GUILD_MEMBER_ROLES_UPDATE: 'guildMemberRolesUpdate',
|
GUILD_MEMBER_ROLES_UPDATE: 'guildMemberRolesUpdate',
|
||||||
|
GUILD_ROLE_CREATE: 'guildRoleCreate',
|
||||||
|
GUILD_ROLE_DELETE: 'guildRoleDelete',
|
||||||
|
GUILD_ROLE_UPDATE: 'guildRoleUpdate',
|
||||||
CHANNEL_CREATE: 'channelCreate',
|
CHANNEL_CREATE: 'channelCreate',
|
||||||
CHANNEL_DELETE: 'channelDelete',
|
CHANNEL_DELETE: 'channelDelete',
|
||||||
CHANNEL_UPDATE: 'channelUpdate',
|
CHANNEL_UPDATE: 'channelUpdate',
|
||||||
|
|||||||
@@ -37,3 +37,14 @@ client.on('guildMemberRemove', (guild, user) => {
|
|||||||
console.log('dead guild member', user.username, 'in', guild.name);
|
console.log('dead guild member', user.username, 'in', guild.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('guildRoleCreate', (guild, role) => {
|
||||||
|
console.log('new role', role.name, 'in', guild.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('guildRoleDelete', (guild, role) => {
|
||||||
|
console.log('dead role', role.name, 'in', guild.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('guildRoleUpdate', (guild, old, newRole) => {
|
||||||
|
console.log('updated role', old.name, 'to', newRole.name, 'in', guild.name);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user