diff --git a/src/grom.gleam b/src/grom.gleam index a379342..42dbe7e 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -22241,3 +22241,85 @@ pub fn delete_guild_command_response( ) -> Result(Nil, RestError) { handle_no_content_response(response) } + +pub opaque type BulkOverwriteGuildCommands { + BulkOverwriteGuildCommands( + slash_commands: List(CreateGuildSlashCommand), + user_commands: List(CreateGuildUserCommand), + message_commands: List(CreateGuildMessageCommand), + ) +} + +pub fn bulk_overwrite_guild_commands() -> BulkOverwriteGuildCommands { + BulkOverwriteGuildCommands( + slash_commands: [], + user_commands: [], + message_commands: [], + ) +} + +pub fn bulk_overwrite_guild_slash_commands( + bulk_overwrite: BulkOverwriteGuildCommands, + new slash_commands: List(CreateGuildSlashCommand), +) -> BulkOverwriteGuildCommands { + BulkOverwriteGuildCommands(..bulk_overwrite, slash_commands:) +} + +pub fn bulk_overwrite_guild_user_commands( + bulk_overwrite: BulkOverwriteGuildCommands, + new user_commands: List(CreateGuildUserCommand), +) -> BulkOverwriteGuildCommands { + BulkOverwriteGuildCommands(..bulk_overwrite, user_commands:) +} + +pub fn bulk_overwrite_guild_message_commands( + bulk_overwrite: BulkOverwriteGuildCommands, + new message_commands: List(CreateGuildMessageCommand), +) -> BulkOverwriteGuildCommands { + BulkOverwriteGuildCommands(..bulk_overwrite, message_commands:) +} + +pub fn bulk_overwrite_guild_commands_to_json( + bulk_overwrite: BulkOverwriteGuildCommands, +) -> Json { + let slash_commands = + bulk_overwrite.slash_commands + |> list.map(create_guild_slash_command_to_json) + let user_commands = + bulk_overwrite.user_commands |> list.map(create_guild_user_command_to_json) + let message_commands = + bulk_overwrite.message_commands + |> list.map(create_guild_message_command_to_json) + + slash_commands + |> list.append(user_commands) + |> list.append(message_commands) + |> json.preprocessed_array +} + +pub fn bulk_overwrite_guild_commands_request( + token token: Token, + current_application_id application_id: Snowflake(Application), + guild_id guild_id: Snowflake(Guild), + using bulk_overwrite: BulkOverwriteGuildCommands, +) -> Request(String) { + let body = + bulk_overwrite |> bulk_overwrite_guild_commands_to_json |> json.to_string + + new_request( + token:, + to: "/applications/" + <> snowflake_to_string(application_id) + <> "/guilds/" + <> snowflake_to_string(guild_id) + <> "/commands", + method: http.Put, + ) + |> request.set_body(body) +} + +pub fn bulk_ovewrite_guild_commands_response( + response: Response(String), +) -> Result(List(Command), RestError) { + handle_response(response:, decode_with: decode.list(of: command_decoder())) +}