Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stage instance invite #5856

Merged
merged 9 commits into from Jun 17, 2021
10 changes: 10 additions & 0 deletions src/structures/Invite.js
Expand Up @@ -2,6 +2,7 @@

const Base = require('./Base');
const IntegrationApplication = require('./IntegrationApplication');
const InviteStageInstance = require('./InviteStageInstance');
const { Error } = require('../errors');
const { Endpoints } = require('../util/Constants');
const Permissions = require('../util/Permissions');
Expand Down Expand Up @@ -112,6 +113,15 @@ 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;

/**
* 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.channel.id, this.guild.id)
: null;
}

/**
Expand Down
80 changes: 80 additions & 0 deletions src/structures/InviteStageInstance.js
@@ -0,0 +1,80 @@
'use strict';

const Base = require('./Base');
const Collection = require('../util/Collection');

/**
* Represents the data about a public {@link StageInstance} in an {@link Invite}
iShibi marked this conversation as resolved.
Show resolved Hide resolved
* @extends {Base}
*/
class InviteStageInstance extends Base {
SpaceEEC marked this conversation as resolved.
Show resolved Hide resolved
constructor(client, data, channelID, guildID) {
super(client);

/**
* 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<Snowflake, GuildMember>}
*/
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;

this.members.clear();
for (const rawMember of data.members) {
iShibi marked this conversation as resolved.
Show resolved Hide resolved
const member = this.guild.members.add(rawMember);
this.members.set(member.id, member);
}
}

/**
* 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;
13 changes: 13 additions & 0 deletions typings/index.d.ts
Expand Up @@ -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<Snowflake, GuildMember>;
public topic: string;
public participantCount: number;
public speakerCount: number;
public readonly channel: StageChannel | null;
public readonly guild: Guild | null;
}

export class Message extends Base {
Expand Down