diff --git a/gleam.toml b/gleam.toml index 0dfb102..51cf6f0 100644 --- a/gleam.toml +++ b/gleam.toml @@ -7,11 +7,6 @@ internal_modules = [ "grom/internal/*" ] -# [documentation] -# pages = [ -# { title = "Your first bot", path = "01-your-first-bot.html", source = "./pages/01-your-first-bot.md"} -# ] - [dependencies] gleam_erlang = ">= 1.3.0 and < 2.0.0" gleam_http = ">= 4.0.0 and < 5.0.0" @@ -23,8 +18,6 @@ gleam_time = ">= 1.1.0 and < 2.0.0" multipart_form = ">= 1.1.0 and < 2.0.0" operating_system = ">= 1.0.1 and < 2.0.0" status_code = ">= 1.0.0 and < 2.0.0" -stratus = ">= 3.0.0 and < 4.0.0" -splitter = ">= 1.2.0 and < 2.0.0" gleam_community_colour = ">= 2.0.4 and < 3.0.0" json_value = ">= 1.0.0 and < 2.0.0" datebook = ">= 1.1.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index 4c2ecc5..e44670b 100644 --- a/manifest.toml +++ b/manifest.toml @@ -3,25 +3,19 @@ packages = [ { name = "datebook", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "datebook", source = "hex", outer_checksum = "8895C5D7F66AD8D785E550DDB875FAC9D5151020B1C00F00123A2240C030D76C" }, - { name = "exception", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "329D269D5C2A314F7364BD2711372B6F2C58FA6F39981572E5CA68624D291F8C" }, { name = "gleam_community_colour", version = "2.0.4", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "6DB4665555D7D2B27F0EA32EF47E8BEBC4303821765F9C73D483F38EE24894F0" }, - { name = "gleam_crypto", version = "1.5.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "43A25BCE17834475AEA7FFC9408B6D0FC1D709A682BCAE5FEFC6D4192CF47718" }, { name = "gleam_erlang", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "1124AD3AA21143E5AF0FC5CF3D9529F6DB8CA03E43A55711B60B6B7B3874375C" }, { name = "gleam_http", version = "4.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "82EA6A717C842456188C190AFB372665EA56CE13D8559BF3B1DD9E40F619EE0C" }, { name = "gleam_httpc", version = "5.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "C545172618D07811494E97AAA4A0FB34DA6F6D0061FDC8041C2F8E3BE2B2E48F" }, { name = "gleam_json", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "44FDAA8847BE8FC48CA7A1C089706BD54BADCC4C45B237A992EDDF9F2CDB2836" }, { name = "gleam_otp", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BA6A294E295E428EC1562DC1C11EA7530DCB981E8359134BEABC8493B7B2258E" }, - { name = "gleam_stdlib", version = "0.71.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "702F3BC2A14793906880B1078B19A6165F87323AEE8D0C4A34085846336FCAAE" }, + { name = "gleam_stdlib", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "960090C2FB391784BB34267B099DC9315CC1B1F6013E7415BC763CEF1905D7D3" }, { name = "gleam_time", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "533D8723774D61AD4998324F5DD1DABDCDBFABAFB9E87CB5D03C6955448FC97D" }, - { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, - { name = "gramps", version = "6.0.0", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "8B7195978FBFD30B43DF791A8A272041B81E45D245314D7A41FC57237AA882A0" }, + { name = "gleeunit", version = "1.10.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "254B697FE72EEAD7BF82E941723918E421317813AC49923EE76A18C788C61E72" }, { name = "json_value", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "json_value", source = "hex", outer_checksum = "D784AA7A33EAF1349C58EE79E3587484B4086D22079C2C4960DED5DC46FB2899" }, - { name = "logging", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "BC5F18CE5DD9686100229FE5409BDC3DD5C46D5A7DF2F804AD2D8F0DD6C5060E" }, { name = "multipart_form", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib"], otp_app = "multipart_form", source = "hex", outer_checksum = "082C77A0C3BB1128FCD55491665E9B72BC943E849B67D02B08CFA6808AD8E47C" }, { name = "operating_system", version = "1.0.1", build_tools = ["gleam"], requirements = [], otp_app = "operating_system", source = "hex", outer_checksum = "682D4D19496E607A6E6229AA51A38A1400ED5067C2C54D56843DBCB0C61FFA6D" }, - { name = "splitter", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "splitter", source = "hex", outer_checksum = "3DFD6B6C49E61EDAF6F7B27A42054A17CFF6CA2135FF553D0CB61C234D281DD0" }, { name = "status_code", version = "1.1.0", build_tools = ["gleam"], requirements = [], otp_app = "status_code", source = "hex", outer_checksum = "F6EC765345A634602AD030EB1B4D34A425873CBC223CEC595EBF062073CD70BC" }, - { name = "stratus", version = "3.0.0", build_tools = ["gleam"], requirements = ["exception", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "gramps", "logging"], otp_app = "stratus", source = "hex", outer_checksum = "21C93D657E4E7964E36EACDE83609459F259289DF403B5FEBD3C60612594BE24" }, ] [requirements] @@ -38,6 +32,8 @@ gleeunit = { version = ">= 1.0.0 and < 2.0.0" } json_value = { version = ">= 1.0.0 and < 2.0.0" } multipart_form = { version = ">= 1.1.0 and < 2.0.0" } operating_system = { version = ">= 1.0.1 and < 2.0.0" } -splitter = { version = ">= 1.2.0 and < 2.0.0" } status_code = { version = ">= 1.0.0 and < 2.0.0" } +<<<<<<< HEAD stratus = { version = ">= 3.0.0 and < 4.0.0" } +======= +>>>>>>> 3cbcf5b (thats enough for a commit) diff --git a/src/grom.gleam b/src/grom.gleam index c8f6e8e..78b57d1 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -3728,7 +3728,9 @@ pub fn modify_guild_member_verification_level( } /// Resets the guild's member verification level back to default. -pub fn reset_guild_member_verification_level(modify: ModifyGuild) -> ModifyGuild { +pub fn reset_guild_member_verification_level( + modify: ModifyGuild, +) -> ModifyGuild { ModifyGuild(..modify, member_verification_level: Delete) } @@ -4458,7 +4460,9 @@ pub fn create_text_channel_with_parent_id( } /// Creates an age-restricted text channel. -pub fn create_nsfw_text_channel(create: CreateTextChannel) -> CreateTextChannel { +pub fn create_nsfw_text_channel( + create: CreateTextChannel, +) -> CreateTextChannel { CreateTextChannel(..create, is_nsfw: Some(True)) } @@ -4674,7 +4678,9 @@ pub fn create_category_channel( |> send_request(decode_with: guild_channel_decoder()) } -pub fn new_create_category_channel(named name: String) -> CreateCategoryChannel { +pub fn new_create_category_channel( + named name: String, +) -> CreateCategoryChannel { CreateCategoryChannel(name, None, None) } @@ -5243,6 +5249,7 @@ pub fn new_modify_guild_channel_position( ModifyGuildChannelPosition(id, Skip, None, Skip) } +/// Channels with the same position are sorted by ID (newer channel will be lower) pub fn modify_guild_channel_position( modify: ModifyGuildChannelPosition, new position: Int, @@ -5495,7 +5502,9 @@ pub fn modify_guild_member_nick( } /// Requires the `AllowManagingNicknames` permission. -pub fn delete_guild_member_nick(modify: ModifyGuildMember) -> ModifyGuildMember { +pub fn delete_guild_member_nick( + modify: ModifyGuildMember, +) -> ModifyGuildMember { ModifyGuildMember(..modify, nick: Delete) } @@ -5512,7 +5521,9 @@ pub fn modify_guild_member_roles( /// Requires the `AllowManagingRoles` permission. /// /// Does not actually delete the roles - only removes them from the member. -pub fn delete_guild_member_roles(modify: ModifyGuildMember) -> ModifyGuildMember { +pub fn delete_guild_member_roles( + modify: ModifyGuildMember, +) -> ModifyGuildMember { ModifyGuildMember(..modify, roles: Delete) } @@ -6147,7 +6158,10 @@ pub fn create_hoisted_role(create: CreateRole) -> CreateRole { } /// Requires the `GuildCanUseRoleIcons` feature. -pub fn create_role_with_icon(create: CreateRole, icon: ImageData) -> CreateRole { +pub fn create_role_with_icon( + create: CreateRole, + icon: ImageData, +) -> CreateRole { CreateRole(..create, icon: Some(icon)) } @@ -7670,7 +7684,9 @@ pub opaque type ModifyGuildWelcomeScreen { ) } -fn modify_guild_welcome_screen_to_json(modify: ModifyGuildWelcomeScreen) -> Json { +fn modify_guild_welcome_screen_to_json( + modify: ModifyGuildWelcomeScreen, +) -> Json { [ modification_to_json(modify.is_enabled, "enabled", json.bool), modification_to_json( @@ -7904,7 +7920,9 @@ pub opaque type ModifyGuildIncidentsData { ) } -fn modify_guild_incidents_data_to_json(modify: ModifyGuildIncidentsData) -> Json { +fn modify_guild_incidents_data_to_json( + modify: ModifyGuildIncidentsData, +) -> Json { [ modification_to_json( modify.invites_disabled_until, @@ -8020,9 +8038,23 @@ pub opaque type ModifyTextChannel { default_thread_auto_archive_duration: Modification( ThreadAutoArchiveDuration, ), + default_thread_rate_limit_per_user: Option(Duration), ) } +pub fn modify_text_channel_topic( + modify: ModifyTextChannel, + new topic: String, +) -> ModifyTextChannel { + ModifyTextChannel(..modify, topic: Modify(topic)) +} + +pub fn delete_text_channel_topic( + modify: ModifyTextChannel, +) -> ModifyTextChannel { + ModifyTextChannel(..modify, topic: Delete) +} + fn modify_text_channel_to_json(modify: ModifyTextChannel) -> Json { let type_ = case modify.switch_to_announcement { Some(True) -> Ok(#("type", json.int(5))) @@ -8051,13 +8083,29 @@ fn modify_text_channel_to_json(modify: ModifyTextChannel) -> Json { "default_auto_archive_duration", thread_auto_archive_duration_to_json, ), + optional_to_json( + modify.default_thread_rate_limit_per_user, + "default_thread_rate_limit_per_user", + duration_to_json_seconds, + ), ] |> list.filter_map(function.identity) |> json.object } pub fn new_modify_text_channel() -> ModifyTextChannel { - ModifyTextChannel(None, None, Skip, Skip, None, Skip, None, Skip, Skip) + ModifyTextChannel(None, None, Skip, Skip, None, Skip, None, Skip, Skip, None) +} + +/// The modified value will only apply to new threads - existing threads won't auto-update. +pub fn modify_text_channel_default_thread_rate_limit_per_user( + modify: ModifyTextChannel, + new duration: Duration, +) -> ModifyTextChannel { + ModifyTextChannel( + ..modify, + default_thread_rate_limit_per_user: Some(duration), + ) } pub fn modify_text_channel_name( @@ -8074,6 +8122,7 @@ pub fn convert_text_channel_to_announcement_channel( ModifyTextChannel(..modify, switch_to_announcement: Some(True)) } +/// Channels with the same position are sorted by ID (newer channel will be lower) pub fn modify_text_channel_position( modify: ModifyTextChannel, new position: Int, @@ -8081,13 +8130,16 @@ pub fn modify_text_channel_position( ModifyTextChannel(..modify, position: Modify(position)) } +/// Channels without a specified position will automatically be assigned one at the bottom of their category/channel list. pub fn unset_text_channel_position( modify: ModifyTextChannel, ) -> ModifyTextChannel { ModifyTextChannel(..modify, position: Delete) } -pub fn set_text_channel_as_nsfw(modify: ModifyTextChannel) -> ModifyTextChannel { +pub fn set_text_channel_as_nsfw( + modify: ModifyTextChannel, +) -> ModifyTextChannel { ModifyTextChannel(..modify, is_nsfw: Some(True)) } @@ -8114,6 +8166,8 @@ pub fn delete_text_channel_rate_limit_per_user( ModifyTextChannel(..modify, rate_limit_per_user: Delete) } +/// You can only allow/deny permissions if your bot has those permissions. +/// Setting the `AllowManagingRoles` permission requires your bot to have the `AdministratorPermission`. pub fn modify_text_channel_permission_ovewrites( modify: ModifyTextChannel, new overwrites: List(PermissionOverwrite), @@ -8150,6 +8204,7 @@ pub fn unset_text_channel_default_thread_auto_archive_duration( ModifyTextChannel(..modify, default_thread_auto_archive_duration: Delete) } +/// Requires the `AllowManagingChannels` permission. pub fn modify_text_channel( token token: Token, with_id channel_id: Snowflake(TextChannel), @@ -8194,6 +8249,7 @@ pub fn modify_voice_channel_name( ModifyVoiceChannel(..modify, name: Some(name)) } +/// Channels with the same position are sorted by ID (newer channel will be lower) pub fn modify_voice_channel_position( modify: ModifyVoiceChannel, new position: Int, @@ -8201,6 +8257,7 @@ pub fn modify_voice_channel_position( ModifyVoiceChannel(..modify, position: Modify(position)) } +/// Channels without a specified position will automatically be assigned one at the bottom of their category/channel list. pub fn unset_voice_channel_position( modify: ModifyVoiceChannel, ) -> ModifyVoiceChannel { @@ -8257,6 +8314,8 @@ pub fn modify_voice_channel_user_limit( ModifyVoiceChannel(..modify, user_limit: Modify(limit)) } +/// You can only allow/deny permissions if your bot has those permissions. +/// Setting the `AllowManagingRoles` permission requires your bot to have the `AdministratorPermission`. pub fn modify_voice_channel_permission_overwrites( modify: ModifyVoiceChannel, new overwrites: List(PermissionOverwrite), @@ -8264,12 +8323,6 @@ pub fn modify_voice_channel_permission_overwrites( ModifyVoiceChannel(..modify, permission_overwrites: Some(overwrites)) } -pub fn delete_voice_channel_permission_overwrites( - modify: ModifyVoiceChannel, -) -> ModifyVoiceChannel { - ModifyVoiceChannel(..modify, permission_overwrites: None) -} - pub fn modify_voice_channel_parent_id( modify: ModifyVoiceChannel, new parent_id: Snowflake(CategoryChannel), @@ -8333,6 +8386,7 @@ fn modify_voice_channel_to_json(modify: ModifyVoiceChannel) -> Json { |> json.object } +/// Requires the `AllowManagingChannels` permission. pub fn modify_voice_channel( token token: Token, with_id channel_id: Snowflake(VoiceChannel), @@ -8350,3 +8404,126 @@ pub fn modify_voice_channel( |> request_with_reason(reason) |> send_request(decode_with: guild_channel_decoder()) } + +pub opaque type ModifyCategoryChannel { + ModifyCategoryChannel( + name: Option(String), + position: Modification(Int), + permission_overwrites: Option(List(PermissionOverwrite)), + ) +} + +pub fn new_modify_category_channel() -> ModifyCategoryChannel { + ModifyCategoryChannel(None, Skip, None) +} + +pub fn modify_category_channel_name( + modify: ModifyCategoryChannel, + new name: String, +) -> ModifyCategoryChannel { + ModifyCategoryChannel(..modify, name: Some(name)) +} + +/// Channels with the same position are sorted by ID (newer channel will be lower) +pub fn modify_category_channel_position( + modify: ModifyCategoryChannel, + new position: Int, +) -> ModifyCategoryChannel { + ModifyCategoryChannel(..modify, position: Modify(position)) +} + +/// Channels without a specified position will automatically be assigned one at the bottom of their category/channel list. +pub fn unset_category_channel_position( + modify: ModifyCategoryChannel, +) -> ModifyCategoryChannel { + ModifyCategoryChannel(..modify, position: Delete) +} + +/// You can only allow/deny permissions if your bot has those permissions. +/// Setting the `AllowManagingRoles` permission requires your bot to have the `AdministratorPermission`. +pub fn modify_category_channel_permission_overwrites( + modify: ModifyCategoryChannel, + new overwrites: List(PermissionOverwrite), +) -> ModifyCategoryChannel { + ModifyCategoryChannel(..modify, permission_overwrites: Some(overwrites)) +} + +fn modify_category_channel_to_json(modify: ModifyCategoryChannel) -> Json { + [ + optional_to_json(modify.name, "name", json.string), + modification_to_json(modify.position, "position", json.int), + optional_to_json( + modify.permission_overwrites, + "permission_overwrites", + json.array(_, permission_overwrite_to_json), + ), + ] + |> list.filter_map(function.identity) + |> json.object +} + +/// Requires the `AllowManagingChannels` permission. +pub fn modify_category_channel( + token token: Token, + with_id channel_id: Snowflake(CategoryChannel), + using modify: ModifyCategoryChannel, + reason reason: Option(String), +) -> Result(GuildChannel, RestError) { + let body = modify |> modify_category_channel_to_json |> json.to_string + + new_request( + token:, + to: "/channels/" <> snowflake_to_string(channel_id), + method: http.Patch, + ) + |> request.set_body(body) + |> request_with_reason(reason) + |> send_request(decode_with: guild_channel_decoder()) +} + +pub opaque type ModifyAnnouncementChannel { + ModifyAnnouncementChannel( + name: Option(String), + switch_to_text: Option(Bool), + position: Modification(Int), + topic: Modification(String), + is_nsfw: Option(Bool), + permission_overwrites: Option(List(PermissionOverwrite)), + parent_id: Modification(Snowflake(CategoryChannel)), + default_thread_auto_archive_duration: Modification( + ThreadAutoArchiveDuration, + ), + ) +} + +pub fn new_modify_announcement_channel() -> ModifyAnnouncementChannel { + ModifyAnnouncementChannel(None, None, Skip, Skip, None, None, Skip, Skip) +} + +pub fn modify_announcement_channel_name( + modify: ModifyAnnouncementChannel, + new name: String, +) -> ModifyAnnouncementChannel { + ModifyAnnouncementChannel(..modify, name: Some(name)) +} + +pub fn convert_announcement_channel_to_text_channel( + modify: ModifyAnnouncementChannel, +) -> ModifyAnnouncementChannel { + ModifyAnnouncementChannel(..modify, switch_to_text: Some(True)) +} + +/// Channels with the same position are sorted by ID (newer channel will be lower) +pub fn modify_announcement_channel_position( + modify: ModifyAnnouncementChannel, + new position: Int, +) -> ModifyAnnouncementChannel { + ModifyAnnouncementChannel(..modify, position: Modify(position)) +} + +/// Channels without a specified position will automatically be assigned one at the bottom of their category/channel list. +pub fn unset_announcement_channel_position( + modify: ModifyAnnouncementChannel, +) -> ModifyAnnouncementChannel { + ModifyAnnouncementChannel(..modify, position: Delete) +}