mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Client): backport INVITE_CREATE and INVITE_DELETE events (#3728)
* Backport INVITE_CREATE and INVITE_DELETE * Register events to Websocket * Dont create an Invite if the guild is null * Null check channel too
This commit is contained in:
@@ -20,6 +20,8 @@ class ActionsManager {
|
||||
this.register(require('./GuildRoleCreate'));
|
||||
this.register(require('./GuildRoleDelete'));
|
||||
this.register(require('./GuildRoleUpdate'));
|
||||
this.register(require('./InviteCreate'));
|
||||
this.register(require('./InviteDelete'));
|
||||
this.register(require('./UserGet'));
|
||||
this.register(require('./UserUpdate'));
|
||||
this.register(require('./UserNoteUpdate'));
|
||||
|
||||
29
src/client/actions/InviteCreate.js
Normal file
29
src/client/actions/InviteCreate.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class InviteCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
const channel = client.channels.get(data.channel_id);
|
||||
if (guild && channel) {
|
||||
const inviteData = Object.assign(data, { guild, channel });
|
||||
const invite = new Invite(client, inviteData);
|
||||
/**
|
||||
* Emitted when an invite is created.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* @event Client#inviteCreate
|
||||
* @param {Invite} invite The invite that was created
|
||||
*/
|
||||
client.emit(Events.INVITE_CREATE, invite);
|
||||
return { invite };
|
||||
}
|
||||
return { invite: null };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteCreateAction;
|
||||
25
src/client/actions/InviteDelete.js
Normal file
25
src/client/actions/InviteDelete.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class InviteDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
const channel = client.channels.get(data.channel_id);
|
||||
if (guild && channel) {
|
||||
const inviteData = Object.assign(data, { guild, channel });
|
||||
const invite = new Invite(client, inviteData);
|
||||
/**
|
||||
* Emitted when an invite is deleted.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* @event Client#inviteDelete
|
||||
* @param {Invite} invite The invite that was deleted
|
||||
*/
|
||||
client.emit(Events.INVITE_DELETE, invite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteDeleteAction;
|
||||
@@ -32,6 +32,8 @@ class WebSocketPacketManager {
|
||||
this.register(Constants.WSEvents.GUILD_EMOJIS_UPDATE, require('./handlers/GuildEmojisUpdate'));
|
||||
this.register(Constants.WSEvents.GUILD_MEMBERS_CHUNK, require('./handlers/GuildMembersChunk'));
|
||||
this.register(Constants.WSEvents.GUILD_INTEGRATIONS_UPDATE, require('./handlers/GuildIntegrationsUpdate'));
|
||||
this.register(Constants.WSEvents.INVITE_CREATE, require('./handlers/InviteCreate'));
|
||||
this.register(Constants.WSEvents.INVITE_DELETE, require('./handlers/InviteDelete'));
|
||||
this.register(Constants.WSEvents.CHANNEL_CREATE, require('./handlers/ChannelCreate'));
|
||||
this.register(Constants.WSEvents.CHANNEL_DELETE, require('./handlers/ChannelDelete'));
|
||||
this.register(Constants.WSEvents.CHANNEL_UPDATE, require('./handlers/ChannelUpdate'));
|
||||
|
||||
11
src/client/websocket/packets/handlers/InviteCreate.js
Normal file
11
src/client/websocket/packets/handlers/InviteCreate.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
|
||||
class InviteCreateHandler extends AbstractHandler {
|
||||
handle(packet) {
|
||||
const client = this.packetManager.client;
|
||||
const data = packet.d;
|
||||
client.actions.InviteCreate.handle(data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteCreateHandler;
|
||||
11
src/client/websocket/packets/handlers/InviteDelete.js
Normal file
11
src/client/websocket/packets/handlers/InviteDelete.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
|
||||
class InviteDeleteHandler extends AbstractHandler {
|
||||
handle(packet) {
|
||||
const client = this.packetManager.client;
|
||||
const data = packet.d;
|
||||
client.actions.InviteDelete.handle(data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteDeleteHandler;
|
||||
@@ -337,6 +337,8 @@ exports.Events = {
|
||||
GUILD_EMOJI_UPDATE: 'emojiUpdate',
|
||||
GUILD_BAN_ADD: 'guildBanAdd',
|
||||
GUILD_BAN_REMOVE: 'guildBanRemove',
|
||||
INVITE_CREATE: 'inviteCreate',
|
||||
INVITE_DELETE: 'inviteDelete',
|
||||
CHANNEL_CREATE: 'channelCreate',
|
||||
CHANNEL_DELETE: 'channelDelete',
|
||||
CHANNEL_UPDATE: 'channelUpdate',
|
||||
@@ -447,6 +449,8 @@ exports.WSEvents = {
|
||||
GUILD_BAN_ADD: 'GUILD_BAN_ADD',
|
||||
GUILD_BAN_REMOVE: 'GUILD_BAN_REMOVE',
|
||||
GUILD_EMOJIS_UPDATE: 'GUILD_EMOJIS_UPDATE',
|
||||
INVITE_CREATE: 'INVITE_CREATE',
|
||||
INVITE_DELETE: 'INVITE_DELETE',
|
||||
CHANNEL_CREATE: 'CHANNEL_CREATE',
|
||||
CHANNEL_DELETE: 'CHANNEL_DELETE',
|
||||
CHANNEL_UPDATE: 'CHANNEL_UPDATE',
|
||||
|
||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -132,6 +132,7 @@ declare module 'discord.js' {
|
||||
public on(event: 'guildUnavailable', listener: (guild: Guild) => void): this;
|
||||
public on(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this;
|
||||
public on(event: 'guildIntegrationsUpdate', listener: (guild: Guild) => void): this;
|
||||
public on(event: 'inviteCreate' | 'inviteDelete', listener: (invite: Invite) => void): this;
|
||||
public on(event: 'message', listener: (message: Message) => void): this;
|
||||
public on(event: 'messageDelete', listener: (message: Message) => void): this;
|
||||
public on(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message>) => void): this;
|
||||
|
||||
Reference in New Issue
Block a user