Skip to content

Commit

Permalink
Expose stage instance
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 committed Aug 17, 2021
1 parent c591b45 commit 1f20e38
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 0 deletions.
2 changes: 2 additions & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const {
SequentialBucket,
Shard,
SharedStream,
StageChannel,
StageInstance,
StoreChannel,
TextChannel,
ThreadChannel,
Expand Down
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ declare namespace Eris {
}

// Voice
interface EditStageInstanceOptions {
topic: string;
}
interface UncachedMemberVoiceState {
id: string;
voiceState: OldVoiceState;
Expand Down Expand Up @@ -1686,6 +1689,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>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
Expand All @@ -1700,6 +1704,7 @@ declare namespace Eris {
deleteRole(guildID: string, roleID: string, reason?: string): Promise<void>;
deleteSelfConnection(platform: string, id: string): Promise<void>;
deleteSelfPremiumSubscription(): Promise<void>;
deleteStageInstance(channelID: string): Promise<void>;
deleteUserNote(userID: string): Promise<void>;
deleteWebhook(webhookID: string, token?: string, reason?: string): Promise<void>;
deleteWebhookMessage(webhookID: string, token: string, messageID: string): Promise<void>;
Expand Down Expand Up @@ -1746,6 +1751,7 @@ declare namespace Eris {
data: { friendSync: boolean; visibility: number }
): Promise<Connection>;
editSelfSettings(data: UserSettings): Promise<UserSettings>;
editStageInstance(channelID: string, options: EditStageInstanceOptions): 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 @@ -1861,6 +1867,7 @@ declare namespace Eris {
status: number;
}[]>;
getSelfSettings(): Promise<UserSettings>;
getStageInstance(channelID: string): Promise<StageInstance>;
getThreadMembers(channelID: string): Promise<ThreadMember[]>;
getUserProfile(userID: string): Promise<UserProfile>;
getVoiceRegions(guildID?: string): Promise<VoiceRegion[]>;
Expand Down Expand Up @@ -2630,6 +2637,20 @@ declare namespace Eris {
export class StageChannel extends VoiceChannel {
topic?: string;
type: 13;
createInstance(topic: string): Promise<StageInstance>;
deleteInstance(): Promise<void>;
editInstance(options: EditStageInstanceOptions): Promise<StageInstance>;
getInstance(): Promise<StageInstance>;
}

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

export class StoreChannel extends GuildChannel {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Eris.Role = require("./lib/structures/Role");
Eris.SequentialBucket = require("./lib/util/SequentialBucket");
Eris.Shard = require("./lib/gateway/Shard");
Eris.SharedStream = require("./lib/voice/SharedStream");
Eris.StageChannel = require("./lib/structures/StageChannel");
Eris.StageInstance = require("./lib/structures/StageInstance");
Eris.StoreChannel = require("./lib/structures/StoreChannel");
Eris.TextChannel = require("./lib/structures/TextChannel");
Eris.ThreadChannel = require("./lib/structures/ThreadChannel");
Expand Down
43 changes: 43 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ThreadMember = require("./structures/ThreadMember");
const UnavailableGuild = require("./structures/UnavailableGuild");
const User = require("./structures/User");
const VoiceConnectionManager = require("./voice/VoiceConnectionManager");
const StageInstance = require("./structures/StageInstance");

let EventEmitter;
try {
Expand Down Expand Up @@ -704,6 +705,19 @@ 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
* @returns {Promise<StageInstance>}
*/
createStageInstance(channelID, topic) {
return this.requestHandler.request("POST", Endpoints.STAGE_INSTANCES, true, {
channel_id: channelID,
topic: topic
}).then((instance) => new StageInstance(instance, this));
}

/**
* Crosspost (publish) a message to subscribed channels
* @arg {String} channelID The ID of the NewsChannel
Expand Down Expand Up @@ -881,6 +895,15 @@ class Client extends EventEmitter {
return this.requestHandler.request("DELETE", Endpoints.USER_BILLING_PREMIUM_SUBSCRIPTION("@me"), true);
}

/**
* Delete a stage instance
* @arg {String} channelID The stage channel associated with the instance
* @returns {Promise}
*/
deleteStageInstance(channelID) {
return this.requestHandler.request("DELETE", Endpoints.STAGE_INSTANCE(channelID), true);
}

/**
* [USER ACCOUNT] Delete the current user's note for another user
* @returns {Promise}
Expand Down Expand Up @@ -1454,6 +1477,17 @@ 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
* @returns {Promise<StageInstance>}
*/
editStageInstance(channelID, options) {
return this.requestHandler.request("PATCH", Endpoints.STAGE_INSTANCE(channelID), true, options).then((instance) => new StageInstance(instance, this));
}

/**
* Update the bot's status on all guilds
* @arg {String} [status] Sets the bot's status, either "online", "idle", "dnd", or "invisible"
Expand Down Expand Up @@ -2328,6 +2362,15 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.USER_SETTINGS("@me"), true);
}

/**
* Get the stage instance associated with a stage channel
* @arg {String} channelID The stage channel ID
* @returns {Promise<StageInstance>}
*/
getStageInstance(channelID) {
return this.requestHandler.request("GET", Endpoints.STAGE_INSTANCE(channelID), true).then((instance) => new StageInstance(instance, this));
}

/**
* Get a list of members that are part of a thread channel
* @arg {String} channelID The ID of the thread channel
Expand Down
2 changes: 2 additions & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ module.exports.GUILD_VOICE_STATE = (guildID, user)
module.exports.GUILDS = "/guilds";
module.exports.INVITE = (inviteID) => `/invites/${inviteID}`;
module.exports.OAUTH2_APPLICATION = (appID) => `/oauth2/applications/${appID}`;
module.exports.STAGE_INSTANCE = (channelID) => `/stage-instances/${channelID}`;
module.exports.STAGE_INSTANCES = "/stage-instances";
module.exports.USER = (userID) => `/users/${userID}`;
module.exports.USER_BILLING = (userID) => `/users/${userID}/billing`;
module.exports.USER_BILLING_PAYMENTS = (userID) => `/users/${userID}/billing/payments`;
Expand Down
35 changes: 35 additions & 0 deletions lib/structures/StageChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@ class StageChannel extends VoiceChannel {
}
}

/**
* Create a stage instance
* @arg {String} topic The topic for the stage instance
* @returns {Promise<StageInstance>}
*/
createInstance(topic) {
return this.client.createStageInstance.call(this.client, this.id, topic);
}

/**
* Delete the stage instance for this channel
* @returns {Promise}
*/
deleteInstance() {
return this.client.deleteStageInstance.call(this.client, this.id);
}

/**
* Update the stage instance for this channel
* @arg {Object} options The properties to edit
* @arg {String} options.topic The stage instance topic
* @returns {Promise<StageInstance>}
*/
editInstance(options) {
return this.client.editStageInstance.call(this.client, this.id, options);
}

/**
* Get the stage instance for this channel
* @returns {Promise<StageInstance>}
*/
getInstance() {
return this.client.getStageInstance.call(this.client, this.id);
}

toJSON(props = []) {
return super.toJSON([
"topic",
Expand Down
40 changes: 40 additions & 0 deletions lib/structures/StageInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

const Base = require("./Base");

/**
* Represents a stage instance
* @prop {StageChannel} channel The associated stage channel
* @prop {Guild} guild The guild of the associated stage channel
* @prop {String} id The ID of the stage instance
* @prop {String} topic The stage instance topic
*/
class StageInstance extends Base {
constructor(data, client) {
super(data.id);
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;
}

/**
* Delete this stage instance
* @returns {Promise}
*/
delete() {
return this.client.deleteStageInstance.call(this.client, this.channel.id);
}

/**
* Update this stage instance
* @arg {Object} options The properties to edit
* @arg {String} options.topic The stage instance topic
* @returns {Promise<StageInstance>}
*/
edit(options) {
return this.client.editStageInstance.call(this.client, options);
}
}

module.exports = StageInstance;

0 comments on commit 1f20e38

Please sign in to comment.