diff --git a/index.d.ts b/index.d.ts index 96a5b3888..8e527fb37 100644 --- a/index.d.ts +++ b/index.d.ts @@ -479,6 +479,9 @@ declare namespace Eris { permissions: Permission; position: number; } + interface OldStageInstance { + topic: string; + } interface OldThread { name: string; rateLimitPerUser: number; @@ -553,6 +556,8 @@ declare namespace Eris { event: "relationshipUpdate", listener: (relationship: Relationship, oldRelationship: { type: number }) => void ): T; + (event: "stageInstanceCreate" | "stageInstanceDelete", listener: (stageInstance: StageInstance) => void): T; + (event: "stageInstanceUpdate", listener: (stageInstance: StageInstance, oldStageInstance: OldStageInstance | null) => void): T; (event: "threadCreate" | "threadDelete", listener: (channel: AnyThreadChannel) => void): T; (event: "threadListSync", listener: (guild: Guild, deletedThreads: (AnyThreadChannel | Uncached)[], activeThreads: AnyThreadChannel[], joinedThreadsMember: ThreadMember[]) => void): T; (event: "threadMembersUpdate", listener: (channel: AnyThreadChannel, removedMembers: (ThreadMember | Uncached)[], addedMembers: ThreadMember[]) => void): T; @@ -2080,6 +2085,7 @@ declare namespace Eris { shard: Shard; splash: string | null; splashURL: string | null; + stageInstances: Collection; systemChannelFlags: number; systemChannelID: string | null; threads: Collection; diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 73ad30097..46df5579c 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -15,6 +15,7 @@ const User = require("../structures/User"); const Invite = require("../structures/Invite"); const Constants = require("../Constants"); const ThreadChannel = require("../structures/ThreadChannel"); +const StageInstance = require("../structures/StageInstance"); const WebSocket = typeof window !== "undefined" ? require("../util/BrowserWebSocket") : require("ws"); @@ -2214,6 +2215,57 @@ class Shard extends EventEmitter { this.emit("threadMembersUpdate", channel, removedMembers, addedMembers); break; } + case "STAGE_INSTANCE_CREATE": { + const guild = this.client.guilds.get(packet.d.guild_id); + if(!guild) { + this.emit("debug", `Missing guild ${packet.d.guild_id} in STAGE_INSTANCE_CREATE`); + break; + } + /** + * Fired when a stage instance is created + * @event Client#stageInstanceCreate + * @prop {StageInstance} stageInstance The stage instance + */ + this.emit("stageInstanceCreate", guild.stageInstances.add(packet.d)); + break; + } + case "STAGE_INSTANCE_UPDATE": { + const guild = this.client.guilds.get(packet.d.guild_id); + if(!guild) { + this.emit("stageInstanceUpdate", packet.d, null); + break; + } + const stageInstance = guild.stageInstances.get(packet.d.id); + let oldStageInstance = null; + if(stageInstance) { + oldStageInstance = { + topic: stageInstance.topic + }; + } + /** + * Fired when a stage instance is updated + * @event Client#stageInstanceUpdate + * @prop {StageInstance} stageInstance The stage instance + * @prop {Object?} oldStageInstance The old stage instance. If the stage instance was cached, this will be an object with the properties below. Otherwise, it will be null + * @prop {String} oldStageInstance.topic The stage instance topic + */ + this.emit("stageInstanceUpdate", guild.stageInstances.update(packet.d, this.client), oldStageInstance); + break; + } + case "STAGE_INSTANCE_DELETE": { + const guild = this.client.guilds.get(packet.d.guild_id); + if(!guild) { + this.emit("stageInstanceDelete", new StageInstance(packet.d, this.client)); + break; + } + /** + * Fired when a stage instance is deleted + * @event Client#stageInstanceDelete + * @prop {StageInstance} stageInstance The deleted stage instance + */ + this.emit("stageInstanceDelete", guild.stageInstances.remove(packet.d) || new StageInstance(packet.d, this.client)); + break; + } case "MESSAGE_ACK": // Ignore these case "GUILD_INTEGRATIONS_UPDATE": case "USER_SETTINGS_UPDATE": diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index bdeb56bc2..ebfb92ff9 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -10,6 +10,7 @@ const Role = require("./Role"); const VoiceState = require("./VoiceState"); const Permission = require("./Permission"); const {Permissions} = require("../Constants"); +const StageInstance = require("./StageInstance"); const ThreadChannel = require("./ThreadChannel"); /** @@ -61,6 +62,7 @@ const ThreadChannel = require("./ThreadChannel"); * @prop {Shard} shard The Shard that owns the guild * @prop {String?} splash The hash of the guild splash image, or null if no splash (VIP only) * @prop {String?} splashURL The URL of the guild's splash image +* @prop {Collection} stageInstances Collection of stage instances in the guild * @prop {Number} systemChannelFlags The flags for the system channel * @prop {String?} systemChannelID The ID of the default channel for system messages (built-in join messages and boost messages) * @prop {Collection} threads Collection of threads that the current user has permission to view @@ -85,6 +87,7 @@ class Guild extends Base { this.channels = new Collection(GuildChannel); this.threads = new Collection(ThreadChannel); this.members = new Collection(Member); + this.stageInstances = new Collection(StageInstance); this.memberCount = data.member_count; this.roles = new Collection(Role); this.applicationID = data.application_id; @@ -152,6 +155,13 @@ class Guild extends Base { member.id = member.user.id; this.members.add(member, this); } + } + + if(data.stage_instances) { + for(const stageInstance of data.stage_instances) { + stageInstance.guild_id = this.id; + this.stageInstances.add(stageInstance, client); + } } if(data.presences) {