feat: handle and forward WEBHOOKS_UPDATE events (#2762)

* src: Handle WEBHOOK_UPDATE events

* Commit rename of 77'
Or adding the letter S

* I missed this

* Properly do this now
Typos everywhere

* Typings

* refactor: remove now unnecessary guild variable
This commit is contained in:
Frangu Vlad
2018-08-21 11:38:35 +03:00
committed by SpaceEEC
parent ab0ede0d5a
commit 0401b8ad77
4 changed files with 28 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ class WebSocketPacketManager {
this.register(WSEvents.MESSAGE_REACTION_ADD, require('./handlers/MessageReactionAdd'));
this.register(WSEvents.MESSAGE_REACTION_REMOVE, require('./handlers/MessageReactionRemove'));
this.register(WSEvents.MESSAGE_REACTION_REMOVE_ALL, require('./handlers/MessageReactionRemoveAll'));
this.register(WSEvents.WEBHOOKS_UPDATE, require('./handlers/WebhooksUpdate'));
}
get client() {

View File

@@ -0,0 +1,19 @@
const AbstractHandler = require('./AbstractHandler');
const { Events } = require('../../../../util/Constants');
class WebhooksUpdate extends AbstractHandler {
handle(packet) {
const client = this.packetManager.client;
const data = packet.d;
const channel = client.channels.get(data.channel_id);
if (channel) client.emit(Events.WEBHOOKS_UPDATE, channel);
}
}
/**
* Emitted whenever a guild text channel has its webhooks changed.
* @event Client#webhookUpdate
* @param {TextChannel} channel The channel that had a webhook update
*/
module.exports = WebhooksUpdate;

View File

@@ -249,6 +249,7 @@ exports.Events = {
VOICE_BROADCAST_UNSUBSCRIBE: 'unsubscribe',
TYPING_START: 'typingStart',
TYPING_STOP: 'typingStop',
WEBHOOKS_UPDATE: 'webhookUpdate',
DISCONNECT: 'disconnect',
RECONNECTING: 'reconnecting',
ERROR: 'error',
@@ -290,6 +291,7 @@ exports.Events = {
* * VOICE_STATE_UPDATE
* * TYPING_START
* * VOICE_SERVER_UPDATE
* * WEBHOOKS_UPDATE
* @typedef {string} WSEventType
*/
exports.WSEvents = keyMirror([
@@ -324,6 +326,7 @@ exports.WSEvents = keyMirror([
'VOICE_STATE_UPDATE',
'TYPING_START',
'VOICE_SERVER_UPDATE',
'WEBHOOKS_UPDATE',
]);
/**

7
typings/index.d.ts vendored
View File

@@ -140,7 +140,8 @@ declare module 'discord.js' {
public on(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this;
public on(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
public on(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
public once(event: 'voiceStateUpdate', listener: (oldState: VoiceState, newState: VoiceState) => void): this;
public on(event: 'voiceStateUpdate', listener: (oldState: VoiceState, newState: VoiceState) => void): this;
public on(event: 'webhookUpdate', listener: (channel: TextChannel) => void): this;
public on(event: string, listener: Function): this;
public once(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel) => void): this;
@@ -171,6 +172,7 @@ declare module 'discord.js' {
public once(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
public once(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
public once(event: 'voiceStateUpdate', listener: (oldState: VoiceState, newState: VoiceState) => void): this;
public once(event: 'webhookUpdate', listener: (channel: TextChannel) => void): this;
public once(event: string, listener: Function): this;
}
@@ -1976,7 +1978,8 @@ declare module 'discord.js' {
| 'PRESENCE_UPDATE'
| 'VOICE_STATE_UPDATE'
| 'TYPING_START'
| 'VOICE_SERVER_UPDATE';
| 'VOICE_SERVER_UPDATE'
| 'WEBHOOKS_UPDATE';
//#endregion
}