Skip to content

Commit

Permalink
convert all to snowflakes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyteon committed Jul 24, 2024
1 parent b3b3c92 commit c3051a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/discord_gleam/ws/packets/message.gleam
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import discord_gleam/discord/snowflake.{type Snowflake}
import gleam/dynamic
import gleam/json
import gleam/result

pub type MessageAuthor {
MessageAuthor(id: String, username: String)
MessageAuthor(id: Snowflake, username: String)
}

pub type MessagePacketData {
MessagePacketData(
content: String,
guild_id: String,
channel_id: String,
author: MessageAuthor,
id: String,
guild_id: Snowflake,
channel_id: Snowflake,
author: MessageAuthor,
)
}

Expand All @@ -32,17 +33,17 @@ pub fn string_to_data(encoded: String) -> Result(MessagePacket, String) {
of: dynamic.decode5(
MessagePacketData,
dynamic.field("content", of: dynamic.string),
dynamic.field("guild_id", of: dynamic.string),
dynamic.field("channel_id", of: dynamic.string),
dynamic.field("id", of: snowflake.from_dynamic),
dynamic.field("guild_id", of: snowflake.from_dynamic),
dynamic.field("channel_id", of: snowflake.from_dynamic),
dynamic.field(
"author",
of: dynamic.decode2(
MessageAuthor,
dynamic.field("id", of: dynamic.string),
dynamic.field("id", of: snowflake.from_dynamic),
dynamic.field("username", of: dynamic.string),
),
),
dynamic.field("id", of: dynamic.string),
),
),
)
Expand Down
13 changes: 9 additions & 4 deletions src/discord_gleam/ws/packets/message_delete.gleam
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import discord_gleam/discord/snowflake.{type Snowflake}
import gleam/dynamic
import gleam/json
import gleam/result

pub type MessageDeletePacketData {
MessageDeletePacketData(id: String, guild_id: String, channel_id: String)
MessageDeletePacketData(
id: Snowflake,
guild_id: Snowflake,
channel_id: Snowflake,
)
}

pub type MessageDeletePacket {
Expand All @@ -21,9 +26,9 @@ pub fn string_to_data(encoded: String) -> Result(MessageDeletePacket, String) {
"d",
of: dynamic.decode3(
MessageDeletePacketData,
dynamic.field("id", of: dynamic.string),
dynamic.field("guild_id", of: dynamic.string),
dynamic.field("channel_id", of: dynamic.string),
dynamic.field("id", of: snowflake.from_dynamic),
dynamic.field("guild_id", of: snowflake.from_dynamic),
dynamic.field("channel_id", of: snowflake.from_dynamic),
),
),
)
Expand Down
5 changes: 3 additions & 2 deletions src/discord_gleam/ws/packets/ready.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import discord_gleam/discord/snowflake.{type Snowflake}
import gleam/dynamic
import gleam/json
import gleam/result
import logging

pub type ReadyUser {
ReadyUser(username: String, id: String, discriminator: String, bot: Bool)
ReadyUser(username: String, id: Snowflake, discriminator: String, bot: Bool)
}

pub type ReadyData {
Expand Down Expand Up @@ -32,7 +33,7 @@ pub fn string_to_data(encoded: String) -> Result(ReadyPacket, String) {
of: dynamic.decode4(
ReadyUser,
dynamic.field("username", of: dynamic.string),
dynamic.field("id", of: dynamic.string),
dynamic.field("id", of: snowflake.from_dynamic),
dynamic.field("discriminator", of: dynamic.string),
dynamic.field("bot", of: dynamic.bool),
),
Expand Down

0 comments on commit c3051a9

Please sign in to comment.