diff --git a/src/flybycord/channel.gleam b/src/flybycord/channel.gleam index 504df3b..0f48885 100644 --- a/src/flybycord/channel.gleam +++ b/src/flybycord/channel.gleam @@ -147,21 +147,3 @@ pub fn get(client: Client, id channel_id: String) { |> json.parse(using: decoder()) |> result.map_error(error.DecodeError) } - -pub fn create_dm( - client: Client, - to recipient_id: String, -) -> Result(Channel, error.FlybycordError) { - let json = json.object([#("recipient_id", json.string(recipient_id))]) - - use response <- result.try( - client - |> rest.new_request(http.Post, "/users/@me/channels") - |> request.set_body(json |> json.to_string) - |> rest.execute, - ) - - response.body - |> json.parse(using: decoder()) - |> result.map_error(error.DecodeError) -} diff --git a/src/flybycord/channel/user/dm.gleam b/src/flybycord/channel/user/dm.gleam index 8c3e4f4..8290f19 100644 --- a/src/flybycord/channel/user/dm.gleam +++ b/src/flybycord/channel/user/dm.gleam @@ -1,7 +1,14 @@ +import flybycord/client.{type Client} +import flybycord/error +import flybycord/internal/rest import flybycord/permission.{type Permission} import flybycord/user.{type User} import gleam/dynamic/decode +import gleam/http +import gleam/http/request +import gleam/json import gleam/option.{type Option, None} +import gleam/result // TYPES ----------------------------------------------------------------------- @@ -36,3 +43,23 @@ pub fn channel_decoder() { current_user_permissions:, )) } + +// PUBLIC API FUNCTIONS -------------------------------------------------------- + +pub fn create( + client: Client, + to recipient_id: String, +) -> Result(Channel, error.FlybycordError) { + let json = json.object([#("recipient_id", json.string(recipient_id))]) + + use response <- result.try( + client + |> rest.new_request(http.Post, "/users/@me/channels") + |> request.set_body(json |> json.to_string) + |> rest.execute, + ) + + response.body + |> json.parse(using: channel_decoder()) + |> result.map_error(error.DecodeError) +}