Skip to content

Commit

Permalink
Support stage instance invites
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 committed Aug 17, 2021
1 parent 83bbbdf commit 5147bda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare namespace Eris {
type AnyVoiceChannel = VoiceChannel | StageChannel;
type ChannelTypes = Constants["ChannelTypes"][keyof Constants["ChannelTypes"]];
type GuildTextableChannel = TextChannel | NewsChannel | AnyThreadChannel;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel>;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel | AnyThreadChannel>;
type PossiblyUncachedTextable = Textable | Uncached;
type PossiblyUncachedTextableChannel = TextableChannel | Uncached;
type TextableChannel = (GuildTextable & GuildTextableChannel) | (Textable & PrivateChannel);
Expand Down Expand Up @@ -813,6 +813,12 @@ declare namespace Eris {
recipients?: { username: string }[];
type: Exclude<ChannelTypes, 1>;
}
interface InviteStageInstance {
members: Member[];
participantCount: number;
speakerCount: number;
topic: string;
}

// Member/User
interface FetchMembersOptions {
Expand Down Expand Up @@ -2320,6 +2326,7 @@ declare namespace Eris {
maxUses: CT extends "withMetadata" ? number : null;
memberCount: CT extends "withMetadata" | "withoutCount" ? null : number;
presenceCount: CT extends "withMetadata" | "withoutCount" ? null : number;
stageInstance: CH extends StageChannel ? InviteStageInstance : null;
temporary: CT extends "withMetadata" ? boolean : null;
uses: CT extends "withMetadata" ? number : null;
constructor(data: BaseData, client: Client);
Expand Down
17 changes: 16 additions & 1 deletion lib/structures/Invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Guild = require("./Guild");

/**
* Represents an invite. Some properties are only available when fetching invites from channels, which requires the Manage Channel permission.
* @prop {TextChannel | NewsChannel | VoiceChannel | GroupChannel | Object} channel Info on the invite channel
* @prop {TextChannel | NewsChannel | VoiceChannel | GroupChannel | StageChannel | Object} channel Info on the invite channel
* @prop {String} channel.id The ID of the invite's channel
* @prop {String?} channel.name The name of the invite's channel
* @prop {Number} channel.type The type of the invite's channel
Expand All @@ -18,6 +18,7 @@ const Guild = require("./Guild");
* @prop {Number?} maxUses The max number of invite uses
* @prop {Number?} memberCount The **approximate** member count for the guild
* @prop {Number?} presenceCount The **approximate** presence count for the guild
* @prop {Object?} stageInstance The active public stage instance data for the stage channel this invite is for
* @prop {Boolean?} temporary Whether the invite grants temporary membership or not
* @prop {Number?} uses The number of invite uses
*/
Expand Down Expand Up @@ -48,6 +49,20 @@ class Invite extends Base {
this._createdAt = data.created_at !== undefined ? data.created_at : null;
this.presenceCount = data.approximate_presence_count !== undefined ? data.approximate_presence_count : null;
this.memberCount = data.approximate_member_count !== undefined ? data.approximate_member_count : null;
if(data.stage_instance !== undefined) {
data.stage_instance.members = data.stage_instance.members.map((m) => {
m.id = m.user.id;
return m;
});
this.stageInstance = {
members: this.guild.members.update(data.stage_instance.members, this.guild),
participantCount: data.stage_instance.participant_count,
speakerCount: data.stage_instance.speaker_count,
topic: data.stage_instance.topic
};
} else {
this.stageInstance = null;
}
}

get createdAt() {
Expand Down

0 comments on commit 5147bda

Please sign in to comment.