diff --git a/src/grom.gleam b/src/grom.gleam index 770213a..1d29e9c 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -9297,7 +9297,8 @@ fn voice_region_decoder() -> Decoder(VoiceRegion) { )) } -/// Unlike the similar [`get_voice_regions`](#get_voice_regions), this returns VIP regions if the guild is VIP-enabled. +/// Unlike the similar [`get_voice_regions_request`](#get_voice_regions_request), +/// this returns VIP regions if the guild is VIP-enabled. pub fn get_guild_voice_regions_request( token token: Token, for_guild_with_id guild_id: Snowflake(Guild), @@ -17600,3 +17601,128 @@ pub fn delete_stage_instance_response( ) -> Result(Nil, RestError) { handle_no_content_response(response) } + +pub type VoiceState { + VoiceState( + guild_id: Snowflake(Guild), + /// Is `None` when the user is not connected to any channel. + channel_id: Option(Snowflake(Channel)), + /// Is `None` when the user is not connected to any channel. + guild_channel_id: Option(Snowflake(GuildChannel)), + /// Is `None` when the user is not connected to any channel. + voice_like_channel_id: Option(Snowflake(VoiceLikeChannel)), + user_id: Snowflake(User), + guild_member: GuildMember, + session_id: String, + is_guild_deafened: Bool, + is_guild_muted: Bool, + is_self_deafened: Bool, + is_self_muted: Bool, + is_streaming: Bool, + is_sharing_camera: Bool, + /// For stage channels with an active instance, whether the user's request to speak was denied. + is_suppressed: Bool, + /// For stage channels with an active instance, when the user requested to speak. + request_to_speak_timestamp: Option(Timestamp), + ) +} + +fn voice_state_decoder() -> Decoder(VoiceState) { + use guild_id <- decode.field("guild_id", snowflake_decoder()) + use channel_id <- decode.field( + "channel_id", + decode.optional(snowflake_decoder()), + ) + use guild_channel_id <- decode.field( + "channel_id", + decode.optional(snowflake_decoder()), + ) + use voice_like_channel_id <- decode.field( + "channel_id", + decode.optional(snowflake_decoder()), + ) + use user_id <- decode.field("user_id", snowflake_decoder()) + use guild_member <- decode.field("member", guild_member_decoder()) + use session_id <- decode.field("session_id", decode.string) + use is_guild_deafened <- decode.field("deaf", decode.bool) + use is_guild_muted <- decode.field("mute", decode.bool) + use is_self_deafened <- decode.field("self_deaf", decode.bool) + use is_self_muted <- decode.field("self_mute", decode.bool) + use is_streaming <- decode.optional_field("self_stream", False, decode.bool) + use is_sharing_camera <- decode.field("self_video", decode.bool) + use is_suppressed <- decode.field("suppress", decode.bool) + use request_to_speak_timestamp <- decode.field( + "request_to_speak_timestamp", + decode.optional(rfc3339_decoder()), + ) + decode.success(VoiceState( + guild_id:, + channel_id:, + guild_channel_id:, + voice_like_channel_id:, + user_id:, + guild_member:, + session_id:, + is_guild_deafened:, + is_guild_muted:, + is_self_deafened:, + is_self_muted:, + is_streaming:, + is_sharing_camera:, + is_suppressed:, + request_to_speak_timestamp:, + )) +} + +pub fn get_voice_regions_request(token token: Token) -> Request(String) { + new_request(token:, to: "/voice/regions", method: http.Get) +} + +pub fn get_voice_regions_response( + response: Response(String), +) -> Result(List(VoiceRegion), RestError) { + handle_response( + response, + decode_with: decode.list(of: voice_region_decoder()), + ) +} + +pub fn get_current_user_voice_state_request( + token token: Token, + in_guild_with_id guild_id: Snowflake(Guild), +) -> Request(String) { + new_request( + token:, + to: "/guilds/" <> snowflake_to_string(guild_id) <> "/voice-states/@me", + method: http.Get, + ) +} + +pub fn get_current_user_voice_state_response( + response: Response(String), +) -> Result(VoiceState, RestError) { + handle_response(response, decode_with: voice_state_decoder()) +} + +/// If the user is connected to a voice channel, +/// requires the `AllowConnectingToVoiceChannels` permission in that channel. +pub fn get_user_voice_state_request( + token token: Token, + in_guild_with_id guild_id: Snowflake(Guild), + for_user_with_id user_id: Snowflake(User), +) -> Request(String) { + new_request( + token:, + to: "/guilds/" + <> snowflake_to_string(guild_id) + <> "/voice-states/" + <> snowflake_to_string(user_id), + method: http.Get, + ) +} + +pub fn get_user_voice_state_response( + response: Response(String), +) -> Result(VoiceState, RestError) { + handle_response(response, decode_with: voice_state_decoder()) +}