tangled
alpha
login
or
join now
folospior.dev
/
grom
0
fork
atom
A Discord API Library for Gleam! 💫
0
fork
atom
overview
issues
pulls
pipelines
message get pinned function
folospior.dev
10 months ago
d098f26f
1e26d45f
+40
-3
2 changed files
expand all
collapse all
unified
split
src
flybycord
message
resolved.gleam
message.gleam
+25
-2
src/flybycord/message.gleam
···
1
1
import flybycord/application.{type Application}
2
2
import flybycord/channel.{type Channel}
3
3
+
import flybycord/client.{type Client}
4
4
+
import flybycord/error
3
5
import flybycord/guild/role.{type Role}
4
6
import flybycord/internal/flags
7
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
22
+
import gleam/http
19
23
import gleam/int
24
24
+
import gleam/json
20
25
import gleam/option.{type Option, None}
26
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
174
-
pub fn message_decoder() -> decode.Decoder(Message) {
180
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
251
-
decode.optional(message_decoder()),
257
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
471
+
472
472
+
// PUBLIC API FUNCTIONS --------------------------------------------------------
473
473
+
474
474
+
pub fn get_pinned(
475
475
+
client: Client,
476
476
+
in channel_id: String,
477
477
+
) -> Result(List(Message), error.FlybycordError) {
478
478
+
use response <- result.try(
479
479
+
client
480
480
+
|> rest.new_request(http.Get, "/channels/" <> channel_id <> "/pins")
481
481
+
|> rest.execute,
482
482
+
)
483
483
+
484
484
+
response.body
485
485
+
|> json.parse(using: decode.list(decoder()))
486
486
+
|> result.map_error(error.DecodeError)
487
487
+
}
+15
-1
src/flybycord/message/resolved.gleam
···
25
25
PartialChannel(
26
26
id: String,
27
27
name: String,
28
28
-
type_: channel.Type,
28
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
39
+
}
40
40
+
41
41
+
pub type Type {
42
42
+
GuildTextChannel
43
43
+
DmChannel
44
44
+
GuildVoiceChannel
45
45
+
GuildCategoryChannel
46
46
+
GuildAnnouncementChannel
47
47
+
AnnouncementThreadChannel
48
48
+
PublicThreadChannel
49
49
+
PrivateThreadChannel
50
50
+
GuildStageVoiceChannel
51
51
+
GuildForumChannel
52
52
+
GuildMediaChannel
39
53
}
40
54
41
55
// DECODERS --------------------------------------------------------------------