From 5945d725ac9e5aa4630a793b7f1ef146d96e730a Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Sat, 14 Jun 2025 17:20:46 +0200 Subject: [PATCH] switching distros --- flake.lock | 6 +- flake.nix | 1 - src/grom/channel.gleam | 104 ++++++++++---------- src/grom/channel/permission_overwrite.gleam | 32 +++--- 4 files changed, 71 insertions(+), 72 deletions(-) diff --git a/flake.lock b/flake.lock index 46fc6ce..46db729 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1748929857, - "narHash": "sha256-lcZQ8RhsmhsK8u7LIFsJhsLh/pzR9yZ8yqpTzyGdj+Q=", + "lastModified": 1749794982, + "narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c2a03962b8e24e669fb37b7df10e7c79531ff1a4", + "rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ed8e604..a8dada2 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,6 @@ { inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; outputs = { - self, nixpkgs, ... }: let diff --git a/src/grom/channel.gleam b/src/grom/channel.gleam index 12195d4..0ef8ac3 100644 --- a/src/grom/channel.gleam +++ b/src/grom/channel.gleam @@ -1396,58 +1396,6 @@ pub fn get(client: Client, id channel_id: String) -> Result(Channel, Error) { |> result.map_error(error.CouldNotDecode) } -pub fn delete( - client: Client, - id channel_id: String, - reason reason: Option(String), -) -> Result(Channel, Error) { - use response <- result.try( - client - |> rest.new_request(http.Delete, "/channels/" <> channel_id) - |> rest.with_reason(reason) - |> rest.execute, - ) - - response.body - |> json.parse(using: decoder()) - |> result.map_error(error.CouldNotDecode) -} - -pub fn announcement_follow( - client: Client, - from channel_id: String, - to webhook_channel_id: String, - reason reason: Option(String), -) -> Result(FollowedChannel, Error) { - let json = - json.object([#("webhook_channel_id", json.string(webhook_channel_id))]) - - use response <- result.try( - client - |> rest.new_request(http.Post, "/channels/" <> channel_id <> "/followers") - |> rest.with_reason(reason) - |> request.set_body(json |> json.to_string) - |> rest.execute, - ) - - response.body - |> json.parse(using: followed_channel_decoder()) - |> result.map_error(error.CouldNotDecode) -} - -pub fn trigger_typing_indicator( - client: Client, - in channel_id: String, -) -> Result(Nil, Error) { - use _response <- result.try( - client - |> rest.new_request(http.Post, "/channels/" <> channel_id <> "/typing") - |> rest.execute, - ) - - Ok(Nil) -} - pub fn modify( client: Client, id channel_id: String, @@ -1855,3 +1803,55 @@ pub fn modify_thread_applied_tags_ids( _ -> modify } } + +pub fn delete( + client: Client, + id channel_id: String, + because reason: Option(String), +) -> Result(Channel, Error) { + use response <- result.try( + client + |> rest.new_request(http.Delete, "/channels/" <> channel_id) + |> rest.with_reason(reason) + |> rest.execute, + ) + + response.body + |> json.parse(using: decoder()) + |> result.map_error(error.CouldNotDecode) +} + +pub fn announcement_follow( + client: Client, + from channel_id: String, + to webhook_channel_id: String, + because reason: Option(String), +) -> Result(FollowedChannel, Error) { + let json = + json.object([#("webhook_channel_id", json.string(webhook_channel_id))]) + + use response <- result.try( + client + |> rest.new_request(http.Post, "/channels/" <> channel_id <> "/followers") + |> rest.with_reason(reason) + |> request.set_body(json |> json.to_string) + |> rest.execute, + ) + + response.body + |> json.parse(using: followed_channel_decoder()) + |> result.map_error(error.CouldNotDecode) +} + +pub fn trigger_typing_indicator( + client: Client, + in channel_id: String, +) -> Result(Nil, Error) { + use _response <- result.try( + client + |> rest.new_request(http.Post, "/channels/" <> channel_id <> "/typing") + |> rest.execute, + ) + + Ok(Nil) +} diff --git a/src/grom/channel/permission_overwrite.gleam b/src/grom/channel/permission_overwrite.gleam index 0a4ed8f..1f80048 100644 --- a/src/grom/channel/permission_overwrite.gleam +++ b/src/grom/channel/permission_overwrite.gleam @@ -5,7 +5,7 @@ import gleam/json.{type Json} import gleam/option.{type Option} import gleam/result import grom/client.{type Client} -import grom/error +import grom/error.{type Error} import grom/internal/rest import grom/permission.{type Permission} @@ -29,8 +29,8 @@ pub type Create { } pub type Type { - Role - Member + ForRole + ForMember } // DECODERS -------------------------------------------------------------------- @@ -48,28 +48,28 @@ pub fn decoder() -> decode.Decoder(PermissionOverwrite) { pub fn type_decoder() -> decode.Decoder(Type) { use variant <- decode.then(decode.int) case variant { - 0 -> decode.success(Role) - 1 -> decode.success(Member) - _ -> decode.failure(Role, "Type") + 0 -> decode.success(ForRole) + 1 -> decode.success(ForMember) + _ -> decode.failure(ForRole, "Type") } } // ENCODERS -------------------------------------------------------------------- @internal -pub fn create_encode(create: Create) -> Json { +pub fn create_to_json(create: Create) -> Json { json.object([ - #("type", type_encode(create.type_)), + #("type", type_to_json(create.type_)), #("allow", json.nullable(create.allow, permission.encode)), #("deny", json.nullable(create.deny, permission.encode)), ]) } @internal -pub fn type_encode(type_: Type) -> Json { +pub fn type_to_json(type_: Type) -> Json { case type_ { - Role -> 0 - Member -> 1 + ForRole -> 0 + ForMember -> 1 } |> json.int } @@ -81,9 +81,9 @@ pub fn edit( for channel_id: String, id overwrite_id: String, new overwrite: Create, - reason reason: Option(String), -) -> Result(Nil, error.Error) { - let json = overwrite |> create_encode + because reason: Option(String), +) -> Result(Nil, Error) { + let json = overwrite |> create_to_json use _response <- result.try( client @@ -103,8 +103,8 @@ pub fn delete( client: Client, for channel_id: String, id overwrite_id: String, - reason reason: Option(String), -) -> Result(Nil, error.Error) { + because reason: Option(String), +) -> Result(Nil, Error) { use _response <- result.try( client |> rest.new_request( -- 2.51.2