feat: stage instance invite (#5856)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Shubham Parihar
2021-06-18 04:31:18 +05:30
committed by GitHub
parent a3cbcca13d
commit 2d12db000f
3 changed files with 103 additions and 0 deletions

View File

@@ -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');
@@ -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;
}
/**

View File

@@ -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
typings/index.d.ts vendored
View File

@@ -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 {