From d5c3fa3ad11054403094b05c283b97d725452f85 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Tue, 15 Jun 2021 01:30:13 +0530 Subject: [PATCH 1/8] feat: stage instance invite --- src/structures/Invite.js | 4 ++++ src/structures/StageInstanceInvite.js | 31 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/structures/StageInstanceInvite.js diff --git a/src/structures/Invite.js b/src/structures/Invite.js index be21bc3ce098..0f4cf7bb3941 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -2,6 +2,7 @@ const Base = require('./Base'); const IntegrationApplication = require('./IntegrationApplication'); +const StageInstanceInvite = require('./StageInstanceInvite'); const { Error } = require('../errors'); const { Endpoints } = require('../util/Constants'); const Permissions = require('../util/Permissions'); @@ -112,6 +113,9 @@ class Invite extends Base { this.createdTimestamp = 'created_at' in data ? new Date(data.created_at).getTime() : null; this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; + + this.stageInstance = + 'stage_instance' in data ? new StageInstanceInvite(this.client, data.stage_instance, this.guild) : null; } /** diff --git a/src/structures/StageInstanceInvite.js b/src/structures/StageInstanceInvite.js new file mode 100644 index 000000000000..366123817cab --- /dev/null +++ b/src/structures/StageInstanceInvite.js @@ -0,0 +1,31 @@ +'use strict'; + +const Base = require('./Base'); +const Collection = require('../util/Collection'); + +class StageInstanceInvite extends Base { + constructor(client, data, guild) { + super(client); + + this.guild = guild; + + this.members = new Collection(); + + this._patch(data); + } + + _patch(data) { + this.topic = data.topic; + + this.participantCount = data.participant_count; + + this.speakerCount = data.speaker_count; + + for (const rawMember of data.members) { + const member = this.guild.members.add(rawMember); + this.members.set(member.id, member); + } + } +} + +module.exports = StageInstanceInvite; From 4125884e0bd92902ee42a05a0cc5842eb2448c3f Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Tue, 15 Jun 2021 17:43:00 +0530 Subject: [PATCH 2/8] refactor: change StageInstanceInvite to InviteStageInstance --- src/structures/Invite.js | 4 ++-- .../{StageInstanceInvite.js => InviteStageInstance.js} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/structures/{StageInstanceInvite.js => InviteStageInstance.js} (87%) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 0f4cf7bb3941..4f0052bf345d 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -2,7 +2,7 @@ const Base = require('./Base'); const IntegrationApplication = require('./IntegrationApplication'); -const StageInstanceInvite = require('./StageInstanceInvite'); +const InviteStageInstance = require('./InviteStageInstance'); const { Error } = require('../errors'); const { Endpoints } = require('../util/Constants'); const Permissions = require('../util/Permissions'); @@ -115,7 +115,7 @@ class Invite extends Base { this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; this.stageInstance = - 'stage_instance' in data ? new StageInstanceInvite(this.client, data.stage_instance, this.guild) : null; + 'stage_instance' in data ? new InviteStageInstance(this.client, data.stage_instance, this.guild) : null; } /** diff --git a/src/structures/StageInstanceInvite.js b/src/structures/InviteStageInstance.js similarity index 87% rename from src/structures/StageInstanceInvite.js rename to src/structures/InviteStageInstance.js index 366123817cab..201f134553a6 100644 --- a/src/structures/StageInstanceInvite.js +++ b/src/structures/InviteStageInstance.js @@ -3,7 +3,7 @@ const Base = require('./Base'); const Collection = require('../util/Collection'); -class StageInstanceInvite extends Base { +class InviteStageInstance extends Base { constructor(client, data, guild) { super(client); @@ -28,4 +28,4 @@ class StageInstanceInvite extends Base { } } -module.exports = StageInstanceInvite; +module.exports = InviteStageInstance; From 98843d72e90aebaa66f5b430ee0373b0d49c6d99 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Tue, 15 Jun 2021 18:17:39 +0530 Subject: [PATCH 3/8] feat(InviteStageInstance): add guild and channel getters --- src/structures/Invite.js | 4 +++- src/structures/InviteStageInstance.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 4f0052bf345d..f2f4a1e9f2df 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -115,7 +115,9 @@ class Invite extends Base { this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; this.stageInstance = - 'stage_instance' in data ? new InviteStageInstance(this.client, data.stage_instance, this.guild) : null; + 'stage_instance' in data + ? new InviteStageInstance(this.client, data.stage_instance, this.guild.id, this.channel.id) + : null; } /** diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 201f134553a6..9f61894eaeae 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -4,10 +4,12 @@ const Base = require('./Base'); const Collection = require('../util/Collection'); class InviteStageInstance extends Base { - constructor(client, data, guild) { + constructor(client, data, guildID, channelID) { super(client); - this.guild = guild; + this.guildID = guildID; + + this.channelID = channelID; this.members = new Collection(); @@ -26,6 +28,14 @@ class InviteStageInstance extends Base { this.members.set(member.id, member); } } + + get guild() { + return this.client.guilds.resolve(this.guildID); + } + + get channel() { + return this.client.channels.resolve(this.channelID); + } } module.exports = InviteStageInstance; From 4d10aab542a939c735e777404aaf7193eed3b1b2 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 16 Jun 2021 23:21:55 +0530 Subject: [PATCH 4/8] docs(InviteStageInstance): add documentation for it --- src/structures/InviteStageInstance.js | 46 +++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 9f61894eaeae..5968431d87de 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -7,20 +7,44 @@ class InviteStageInstance extends Base { constructor(client, data, guildID, channelID) { super(client); - this.guildID = guildID; - + /** + * The ID of the stage channel this invite is for + * @type {Snowflake} + */ this.channelID = channelID; + /** + * The guild ID of the stage channel + * @type {Snowflake} + */ + this.guildID = guildID; + + /** + * The members speaking in the stage channel + * @type {Collection} + */ this.members = new Collection(); this._patch(data); } _patch(data) { + /** + * The topic of the stage instance + * @type {string} + */ this.topic = data.topic; + /** + * The number of users in the stage channel + * @type {number} + */ this.participantCount = data.participant_count; + /** + * The number of users speaking in the stage channel + * @type {number} + */ this.speakerCount = data.speaker_count; for (const rawMember of data.members) { @@ -29,13 +53,23 @@ class InviteStageInstance extends Base { } } - get guild() { - return this.client.guilds.resolve(this.guildID); - } - + /** + * The stage channel this invite is for + * @type {?StageChannel} + * @readonly + */ get channel() { return this.client.channels.resolve(this.channelID); } + + /** + * The guild of the stage channel this invite is for + * @type {?Guild} + * @readonly + */ + get guild() { + return this.client.guilds.resolve(this.guildID); + } } module.exports = InviteStageInstance; From 76b04f9397358303a0fe3635b3e56e5f12285667 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 16 Jun 2021 23:45:18 +0530 Subject: [PATCH 5/8] types: add typings for InviteStageInstance --- src/structures/Invite.js | 6 +++++- src/structures/InviteStageInstance.js | 2 +- typings/index.d.ts | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index f2f4a1e9f2df..c123e527a80e 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -114,9 +114,13 @@ class Invite extends Base { this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; + /** + * The stage instance data if there is a public {@link StageInstance} in the stage channel this invite is for + * @type {?InviteStageInstance} + */ this.stageInstance = 'stage_instance' in data - ? new InviteStageInstance(this.client, data.stage_instance, this.guild.id, this.channel.id) + ? new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id) : null; } diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 5968431d87de..411d9c94eb2c 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -4,7 +4,7 @@ const Base = require('./Base'); const Collection = require('../util/Collection'); class InviteStageInstance extends Base { - constructor(client, data, guildID, channelID) { + constructor(client, data, channelID, guildID) { super(client); /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 5aa6b15d434e..ae713c83f686 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1144,6 +1144,19 @@ declare module 'discord.js' { public toJSON(): unknown; public toString(): string; public static INVITES_PATTERN: RegExp; + public stageInstance: InviteStageInstance | null; + } + + export class InviteStageInstance extends Base { + constructor(client: Client, data: unknown, channelID: Snowflake, guildID: Snowflake); + public channelID: Snowflake; + public guildID: Snowflake; + public members: Collection; + public topic: string; + public participantCount: number; + public speakerCount: number; + public readonly channel: StageChannel | null; + public readonly guild: Guild | null; } export class Message extends Base { From b72089246f8cf7dec35e8d5efd37131faf2a3d6a Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Thu, 17 Jun 2021 00:05:27 +0530 Subject: [PATCH 6/8] fix(InviteStageInstance): clear members collection before patching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- src/structures/InviteStageInstance.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 411d9c94eb2c..d3a48038e5d8 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -47,6 +47,7 @@ class InviteStageInstance extends Base { */ this.speakerCount = data.speaker_count; + this.members.clear(); for (const rawMember of data.members) { const member = this.guild.members.add(rawMember); this.members.set(member.id, member); From 8d81a31f00485bcd7789ad2c19d6a8c305b1ac2a Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Thu, 17 Jun 2021 00:52:52 +0530 Subject: [PATCH 7/8] docs(InviteStageInstance): document the class --- src/structures/InviteStageInstance.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 411d9c94eb2c..c14d47a7bf6a 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -3,6 +3,10 @@ const Base = require('./Base'); const Collection = require('../util/Collection'); +/** + * Represents the data about a public {@link StageInstance} in an {@link Invite} + * @extends {Base} + */ class InviteStageInstance extends Base { constructor(client, data, channelID, guildID) { super(client); From 6eb60217c2176388b0fef025f88540bf84b21a25 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Thu, 17 Jun 2021 01:05:00 +0530 Subject: [PATCH 8/8] docs(InviteStageInstance): add period at the end of class description Co-authored-by: SpaceEEC --- src/structures/InviteStageInstance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js index 67700231e565..c5874495e69d 100644 --- a/src/structures/InviteStageInstance.js +++ b/src/structures/InviteStageInstance.js @@ -4,7 +4,7 @@ const Base = require('./Base'); const Collection = require('../util/Collection'); /** - * Represents the data about a public {@link StageInstance} in an {@link Invite} + * Represents the data about a public {@link StageInstance} in an {@link Invite}. * @extends {Base} */ class InviteStageInstance extends Base {