From d503294d1d9be452e1e30dbb0634496c53b03330 Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Thu, 23 Jul 2026 23:06:10 +0200 Subject: [PATCH] stage instance endpoints --- src/grom.gleam | 150 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/src/grom.gleam b/src/grom.gleam index 0dbd267..770213a 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -17450,3 +17450,153 @@ pub fn delete_guild_soundboard_sound_response( ) -> Result(Nil, RestError) { handle_no_content_response(response) } + +/// A stage instance is an ongoing event in a stage channel. +pub type StageInstance { + StageInstance( + id: Snowflake(StageInstance), + guild_id: Snowflake(Guild), + channel_id: Snowflake(Channel), + guild_channel_id: Snowflake(GuildChannel), + stage_channel_id: Snowflake(StageChannel), + voice_like_channel_id: Snowflake(VoiceLikeChannel), + topic: String, + scheduled_event_id: Option(Snowflake(ScheduledEvent)), + ) +} + +fn stage_instance_decoder() -> Decoder(StageInstance) { + use id <- decode.field("id", snowflake_decoder()) + use guild_id <- decode.field("guild_id", snowflake_decoder()) + use channel_id <- decode.field("channel_id", snowflake_decoder()) + use guild_channel_id <- decode.field("channel_id", snowflake_decoder()) + use stage_channel_id <- decode.field("channel_id", snowflake_decoder()) + use voice_like_channel_id <- decode.field("channel_id", snowflake_decoder()) + use topic <- decode.field("topic", decode.string) + use scheduled_event_id <- decode.field( + "guild_scheduled_event_id", + decode.optional(snowflake_decoder()), + ) + decode.success(StageInstance( + id:, + guild_id:, + channel_id:, + guild_channel_id:, + stage_channel_id:, + voice_like_channel_id:, + topic:, + scheduled_event_id:, + )) +} + +/// Returns the stage instance for the stage channel, if it exists. +pub fn get_stage_instance_request( + token token: Token, + for_channel_with_id channel_id: Snowflake(StageChannel), +) -> Request(String) { + new_request( + token:, + to: "/stage-instances/" <> snowflake_to_string(channel_id), + method: http.Get, + ) +} + +pub fn get_stage_channel_response( + response: Response(String), +) -> Result(StageInstance, RestError) { + handle_response(response, decode_with: stage_instance_decoder()) +} + +pub opaque type CreateStageInstance { + CreateStageInstance( + channel_id: Snowflake(StageChannel), + topic: String, + send_start_notification: Option(Bool), + scheduled_event_id: Option(Snowflake(ScheduledEvent)), + ) +} + +fn create_stage_instance_to_json(create: CreateStageInstance) { + [ + Ok(#("channel_id", snowflake_to_json(create.channel_id))), + Ok(#("topic", json.string(create.topic))), + optional_to_json( + create.send_start_notification, + "send_start_notification", + json.bool, + ), + optional_to_json( + create.scheduled_event_id, + "guild_scheduled_event_id", + snowflake_to_json, + ), + ] + |> list_to_json_object +} + +pub fn new_stage_instance( + in_channel_with_id channel_id: Snowflake(StageChannel), + topic topic: String, +) -> CreateStageInstance { + CreateStageInstance( + channel_id:, + topic:, + send_start_notification: None, + scheduled_event_id: None, + ) +} + +/// Notifies @everyone about the stage instance starting. +/// +/// Requires the `AllowMentioningEveryone` permission. +pub fn new_stage_instance_with_start_notification( + create: CreateStageInstance, +) -> CreateStageInstance { + CreateStageInstance(..create, send_start_notification: Some(True)) +} + +pub fn new_stage_instance_for_scheduled_event( + create: CreateStageInstance, + scheduled_event_with_id scheduled_event_id: Snowflake(ScheduledEvent), +) -> CreateStageInstance { + CreateStageInstance(..create, scheduled_event_id: Some(scheduled_event_id)) +} + +/// Requires the `AllowManagingChannels`, `AllowMutingMembersInVoiceChannels`, +/// and `AllowMovingMembersBetweenVoiceChannels` permissions. +pub fn new_stage_instance_request( + token token: Token, + using create: CreateStageInstance, + reason reason: Option(String), +) -> Request(String) { + let body = create |> create_stage_instance_to_json |> json.to_string + + new_request(token:, to: "/stage-instances", method: http.Post) + |> request.set_body(body) + |> request_with_reason(reason) +} + +/// Requires the `AllowManagingChannels`, `AllowMutingMembersInVoiceChannels`, +/// and `AllowMovingMembersBetweenVoiceChannels` permissions. +pub fn new_stage_instance_response( + response: Response(String), +) -> Result(StageInstance, RestError) { + handle_response(response, decode_with: stage_instance_decoder()) +} + +pub fn delete_stage_instance_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(StageChannel), +) -> Request(String) { + new_request( + token:, + to: "/stage-instances/" <> snowflake_to_string(channel_id), + method: http.Delete, + ) +} + +pub fn delete_stage_instance_response( + response: Response(String), +) -> Result(Nil, RestError) { + handle_no_content_response(response) +} -- 2.51.2