Skip to content

Commit

Permalink
feat: handle and forward WEBHOOKS_UPDATE events (#2762)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vladfrangu authored and SpaceEEC committed Aug 21, 2018
1 parent ab0ede0 commit 0401b8a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/client/websocket/packets/WebSocketPacketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
19 changes: 19 additions & 0 deletions src/client/websocket/packets/handlers/WebhooksUpdate.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -290,6 +291,7 @@ exports.Events = {
* * VOICE_STATE_UPDATE
* * TYPING_START
* * VOICE_SERVER_UPDATE
* * WEBHOOKS_UPDATE
* @typedef {string} WSEventType
*/
exports.WSEvents = keyMirror([
Expand Down Expand Up @@ -324,6 +326,7 @@ exports.WSEvents = keyMirror([
'VOICE_STATE_UPDATE',
'TYPING_START',
'VOICE_SERVER_UPDATE',
'WEBHOOKS_UPDATE',
]);

/**
Expand Down
7 changes: 5 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1976,7 +1978,8 @@ declare module 'discord.js' {
| 'PRESENCE_UPDATE'
| 'VOICE_STATE_UPDATE'
| 'TYPING_START'
| 'VOICE_SERVER_UPDATE';
| 'VOICE_SERVER_UPDATE'
| 'WEBHOOKS_UPDATE';

//#endregion
}

0 comments on commit 0401b8a

Please sign in to comment.