From 985def3f255b37891642172a3c83897c1d2749f6 Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Fri, 19 May 2023 21:18:33 +0200 Subject: [PATCH] feat(api): add stage instances (#9578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(core): add stage instances * chore: use one import * Apply suggestions from code review Co-authored-by: Aura Román * chore: requested changes Co-authored-by: David Malchin Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: David Malchin Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --------- Co-authored-by: Aura Román Co-authored-by: David Malchin Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/src/api/index.ts | 5 ++ packages/core/src/api/stageInstances.ts | 76 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 packages/core/src/api/stageInstances.ts diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index 924f00d0bc81..01812a65ce72 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -6,6 +6,7 @@ import { InteractionsAPI } from './interactions.js'; import { InvitesAPI } from './invite.js'; import { OAuth2API } from './oauth2.js'; import { RoleConnectionsAPI } from './roleConnections.js'; +import { StageInstancesAPI } from './stageInstances.js'; import { StickersAPI } from './sticker.js'; import { ThreadsAPI } from './thread.js'; import { UsersAPI } from './user.js'; @@ -19,6 +20,7 @@ export * from './interactions.js'; export * from './invite.js'; export * from './oauth2.js'; export * from './roleConnections.js'; +export * from './stageInstances.js'; export * from './sticker.js'; export * from './thread.js'; export * from './user.js'; @@ -40,6 +42,8 @@ export class API { public readonly roleConnections: RoleConnectionsAPI; + public readonly stageInstances: StageInstancesAPI; + public readonly stickers: StickersAPI; public readonly threads: ThreadsAPI; @@ -57,6 +61,7 @@ export class API { this.invites = new InvitesAPI(rest); this.roleConnections = new RoleConnectionsAPI(rest); this.oauth2 = new OAuth2API(rest); + this.stageInstances = new StageInstancesAPI(rest); this.stickers = new StickersAPI(rest); this.threads = new ThreadsAPI(rest); this.users = new UsersAPI(rest); diff --git a/packages/core/src/api/stageInstances.ts b/packages/core/src/api/stageInstances.ts new file mode 100644 index 000000000000..a43df7fc9f79 --- /dev/null +++ b/packages/core/src/api/stageInstances.ts @@ -0,0 +1,76 @@ +/* eslint-disable jsdoc/check-param-names */ + +import type { RequestData, REST } from '@discordjs/rest'; +import { + type Snowflake, + type RESTGetAPIStageInstanceResult, + type RESTPatchAPIStageInstanceJSONBody, + type RESTPatchAPIStageInstanceResult, + type RESTPostAPIStageInstanceJSONBody, + type RESTPostAPIStageInstanceResult, + Routes, +} from 'discord-api-types/v10'; + +export class StageInstancesAPI { + public constructor(private readonly rest: REST) {} + + /** + * Creates a new stage instance + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance} + * @param body - The data to use when creating the new stage instance + * @param options - The options for creating the new stage instance + */ + public async create( + body: RESTPostAPIStageInstanceJSONBody, + { reason, signal }: Pick = {}, + ) { + return this.rest.post(Routes.stageInstances(), { + body, + reason, + signal, + }) as Promise; + } + + /** + * Fetches a stage instance + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance} + * @param channelId - The id of the channel + * @param options - The options for fetching the stage instance + */ + public async get(channelId: Snowflake, { signal }: Pick = {}) { + return this.rest.get(Routes.stageInstance(channelId), { signal }) as Promise; + } + + /** + * Edits a stage instance + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance} + * @param channelId - The id of the channel + * @param body - The new stage instance data + * @param options - The options for editing the stage instance + */ + public async edit( + channelId: Snowflake, + body: RESTPatchAPIStageInstanceJSONBody, + { reason, signal }: Pick = {}, + ) { + return this.rest.patch(Routes.stageInstance(channelId), { + body, + reason, + signal, + }) as Promise; + } + + /** + * Deletes a stage instance + * + * @see {@link https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance} + * @param channelId - The id of the channel + * @param options - The options for deleting the stage instance + */ + public async delete(channelId: Snowflake, { reason, signal }: Pick = {}) { + await this.rest.delete(Routes.stageInstance(channelId), { reason, signal }); + } +}