A Discord API Library for Gleam! 💫

message get pinned function

+40 -3
+25 -2
src/flybycord/message.gleam
··· 1 1 import flybycord/application.{type Application} 2 2 import flybycord/channel.{type Channel} 3 + import flybycord/client.{type Client} 4 + import flybycord/error 3 5 import flybycord/guild/role.{type Role} 4 6 import flybycord/internal/flags 7 + import flybycord/internal/rest 5 8 import flybycord/internal/time_rfc3339 6 9 import flybycord/message/activity.{type Activity} 7 10 import flybycord/message/attachment.{type Attachment} ··· 16 19 import flybycord/sticker 17 20 import flybycord/user.{type User} 18 21 import gleam/dynamic/decode 22 + import gleam/http 19 23 import gleam/int 24 + import gleam/json 20 25 import gleam/option.{type Option, None} 26 + import gleam/result 21 27 import gleam/time/timestamp.{type Timestamp} 22 28 23 29 // TYPES ----------------------------------------------------------------------- ··· 171 177 // DECODERS -------------------------------------------------------------------- 172 178 173 179 @internal 174 - pub fn message_decoder() -> decode.Decoder(Message) { 180 + pub fn decoder() -> decode.Decoder(Message) { 175 181 use id <- decode.field("id", decode.string) 176 182 use channel_id <- decode.field("channel_id", decode.string) 177 183 use author <- decode.field("author", user.decoder()) ··· 248 254 use refrenced_message <- decode.optional_field( 249 255 "refrenced_message", 250 256 None, 251 - decode.optional(message_decoder()), 257 + decode.optional(decoder()), 252 258 ) 253 259 use interaction_metadata <- decode.optional_field( 254 260 "interaction_metadata", ··· 462 468 is_renewal:, 463 469 )) 464 470 } 471 + 472 + // PUBLIC API FUNCTIONS -------------------------------------------------------- 473 + 474 + pub fn get_pinned( 475 + client: Client, 476 + in channel_id: String, 477 + ) -> Result(List(Message), error.FlybycordError) { 478 + use response <- result.try( 479 + client 480 + |> rest.new_request(http.Get, "/channels/" <> channel_id <> "/pins") 481 + |> rest.execute, 482 + ) 483 + 484 + response.body 485 + |> json.parse(using: decode.list(decoder())) 486 + |> result.map_error(error.DecodeError) 487 + }
+15 -1
src/flybycord/message/resolved.gleam
··· 25 25 PartialChannel( 26 26 id: String, 27 27 name: String, 28 - type_: channel.Type, 28 + type_: Type, 29 29 permissions: List(Permission), 30 30 ) 31 31 PartialThread( ··· 36 36 metadata: thread.Metadata, 37 37 parent_id: String, 38 38 ) 39 + } 40 + 41 + pub type Type { 42 + GuildTextChannel 43 + DmChannel 44 + GuildVoiceChannel 45 + GuildCategoryChannel 46 + GuildAnnouncementChannel 47 + AnnouncementThreadChannel 48 + PublicThreadChannel 49 + PrivateThreadChannel 50 + GuildStageVoiceChannel 51 + GuildForumChannel 52 + GuildMediaChannel 39 53 } 40 54 41 55 // DECODERS --------------------------------------------------------------------