-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
8 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters