Skip to content

Commit

Permalink
feat: stage instance invite (#5856)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
  • Loading branch information
3 people committed Jun 17, 2021
1 parent a3cbcca commit 2d12db0
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
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}.
* @extends {Base}
*/
class InviteStageInstance extends Base {
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) {
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 @@ -1192,6 +1192,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

0 comments on commit 2d12db0

Please sign in to comment.