diff --git a/src/helpers/channels/createStageInstance.ts b/src/helpers/channels/createStageInstance.ts index d32522c5e..abbedc881 100644 --- a/src/helpers/channels/createStageInstance.ts +++ b/src/helpers/channels/createStageInstance.ts @@ -8,9 +8,16 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH); } - return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, { - channel_id: channelId, + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, { + channel_id: channelId.toString(), topic, - privacy_level: privacyLevel, + privacy_level: privacyLevel || PrivacyLevel.GuildOnly, }); + + return { + id: bot.transformers.snowflake(result.id), + guildId: bot.transformers.snowflake(result.guild_id), + channelId: bot.transformers.snowflake(result.channel_id), + topic: result.topic, + }; } diff --git a/src/helpers/channels/updateStageInstance.ts b/src/helpers/channels/updateStageInstance.ts index 3232baa51..ecd330794 100644 --- a/src/helpers/channels/updateStageInstance.ts +++ b/src/helpers/channels/updateStageInstance.ts @@ -1,15 +1,11 @@ import type { StageInstance } from "../../types/channels/stageInstance.ts"; import type { Bot } from "../../bot.ts"; -import { ChannelTypes } from "../../types/channels/channelTypes.ts"; +import { AtLeastOne } from "../../types/util.ts"; /** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */ -export async function updateStageInstance( - bot: Bot, - channelId: bigint, - data: Partial> = {} -) { +export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtLeastOne>) { if ( - data?.topic && + data.topic && !bot.utils.validateLength(data.topic, { min: 1, max: 120, @@ -18,8 +14,19 @@ export async function updateStageInstance( throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH); } - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), { - topic: data.topic, - privacy_level: data.privacyLevel, - }); + const result = await bot.rest.runMethod( + bot.rest, + "patch", + bot.constants.endpoints.STAGE_INSTANCE(channelId), + { + topic: data.topic, + } + ); + + return { + id: bot.transformers.snowflake(result.id), + guildId: bot.transformers.snowflake(result.guild_id), + channelId: bot.transformers.snowflake(result.channel_id), + topic: result.topic, + }; } diff --git a/src/types/channels/privacyLevel.ts b/src/types/channels/privacyLevel.ts index b78e77b39..932ff7c42 100644 --- a/src/types/channels/privacyLevel.ts +++ b/src/types/channels/privacyLevel.ts @@ -1,7 +1,7 @@ // TODO: add resource link export enum PrivacyLevel { /** The Stage instance is visible publicly, such as on Stage discovery */ - Public = 1, + // Public = 1, /** The Stage instance is visible to only guild members */ - GuildOnly, + GuildOnly = 2, } diff --git a/src/types/channels/stageInstance.ts b/src/types/channels/stageInstance.ts index a4e64aee8..690a27756 100644 --- a/src/types/channels/stageInstance.ts +++ b/src/types/channels/stageInstance.ts @@ -1,3 +1,5 @@ +import { PrivacyLevel } from "./privacyLevel.ts"; + /** https://discord.com/developers/docs/resources/stage-instance#auto-closing-stage-instance-structure */ export interface StageInstance { /** The id of this Stage instance */ @@ -9,7 +11,7 @@ export interface StageInstance { /** The topic of the Stage instance (1-120 characters) */ topic: string; /** The privacy level of the Stage instance */ - privacyLevel: number; + privacyLevel: PrivacyLevel; /** Whether or not Stage discovery is disabled */ discoverableDisabled: boolean; } diff --git a/tests/channels/stageInstances.ts b/tests/channels/stageInstances.ts new file mode 100644 index 000000000..f4e7de799 --- /dev/null +++ b/tests/channels/stageInstances.ts @@ -0,0 +1,24 @@ +import { ChannelTypes } from "../../src/types/channels/channelTypes.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts"; +import { assertNotEquals, assertExists } from "../deps.ts"; +import { bot } from "../mod.ts"; + +Deno.test("[stage] Create a stage instance", async (t) => { + const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { + name: "instance", + type: ChannelTypes.GuildStageVoice, + }); + const instance = await bot.helpers.createStageInstance(stage.id, "test it"); + assertExists(instance); + + await t.step("[stage] Edit a stage instance", async () => { + const edited = await bot.helpers.updateStageInstance(stage.id, { + topic: "edited" + }) + assertNotEquals(edited.topic, stage.topic); + }) + + await t.step("[stage] Delete a stage instance", async () => { + await bot.helpers.deleteStageInstance(stage.id); + }); +}); diff --git a/tests/mod.ts b/tests/mod.ts index 02471f214..73cd69ac0 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -565,6 +565,7 @@ Deno.test({ }); import "./channels/connectToVoice.ts"; +import "./channels/stageInstances.ts" import "./emoji/createEmoji.ts"; import "./emoji/deleteEmojiWithReason.ts"; import "./emoji/deleteEmojiWithoutReason.ts";