Skip to content

Commit

Permalink
Stage discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 committed Aug 17, 2021
1 parent 239f48d commit b6f93de
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
21 changes: 14 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ declare namespace Eris {

// Voice
type ConverterCommand = "./ffmpeg" | "./avconv" | "ffmpeg" | "avconv";
type StageInstancePrivacyLevel = 1 | 2;

// Webhook
type MessageWebhookContent = Pick<WebhookPayload, "content" | "embeds" | "file" | "allowedMentions">;
Expand Down Expand Up @@ -480,6 +481,8 @@ declare namespace Eris {
position: number;
}
interface OldStageInstance {
discoverableDisabled: boolean;
privacyLevel: StageInstancePrivacyLevel;
topic: string;
}
interface OldThread {
Expand Down Expand Up @@ -1040,8 +1043,9 @@ declare namespace Eris {
}

// Voice
interface EditStageInstanceOptions {
topic: string;
interface StageInstanceOptions {
privacyLevel?: StageInstancePrivacyLevel;
topic?: string;
}
interface UncachedMemberVoiceState {
id: string;
Expand Down Expand Up @@ -1699,7 +1703,7 @@ declare namespace Eris {
createPrivateThread(channelID: string, options: CreateThreadOptions): Promise<PrivateThreadChannel>;
createPublicThread(channelID: string, options: CreateThreadOptions): Promise<NewsThreadChannel | PublicThreadChannel>;
createRole(guildID: string, options?: RoleOptions | Role, reason?: string): Promise<Role>;
createStageInstance(channelID: string, topic: string): Promise<StageInstance>;
createStageInstance(channelID: string, options: StageInstanceOptions): Promise<StageInstance>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
Expand Down Expand Up @@ -1761,7 +1765,7 @@ declare namespace Eris {
data: { friendSync: boolean; visibility: number }
): Promise<Connection>;
editSelfSettings(data: UserSettings): Promise<UserSettings>;
editStageInstance(channelID: string, options: EditStageInstanceOptions): Promise<StageInstance>;
editStageInstance(channelID: string, options: StageInstanceOptions): Promise<StageInstance>;
editStatus(status: Status, activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editStatus(activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editUserNote(userID: string, note: string): Promise<void>;
Expand Down Expand Up @@ -2649,20 +2653,23 @@ declare namespace Eris {
export class StageChannel extends VoiceChannel {
topic?: string;
type: 13;
createInstance(topic: string): Promise<StageInstance>;
createInstance(options: StageInstanceOptions): Promise<StageInstance>;
deleteInstance(): Promise<void>;
editInstance(options: EditStageInstanceOptions): Promise<StageInstance>;
editInstance(options: StageInstanceOptions): Promise<StageInstance>;
getInstance(): Promise<StageInstance>;
}

export class StageInstance extends Base {
client: Client;
channel: StageChannel | Uncached;
discoverableDisabled: boolean;
guild: Guild | Uncached;
privacyLevel: StageInstancePrivacyLevel;
topic: string;
constructor(data: BaseData, client: Client);
update(data: BaseData): void;
delete(): Promise<void>;
edit(options: EditStageInstanceOptions): Promise<StageInstance>;
edit(options: StageInstanceOptions): Promise<StageInstance>;
}

export class StoreChannel extends GuildChannel {
Expand Down
12 changes: 8 additions & 4 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,16 @@ class Client extends EventEmitter {
/**
* Create a stage instance
* @arg {String} channelID The ID of the stage channel to create the instance in
* @arg {String} topic The topic for the stage instance
* @arg {Object} options The stage instance options
* @arg {Number} [options.privacyLevel] The privacy level of the stage instance. 1 is public, 2 is guild only
* @arg {String} options.topic The stage instance topic
* @returns {Promise<StageInstance>}
*/
createStageInstance(channelID, topic) {
createStageInstance(channelID, options) {
return this.requestHandler.request("POST", Endpoints.STAGE_INSTANCES, true, {
channel_id: channelID,
topic: topic
privacy_level: options.privacyLevel,
topic: options.topic
}).then((instance) => new StageInstance(instance, this));
}

Expand Down Expand Up @@ -1481,7 +1484,8 @@ class Client extends EventEmitter {
* Update a stage instance
* @arg {String} channelID The ID of the stage channel associated with the instance
* @arg {Object} options The properties to edit
* @arg {String} options.topic The stage instance topic
* @arg {Number} [options.privacyLevel] The privacy level of the stage instance. 1 is public, 2 is guild only
* @arg {String} [options.topic] The stage instance topic
* @returns {Promise<StageInstance>}
*/
editStageInstance(channelID, options) {
Expand Down
4 changes: 4 additions & 0 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,8 @@ class Shard extends EventEmitter {
let oldStageInstance = null;
if(stageInstance) {
oldStageInstance = {
discoverableDisabled: stageInstance.discoverableDisabled,
privacyLevel: stageInstance.privacyLevel,
topic: stageInstance.topic
};
}
Expand All @@ -2247,6 +2249,8 @@ class Shard extends EventEmitter {
* @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 {Boolean} oldStageInstance.discoverableDisabled Whether or not stage discovery was disabled
* @prop {Number} oldStageInstance.privacyLevel The privacy level of the stage instance. 1 is public, 2 is guild only
* @prop {String} oldStageInstance.topic The stage instance topic
*/
this.emit("stageInstanceUpdate", guild.stageInstances.update(packet.d, this.client), oldStageInstance);
Expand Down
11 changes: 7 additions & 4 deletions lib/structures/StageChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class StageChannel extends VoiceChannel {

/**
* Create a stage instance
* @arg {String} topic The topic for the stage instance
* @arg {Object} options The stage instance options
* @arg {Number} [options.privacyLevel] The privacy level of the stage instance. 1 is public, 2 is guild only
* @arg {String} options.topic The stage instance topic
* @returns {Promise<StageInstance>}
*/
createInstance(topic) {
return this.client.createStageInstance.call(this.client, this.id, topic);
createInstance(options) {
return this.client.createStageInstance.call(this.client, this.id, options);
}

/**
Expand All @@ -35,7 +37,8 @@ class StageChannel extends VoiceChannel {
/**
* Update the stage instance for this channel
* @arg {Object} options The properties to edit
* @arg {String} options.topic The stage instance topic
* @arg {Number} [options.privacyLevel] The privacy level of the stage instance. 1 is public, 2 is guild only
* @arg {String} [options.topic] The stage instance topic
* @returns {Promise<StageInstance>}
*/
editInstance(options) {
Expand Down
21 changes: 18 additions & 3 deletions lib/structures/StageInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const Base = require("./Base");
/**
* Represents a stage instance
* @prop {StageChannel} channel The associated stage channel
* @prop {Boolean} discoverableDisabled Whether or not stage discovery is disabled
* @prop {Guild} guild The guild of the associated stage channel
* @prop {String} id The ID of the stage instance
* @prop {Number} privacyLevel The privacy level of the stage instance. 1 is public, 2 is guild only
* @prop {String} topic The stage instance topic
*/
class StageInstance extends Base {
Expand All @@ -15,7 +17,19 @@ class StageInstance extends Base {
this.client = client;
this.channel = client.getChannel(data.channel_id) || {id: data.channel_id};
this.guild = client.guilds.get(data.guild_id) || {id: data.guild_id};
this.topic = data.topic;
this.update(data);
}

update(data) {
if(data.discoverable_disabled !== undefined) {
this.discoverableDisabled = data.discoverable_disabled;
}
if(data.privacy_level !== undefined) {
this.privacyLevel = data.privacy_level;
}
if(data.topic !== undefined) {
this.topic = data.topic;
}
}

/**
Expand All @@ -29,11 +43,12 @@ class StageInstance extends Base {
/**
* Update this stage instance
* @arg {Object} options The properties to edit
* @arg {String} options.topic The stage instance topic
* @arg {Number} [options.privacyLevel] The privacy level of the stage instance. 1 is public, 2 is guild only
* @arg {String} [options.topic] The stage instance topic
* @returns {Promise<StageInstance>}
*/
edit(options) {
return this.client.editStageInstance.call(this.client, options);
return this.client.editStageInstance.call(this.client, this.channel.id, options);
}
}

Expand Down

0 comments on commit b6f93de

Please sign in to comment.