diff --git a/src/grom.gleam b/src/grom.gleam index b4a95f6..0386dd9 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -20402,6 +20402,7 @@ pub opaque type CreateGlobalSlashCommand { description_localizations: Option(Dict(Locale, String)), required_permissions: Option(List(Permission)), options: List(SlashCommandOption), + installation_types: Option(List(CommandInstallationType)), contexts: Option(List(CommandContext)), is_nsfw: Bool, ) @@ -20411,16 +20412,6 @@ pub fn create_global_slash_command_to_json( create: CreateGlobalSlashCommand, ) -> Json { // if discord adds another integration type ever im gonna be angwy - let integration_types = case - create.is_guild_installable, - create.is_user_installable - { - True, True -> ["0", "1"] - True, False -> ["0"] - False, True -> ["1"] - False, False -> [] - } - [ Ok(#("type", json.int(1))), Ok(#("name", json.string(create.name))), @@ -20442,8 +20433,14 @@ pub fn create_global_slash_command_to_json( flags_to_string_json(_, bits_permissions()), ), Ok(#("nsfw", json.bool(create.is_nsfw))), - Ok(#("integration_types", json.array(integration_types, json.string))), - Ok(#("contexts", json.array(create.contexts, command_context_to_json))), + optional_to_json(create.installation_types, "integration_types", json.array( + _, + command_installation_type_to_json, + )), + optional_to_json(create.contexts, "contexts", json.array( + _, + command_context_to_json, + )), ] |> list_to_json_object } @@ -20462,9 +20459,8 @@ pub fn new_global_slash_command( description_localizations: None, required_permissions: None, options: [], - is_user_installable: False, - is_guild_installable: False, - contexts: [], + installation_types: None, + contexts: None, is_nsfw: False, ) } @@ -20508,25 +20504,19 @@ pub fn new_global_slash_command_with_options( CreateGlobalSlashCommand(..create, options:) } -/// This will make the command available in guilds where your application was guild-installed. -pub fn new_guild_installable_global_slash_command( +/// Check [CommandInstallationType](#CommandInstallationType) documentation. +pub fn new_global_slash_command_with_allowed_installation_types( create: CreateGlobalSlashCommand, + types: List(CommandInstallationType), ) -> CreateGlobalSlashCommand { - CreateGlobalSlashCommand(..create, is_guild_installable: True) + CreateGlobalSlashCommand(..create, installation_types: Some(types)) } -/// This will make the command available in contexts where your application was user-installed. -pub fn new_user_installable_global_slash_command( - create: CreateGlobalSlashCommand, -) -> CreateGlobalSlashCommand { - CreateGlobalSlashCommand(..create, is_user_installable: True) -} - -pub fn new_global_slash_command_with_contexts( +pub fn new_global_slash_command_with_allowed_contexts( create: CreateGlobalSlashCommand, contexts: List(CommandContext), ) -> CreateGlobalSlashCommand { - CreateGlobalSlashCommand(..create, contexts:) + CreateGlobalSlashCommand(..create, contexts: Some(contexts)) } /// This will only make the command usable in NSFW contexts. @@ -20542,7 +20532,7 @@ pub opaque type CreateGlobalUserCommand { name_localizations: Option(Dict(Locale, String)), required_permissions: Option(List(Permission)), installation_types: Option(List(CommandInstallationType)), - contexts: List(CommandContext), + contexts: Option(List(CommandContext)), is_nsfw: Bool, ) } @@ -20568,7 +20558,10 @@ pub fn create_global_user_command_to_json( _, command_installation_type_to_json, )), - Ok(#("contexts", json.array(create.contexts, command_context_to_json))), + optional_to_json(create.contexts, "contexts", json.array( + _, + command_context_to_json, + )), ] |> list_to_json_object } @@ -20579,9 +20572,8 @@ pub fn new_global_user_command(named name: String) -> CreateGlobalUserCommand { name:, name_localizations: None, required_permissions: None, - is_user_installable: False, - is_guild_installable: False, - contexts: [], + installation_types: None, + contexts: None, is_nsfw: False, ) } @@ -20606,25 +20598,19 @@ pub fn new_global_user_command_with_required_permissions( CreateGlobalUserCommand(..create, required_permissions: Some(permissions)) } -/// This will make the command available in guilds where your application was guild-installed. -pub fn new_guild_installable_global_user_command( +/// Check [CommandInstallationType](#CommandInstallationType) documentation. +pub fn new_global_user_command_with_allowed_installation_types( create: CreateGlobalUserCommand, + types: List(CommandInstallationType), ) -> CreateGlobalUserCommand { - CreateGlobalUserCommand(..create, is_guild_installable: True) + CreateGlobalUserCommand(..create, installation_types: Some(types)) } -/// This will make the command available in contexts where your application was user-installed. -pub fn new_user_installable_global_user_command( - create: CreateGlobalUserCommand, -) -> CreateGlobalUserCommand { - CreateGlobalUserCommand(..create, is_user_installable: True) -} - -pub fn new_global_user_command_with_contexts( +pub fn new_global_user_command_with_allowed_contexts( create: CreateGlobalUserCommand, contexts: List(CommandContext), ) -> CreateGlobalUserCommand { - CreateGlobalUserCommand(..create, contexts:) + CreateGlobalUserCommand(..create, contexts: Some(contexts)) } /// This will only make the command usable in NSFW contexts. @@ -20639,9 +20625,8 @@ pub opaque type CreateGlobalMessageCommand { name: String, name_localizations: Option(Dict(Locale, String)), required_permissions: Option(List(Permission)), - is_user_installable: Bool, - is_guild_installable: Bool, - contexts: List(CommandContext), + installation_types: Option(List(CommandInstallationType)), + contexts: Option(List(CommandContext)), is_nsfw: Bool, ) } @@ -20650,16 +20635,6 @@ pub fn create_global_message_command_to_json( create: CreateGlobalMessageCommand, ) -> Json { // if discord adds another integration type ever im gonna be angwy - let integration_types = case - create.is_guild_installable, - create.is_user_installable - { - True, True -> ["0", "1"] - True, False -> ["0"] - False, True -> ["1"] - False, False -> [] - } - [ Ok(#("type", json.int(3))), Ok(#("name", json.string(create.name))), @@ -20674,8 +20649,14 @@ pub fn create_global_message_command_to_json( flags_to_string_json(_, bits_permissions()), ), Ok(#("nsfw", json.bool(create.is_nsfw))), - Ok(#("integration_types", json.array(integration_types, json.string))), - Ok(#("contexts", json.array(create.contexts, command_context_to_json))), + optional_to_json(create.installation_types, "integration_types", json.array( + _, + command_installation_type_to_json, + )), + optional_to_json(create.contexts, "contexts", json.array( + _, + command_context_to_json, + )), ] |> list_to_json_object } @@ -20688,9 +20669,8 @@ pub fn new_global_message_command( name:, name_localizations: None, required_permissions: None, - is_user_installable: False, - is_guild_installable: False, - contexts: [], + installation_types: None, + contexts: None, is_nsfw: False, ) } @@ -20715,25 +20695,19 @@ pub fn new_global_message_command_with_required_permissions( CreateGlobalMessageCommand(..create, required_permissions: Some(permissions)) } -/// This will make the command available in guilds where your application was guild-installed. -pub fn new_guild_installable_global_message_command( - create: CreateGlobalMessageCommand, -) -> CreateGlobalMessageCommand { - CreateGlobalMessageCommand(..create, is_guild_installable: True) -} - -/// This will make the command available in contexts where your application was user-installed. -pub fn new_message_installable_global_message_command( +/// Check [CommandInstallationType](#CommandInstallationType) documentation. +pub fn new_global_message_command_with_allowed_installation_types( create: CreateGlobalMessageCommand, + types: List(CommandInstallationType), ) -> CreateGlobalMessageCommand { - CreateGlobalMessageCommand(..create, is_user_installable: True) + CreateGlobalMessageCommand(..create, installation_types: Some(types)) } -pub fn new_global_message_command_with_contexts( +pub fn new_global_message_command_with_allowed_contexts( create: CreateGlobalMessageCommand, contexts: List(CommandContext), ) -> CreateGlobalMessageCommand { - CreateGlobalMessageCommand(..create, contexts:) + CreateGlobalMessageCommand(..create, contexts: Some(contexts)) } /// This will only make the command usable in NSFW contexts. @@ -20848,9 +20822,8 @@ pub opaque type ModifyGlobalSlashCommand { description_localizations: Modification(Dict(Locale, String)), required_permissions: Modification(List(Permission)), options: Option(List(SlashCommandOption)), - is_user_installable: Option(Bool), - is_guild_installable: Option(Bool), - contexts: Option(List(CommandContext)), + installation_types: Modification(List(CommandInstallationType)), + contexts: Modification(List(CommandContext)), is_nsfw: Option(Bool), ) } @@ -20863,17 +20836,63 @@ pub fn modify_global_slash_command() -> ModifyGlobalSlashCommand { description_localizations: Skip, required_permissions: Skip, options: None, - is_user_installable: None, - is_guild_installable: None, - contexts: None, + installation_types: Skip, + contexts: Skip, is_nsfw: None, ) } +pub fn modify_global_slash_command_to_json( + modify: ModifyGlobalSlashCommand, +) -> Json { + [ + optional_to_json(modify.name, "name", json.string), + modification_to_json( + modify.name_localizations, + "name_localizations", + json.dict(_, locale_to_string, json.string), + ), + optional_to_json(modify.description, "description", json.string), + modification_to_json( + modify.description_localizations, + "description_localizations", + json.dict(_, locale_to_string, json.string), + ), + optional_to_json(modify.options, "options", json.array( + _, + slash_command_option_to_json, + )), + modification_to_json( + modify.required_permissions, + "default_member_permissions", + flags_to_string_json(_, bits_permissions()), + ), + modification_to_json( + modify.installation_types, + "integration_types", + json.array(_, command_installation_type_to_json), + ), + modification_to_json(modify.contexts, "contexts", json.array( + _, + command_context_to_json, + )), + optional_to_json(modify.is_nsfw, "nsfw", json.bool), + ] + |> list_to_json_object +} + +/// Name must be between 1 and 32 characters. +pub fn modify_global_slash_command_name( + modify: ModifyGlobalSlashCommand, + new name: String, +) -> ModifyGlobalSlashCommand { + ModifyGlobalSlashCommand(..modify, name: Some(name)) +} + /// Name must be between 1 and 32 characters. pub fn modify_global_slash_command_name_localizations( modify: ModifyGlobalSlashCommand, - localizations: Dict(Locale, String), + new localizations: Dict(Locale, String), ) -> ModifyGlobalSlashCommand { ModifyGlobalSlashCommand(..modify, name_localizations: Modify(localizations)) } @@ -20884,10 +20903,18 @@ pub fn delete_global_slash_command_name_localizations( ModifyGlobalSlashCommand(..modify, name_localizations: Delete) } +/// Description must be between 1 and 100 characters. +pub fn modify_global_slash_command_description( + modify: ModifyGlobalSlashCommand, + new description: String, +) -> ModifyGlobalSlashCommand { + ModifyGlobalSlashCommand(..modify, description: Some(description)) +} + /// Description must be between 1 and 100 characters. pub fn modify_global_slash_command_description_localizations( modify: ModifyGlobalSlashCommand, - localizations: Dict(Locale, String), + new localizations: Dict(Locale, String), ) -> ModifyGlobalSlashCommand { ModifyGlobalSlashCommand( ..modify, @@ -20895,6 +20922,12 @@ pub fn modify_global_slash_command_description_localizations( ) } +pub fn delete_global_slash_command_description_localizations( + modify: ModifyGlobalSlashCommand, +) -> ModifyGlobalSlashCommand { + ModifyGlobalSlashCommand(..modify, description_localizations: Delete) +} + /// Use [`delete_global_slash_command_required_permissions`](#delete_global_slash_command_required_permissions) /// to enable the command for everyone. /// @@ -20903,7 +20936,7 @@ pub fn modify_global_slash_command_description_localizations( /// Passing a list with at least one permission will require those permissions to use the command. pub fn modify_global_slash_command_required_permissions( modify: ModifyGlobalSlashCommand, - permissions: List(Permission), + new permissions: List(Permission), ) -> ModifyGlobalSlashCommand { ModifyGlobalSlashCommand(..modify, required_permissions: Modify(permissions)) } @@ -20918,29 +20951,360 @@ pub fn delete_global_slash_command_required_permissions( /// There is a limit of 25 options per command. pub fn modify_global_slash_command_options( modify: ModifyGlobalSlashCommand, - options: List(SlashCommandOption), + new options: List(SlashCommandOption), ) -> ModifyGlobalSlashCommand { ModifyGlobalSlashCommand(..modify, options: Some(options)) } -pub fn modify_global_slash_command_installation_settings( +pub fn modify_global_slash_command_allowed_installation_types( modify: ModifyGlobalSlashCommand, + new types: List(CommandInstallationType), ) -> ModifyGlobalSlashCommand { - ModifyGlobalSlashCommand(..modify, is_guild_installable: Some(True)) + ModifyGlobalSlashCommand(..modify, installation_types: Modify(types)) } pub fn modify_global_slash_command_with_contexts( modify: ModifyGlobalSlashCommand, contexts: List(CommandContext), ) -> ModifyGlobalSlashCommand { - ModifyGlobalSlashCommand(..modify, contexts:) + ModifyGlobalSlashCommand(..modify, contexts: Modify(contexts)) } /// This will only make the command usable in NSFW contexts. -pub fn modify_nsfw_global_slash_command( +pub fn set_global_slash_command_as_nsfw( + modify: ModifyGlobalSlashCommand, +) -> ModifyGlobalSlashCommand { + ModifyGlobalSlashCommand(..modify, is_nsfw: Some(True)) +} + +/// This will only make the command also available outside of NSFW contexts. +pub fn set_global_slash_command_as_sfw( modify: ModifyGlobalSlashCommand, ) -> ModifyGlobalSlashCommand { - ModifyGlobalSlashCommand(..modify, is_nsfw: True) + ModifyGlobalSlashCommand(..modify, is_nsfw: Some(False)) +} + +pub fn modify_global_slash_command_request( + token token: Token, + current_application_id application_id: Snowflake(Application), + command_with_id command_id: Snowflake(SlashCommand), + using modify: ModifyGlobalSlashCommand, +) -> Request(String) { + let body = modify |> modify_global_slash_command_to_json |> json.to_string + + new_request( + token:, + to: "/applications/" + <> snowflake_to_string(application_id) + <> "/commands/" + <> snowflake_to_string(command_id), + method: http.Patch, + ) + |> request.set_body(body) +} + +pub fn modify_global_slash_command_response( + response: Response(String), +) -> Result(SlashCommand, RestError) { + handle_response(response:, decode_with: slash_command_decoder()) +} + +pub opaque type ModifyGlobalUserCommand { + ModifyGlobalUserCommand( + name: Option(String), + name_localizations: Modification(Dict(Locale, String)), + required_permissions: Modification(List(Permission)), + installation_types: Modification(List(CommandInstallationType)), + contexts: Modification(List(CommandContext)), + is_nsfw: Option(Bool), + ) +} + +pub fn modify_global_user_command() -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand( + name: None, + name_localizations: Skip, + required_permissions: Skip, + installation_types: Skip, + contexts: Skip, + is_nsfw: None, + ) +} + +pub fn modify_global_user_command_to_json( + modify: ModifyGlobalUserCommand, +) -> Json { + [ + optional_to_json(modify.name, "name", json.string), + modification_to_json( + modify.name_localizations, + "name_localizations", + json.dict(_, locale_to_string, json.string), + ), + modification_to_json( + modify.required_permissions, + "default_member_permissions", + flags_to_string_json(_, bits_permissions()), + ), + modification_to_json( + modify.installation_types, + "integration_types", + json.array(_, command_installation_type_to_json), + ), + modification_to_json(modify.contexts, "contexts", json.array( + _, + command_context_to_json, + )), + optional_to_json(modify.is_nsfw, "nsfw", json.bool), + ] + |> list_to_json_object +} + +/// Name must be between 1 and 32 characters. +pub fn modify_global_user_command_name( + modify: ModifyGlobalUserCommand, + new name: String, +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, name: Some(name)) +} + +/// Name must be between 1 and 32 characters. +pub fn modify_global_user_command_name_localizations( + modify: ModifyGlobalUserCommand, + new localizations: Dict(Locale, String), +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, name_localizations: Modify(localizations)) +} + +pub fn delete_global_user_command_name_localizations( + modify: ModifyGlobalUserCommand, +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, name_localizations: Delete) +} + +/// Use [`delete_global_user_command_required_permissions`](#delete_global_user_command_required_permissions) +/// to enable the command for everyone. +/// +/// Passing an empty list will disable the command for everyone. +/// +/// Passing a list with at least one permission will require those permissions to use the command. +pub fn modify_global_user_command_required_permissions( + modify: ModifyGlobalUserCommand, + new permissions: List(Permission), +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, required_permissions: Modify(permissions)) +} + +/// Enables the command for everyone. +pub fn delete_global_user_command_required_permissions( + modify: ModifyGlobalUserCommand, +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, required_permissions: Delete) +} + +pub fn modify_global_user_command_allowed_installation_types( + modify: ModifyGlobalUserCommand, + new types: List(CommandInstallationType), +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, installation_types: Modify(types)) +} + +pub fn modify_global_user_command_with_contexts( + modify: ModifyGlobalUserCommand, + contexts: List(CommandContext), +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, contexts: Modify(contexts)) +} + +/// This will only make the command usable in NSFW contexts. +pub fn set_global_user_command_as_nsfw( + modify: ModifyGlobalUserCommand, +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, is_nsfw: Some(True)) +} + +/// This will only make the command also available outside of NSFW contexts. +pub fn set_global_user_command_as_sfw( + modify: ModifyGlobalUserCommand, +) -> ModifyGlobalUserCommand { + ModifyGlobalUserCommand(..modify, is_nsfw: Some(False)) +} + +pub fn modify_global_user_command_request( + token token: Token, + current_application_id application_id: Snowflake(Application), + command_with_id command_id: Snowflake(UserCommand), + using modify: ModifyGlobalUserCommand, +) -> Request(String) { + let body = modify |> modify_global_user_command_to_json |> json.to_string + + new_request( + token:, + to: "/applications/" + <> snowflake_to_string(application_id) + <> "/commands/" + <> snowflake_to_string(command_id), + method: http.Patch, + ) + |> request.set_body(body) +} + +pub fn modify_global_user_command_response( + response: Response(String), +) -> Result(UserCommand, RestError) { + handle_response(response:, decode_with: user_command_decoder()) +} + +pub opaque type ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand( + name: Option(String), + name_localizations: Modification(Dict(Locale, String)), + required_permissions: Modification(List(Permission)), + installation_types: Modification(List(CommandInstallationType)), + contexts: Modification(List(CommandContext)), + is_nsfw: Option(Bool), + ) +} + +pub fn modify_global_message_command() -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand( + name: None, + name_localizations: Skip, + required_permissions: Skip, + installation_types: Skip, + contexts: Skip, + is_nsfw: None, + ) +} + +pub fn modify_global_message_command_to_json( + modify: ModifyGlobalMessageCommand, +) -> Json { + [ + optional_to_json(modify.name, "name", json.string), + modification_to_json( + modify.name_localizations, + "name_localizations", + json.dict(_, locale_to_string, json.string), + ), + modification_to_json( + modify.required_permissions, + "default_member_permissions", + flags_to_string_json(_, bits_permissions()), + ), + modification_to_json( + modify.installation_types, + "integration_types", + json.array(_, command_installation_type_to_json), + ), + modification_to_json(modify.contexts, "contexts", json.array( + _, + command_context_to_json, + )), + optional_to_json(modify.is_nsfw, "nsfw", json.bool), + ] + |> list_to_json_object +} + +/// Name must be between 1 and 32 characters. +pub fn modify_global_message_command_name( + modify: ModifyGlobalMessageCommand, + new name: String, +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, name: Some(name)) +} + +/// Name must be between 1 and 32 characters. +pub fn modify_global_message_command_name_localizations( + modify: ModifyGlobalMessageCommand, + new localizations: Dict(Locale, String), +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand( + ..modify, + name_localizations: Modify(localizations), + ) +} + +pub fn delete_global_message_command_name_localizations( + modify: ModifyGlobalMessageCommand, +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, name_localizations: Delete) +} + +/// Use [`delete_global_message_command_required_permissions`](#delete_global_message_command_required_permissions) +/// to enable the command for everyone. +/// +/// Passing an empty list will disable the command for everyone. +/// +/// Passing a list with at least one permission will require those permissions to use the command. +pub fn modify_global_message_command_required_permissions( + modify: ModifyGlobalMessageCommand, + new permissions: List(Permission), +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand( + ..modify, + required_permissions: Modify(permissions), + ) +} + +/// Enables the command for everyone. +pub fn delete_global_message_command_required_permissions( + modify: ModifyGlobalMessageCommand, +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, required_permissions: Delete) +} + +pub fn modify_global_message_command_allowed_installation_types( + modify: ModifyGlobalMessageCommand, + new types: List(CommandInstallationType), +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, installation_types: Modify(types)) +} + +pub fn modify_global_message_command_with_contexts( + modify: ModifyGlobalMessageCommand, + contexts: List(CommandContext), +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, contexts: Modify(contexts)) +} + +/// This will only make the command usable in NSFW contexts. +pub fn set_global_message_command_as_nsfw( + modify: ModifyGlobalMessageCommand, +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, is_nsfw: Some(True)) +} + +/// This will only make the command also available outside of NSFW contexts. +pub fn set_global_message_command_as_sfw( + modify: ModifyGlobalMessageCommand, +) -> ModifyGlobalMessageCommand { + ModifyGlobalMessageCommand(..modify, is_nsfw: Some(False)) +} + +pub fn modify_global_message_command_request( + token token: Token, + current_application_id application_id: Snowflake(Application), + command_with_id command_id: Snowflake(MessageCommand), + using modify: ModifyGlobalMessageCommand, +) -> Request(String) { + let body = modify |> modify_global_message_command_to_json |> json.to_string + + new_request( + token:, + to: "/applications/" + <> snowflake_to_string(application_id) + <> "/commands/" + <> snowflake_to_string(command_id), + method: http.Patch, + ) + |> request.set_body(body) +} + +pub fn modify_global_message_command_response( + response: Response(String), +) -> Result(MessageCommand, RestError) { + handle_response(response:, decode_with: message_command_decoder()) } /// See also: [ApplicationInstallationType](#ApplicationInstallationType)