From 8ea9d2087b3d8fe3d656455bb92bf169ef763c33 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:48:44 +0000 Subject: [PATCH] add stage helpers --- packages/rest/src/manager.ts | 178 +++++++++++++++++++++++++++---- packages/types/src/discordeno.ts | 12 +++ 2 files changed, 169 insertions(+), 21 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 5c3b2d611..8ae1885f1 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -1,6 +1,5 @@ /** * TODO: missing helpers - * createForumThread * createStageInstance * deleteStageInstance * editStageInstance @@ -25,6 +24,7 @@ import type { CreateGuildChannel, CreateGuildEmoji, CreateMessageOptions, + CreateStageInstance, DeleteWebhookMessageOptions, DiscordApplication, DiscordChannel, @@ -36,10 +36,12 @@ import type { DiscordGetGatewayBot, DiscordInviteMetadata, DiscordMessage, + DiscordStageInstance, DiscordStickerPack, DiscordUser, DiscordWebhook, EditChannelPermissionOverridesOptions, + EditStageInstanceOptions, ExecuteWebhook, GetMessagesOptions, GetWebhookMessageOptions, @@ -157,6 +159,14 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return `/channels/${channelId}/permissions/${overwriteId}` }, + stages: () => { + return '/stage-instances' + }, + + stage: (channelId) => { + return `/stage-instances/${channelId}` + }, + typing: (channelId) => { return `/channels/${channelId}/typing` }, @@ -526,6 +536,24 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.getChannelInvites(id) }, + stages: { + async create(options) { + return await rest.createStageInstance(options) + }, + + async delete(channelId, reason) { + return await rest.deleteStageInstance(channelId, reason) + }, + + async edit(channelId, data) { + return await rest.editStageInstance(channelId, data) + }, + + async get(channelId) { + return await rest.getStageInstance(channelId) + }, + }, + async typing(id) { return await rest.triggerTypingIndicator(id) }, @@ -645,27 +673,14 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.post(rest.routes.guilds.channels(guildId), options) }, - /** - * Creates a new thread in a forum channel, and sends a message within the created thread. - * - * @param channelId - The ID of the forum channel to create the thread within. - * @param options - The parameters for the creation of the thread. - * @returns An instance of {@link DiscordChannel} with a nested {@link Message} object. - * - * @remarks - * Requires the `CREATE_MESSAGES` permission. - * - * Fires a _Thread Create_ gateway event. - * Fires a _Message Create_ gateway event. - * - * @see {@link https://discord.com/developers/docs/resources/channel#start-thread-in-forum-channel} - * - * @experimental - */ async createForumThread(channelId, options) { return await rest.post(rest.routes.channels.forum(channelId), options) }, + async createStageInstance(options) { + return await rest.post(rest.routes.channels.stages(), options) + }, + async deleteChannel(channelId, reason) { return await rest.delete(rest.routes.channels.channel(channelId), { reason }) }, @@ -674,6 +689,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), reason ? { reason } : undefined) }, + async deleteStageInstance(channelId, reason) { + return await rest.delete(rest.routes.channels.stage(channelId), reason ? { reason } : undefined) + }, + async editChannel(channelId, options) { return await rest.patch(rest.routes.channels.channel(channelId), options) }, @@ -686,6 +705,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.patch(rest.routes.guilds.channels(guildId), channelPositions) }, + async editStageInstance(channelId, data) { + return await rest.patch(rest.routes.channels.stage(channelId), { topic: data.topic }) + }, + async followAnnouncement(sourceChannelId, targetChannelId) { return await rest.post(rest.routes.channels.follow(sourceChannelId), { webhook_channel_id: targetChannelId, @@ -708,6 +731,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.get(rest.routes.sessionInfo()) }, + async getStageInstance(channelId) { + return await rest.get(rest.routes.channels.stage(channelId)) + }, + async getUser(id) { return await rest.get(rest.routes.user(id)) }, @@ -832,9 +859,6 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }, } - rest.webhooks.messages.edit('', '', '', {}) - rest.webhooks.messages.edit.original('', '', {}) - return rest } @@ -919,6 +943,10 @@ export interface RestManager { messages: (channelId: BigString, options?: GetMessagesOptions) => string /** Route for handling a specific overwrite. */ overwrite: (channelId: BigString, overwriteId: BigString) => string + /** Route for handling non-specific stages */ + stages: () => string + /** Route for handling a specific stage */ + stage: (channelId: BigString) => string /** Route for handling typing indicators in a channel. */ typing: (channelId: BigString) => string } @@ -1145,6 +1173,61 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites} */ invites: (channelId: BigString) => Promise>> + /** Stage related helpers for a channel. */ + stages: { + /** + * Creates a stage instance associated with a stage channel. + * + * @param options - The parameters for the creation of the stage instance. + * @returns An instance of the created {@link DiscordStageInstance}. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Create_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#create-stage-instance} + */ + create: (options: CreateStageInstance) => Promise> + /** + * Deletes the stage instance associated with a stage channel, if one exists. + * + * @param channelId - The ID of the stage channel the stage instance is associated with. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Delete_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance} + */ + delete: (channelId: BigString, reason?: string) => Promise + /** + * Edits a stage instance. + * + * @param rest - The rest manager to use to make the request. + * @param channelId - The ID of the stage channel the stage instance is associated with. + * @returns An instance of the updated {@link DiscordStageInstance}. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Update_ event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance} + */ + edit: (channelId: BigString, data: EditStageInstanceOptions) => Promise> + /** + * Gets the stage instance associated with a stage channel, if one exists. + * + * @param rest - The rest manager to use to make the request. + * @param channelId - The ID of the stage channel the stage instance is associated with. + * @returns An instance of {@link DiscordStageInstance}. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance} + */ + get: (channelId: BigString) => Promise> + } /** * Triggers a typing indicator for the bot user. * @@ -1473,6 +1556,20 @@ export interface RestManager { * @experimental */ createForumThread: (channelId: BigString, options: CreateForumPostWithMessage) => Promise> + /** + * Creates a stage instance associated with a stage channel. + * + * @param options - The parameters for the creation of the stage instance. + * @returns An instance of the created {@link DiscordStageInstance}. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Create_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#create-stage-instance} + */ + createStageInstance: (options: CreateStageInstance) => Promise> /** * Deletes a channel from within a guild. * @@ -1512,6 +1609,20 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission} */ deleteChannelPermissionOverride: (channelId: BigString, overwriteId: BigString, reason?: string) => Promise + /** + * Deletes the stage instance associated with a stage channel, if one exists. + * + * @param rest - The rest manager to use to make the request. + * @param channelId - The ID of the stage channel the stage instance is associated with. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Delete_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance} + */ + deleteStageInstance: (channelId: BigString, reason?: string) => Promise /** * Edits a channel's settings. * @@ -1572,6 +1683,21 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions} */ editChannelPositions: (guildId: BigString, channelPositions: ModifyGuildChannelPositions[]) => Promise + /** + * Edits a stage instance. + * + * @param rest - The rest manager to use to make the request. + * @param channelId - The ID of the stage channel the stage instance is associated with. + * @returns An instance of the updated {@link DiscordStageInstance}. + * + * @remarks + * Requires the user to be a moderator of the stage channel. + * + * Fires a _Stage Instance Update_ event. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance} + */ + editStageInstance: (channelId: BigString, data: EditStageInstanceOptions) => Promise> /** * Follows an announcement channel, allowing messages posted within it to be cross-posted into the target channel. * @@ -1634,6 +1760,16 @@ export interface RestManager { * @param id The user's id * @returns {Camelize} */ + /** + * Gets the stage instance associated with a stage channel, if one exists. + * + * @param rest - The rest manager to use to make the request. + * @param channelId - The ID of the stage channel the stage instance is associated with. + * @returns An instance of {@link DiscordStageInstance}. + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance} + */ + getStageInstance: (channelId: BigString) => Promise> getUser: (id: BigString) => Promise> /** * Creates an emoji in a guild. diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index 879506923..c32783951 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -716,3 +716,15 @@ export interface CreateForumPostWithMessage extends WithReason { /** The components you would like to have sent in this message */ components?: MessageComponents } + +export interface CreateStageInstance extends WithReason { + channelId: BigString + topic: string + /** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */ + sendStartNotification?: boolean +} + +export interface EditStageInstanceOptions extends WithReason { + /** The topic of the Stage instance (1-120 characters) */ + topic: string +}