A Discord API Library for Gleam! 💫
0

Configure Feed

Select the types of activity you want to include in your feed.

add some fields to invites

+75
+75
src/grom/invite.gleam
··· 3 3 import gleam/dynamic/decode 4 4 import gleam/http 5 5 import gleam/http/request 6 + import gleam/int 6 7 import gleam/json.{type Json} 7 8 import gleam/list 8 9 import gleam/option.{type Option, None, Some} ··· 14 15 import grom/application.{type Application} 15 16 import grom/channel.{type Channel} 16 17 import grom/guild.{type Guild} 18 + import grom/guild/role 19 + import grom/internal/flags 17 20 import grom/internal/rest 18 21 import grom/internal/time_duration 19 22 import grom/internal/time_rfc3339 ··· 40 43 approximate_presence_count: Option(Int), 41 44 approximate_member_count: Option(Int), 42 45 expires_at: Option(Timestamp), 46 + flags: Option(List(Flag)), 47 + roles: Option(List(PartialRole)), 43 48 ) 44 49 } 45 50 51 + pub type PartialRole { 52 + PartialRole( 53 + id: String, 54 + name: String, 55 + position: Int, 56 + colors: role.Colors, 57 + icon_hash: Option(String), 58 + unicode_emoji: Option(String), 59 + ) 60 + } 61 + 62 + fn partial_role_decoder() -> decode.Decoder(PartialRole) { 63 + use id <- decode.field("id", decode.string) 64 + use name <- decode.field("name", decode.string) 65 + use position <- decode.field("position", decode.int) 66 + use colors <- decode.field("colors", role.colors_decoder()) 67 + use icon_hash <- decode.optional_field( 68 + "icon", 69 + None, 70 + decode.optional(decode.string), 71 + ) 72 + use unicode_emoji <- decode.optional_field( 73 + "unicode_emoji", 74 + None, 75 + decode.optional(decode.string), 76 + ) 77 + decode.success(PartialRole( 78 + id:, 79 + name:, 80 + position:, 81 + colors:, 82 + icon_hash:, 83 + unicode_emoji:, 84 + )) 85 + } 86 + 46 87 pub type WithMetadata { 47 88 WithMetadata( 48 89 type_: Type, ··· 59 100 max_age: Duration, 60 101 is_temporary: Bool, 61 102 created_at: Timestamp, 103 + flags: Option(List(Flag)), 104 + roles: Option(List(PartialRole)), 62 105 ) 106 + } 107 + 108 + pub type Flag { 109 + IsGuestInvite 110 + } 111 + 112 + fn bits_flags() -> List(#(Int, Flag)) { 113 + [#(int.bitwise_shift_left(1, 0), IsGuestInvite)] 63 114 } 64 115 65 116 pub type Create { ··· 183 234 None, 184 235 decode.optional(time_rfc3339.decoder()), 185 236 ) 237 + use flags <- decode.optional_field( 238 + "flags", 239 + None, 240 + decode.optional(flags.decoder(bits_flags())), 241 + ) 242 + use roles <- decode.optional_field( 243 + "roles", 244 + None, 245 + decode.optional(decode.list(of: partial_role_decoder())), 246 + ) 186 247 decode.success(WithoutMetadata( 187 248 type_:, 188 249 code:, ··· 193 254 approximate_presence_count:, 194 255 approximate_member_count:, 195 256 expires_at:, 257 + flags:, 258 + roles:, 196 259 )) 197 260 } 198 261 ··· 281 344 ) 282 345 use is_temporary <- decode.field("temporary", decode.bool) 283 346 use created_at <- decode.field("created_at", time_rfc3339.decoder()) 347 + use flags <- decode.optional_field( 348 + "flags", 349 + None, 350 + decode.optional(flags.decoder(bits_flags())), 351 + ) 352 + use roles <- decode.optional_field( 353 + "roles", 354 + None, 355 + decode.optional(decode.list(of: partial_role_decoder())), 356 + ) 284 357 285 358 decode.success(WithMetadata( 286 359 type_:, ··· 297 370 max_age:, 298 371 is_temporary:, 299 372 created_at:, 373 + flags:, 374 + roles:, 300 375 )) 301 376 } 302 377