From ed62dba859d7b6327d940f1d45d451910a41b9cf Mon Sep 17 00:00:00 2001 From: cyteon Date: Wed, 17 Jul 2024 20:38:25 +0200 Subject: [PATCH] some cleaning --- src/discord_gleam/discord/snowflake.gleam | 30 ----------------------- src/discord_gleam/ws/event_loop.gleam | 12 +++++---- 2 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 src/discord_gleam/discord/snowflake.gleam diff --git a/src/discord_gleam/discord/snowflake.gleam b/src/discord_gleam/discord/snowflake.gleam deleted file mode 100644 index 997abc4..0000000 --- a/src/discord_gleam/discord/snowflake.gleam +++ /dev/null @@ -1,30 +0,0 @@ -import gleam/dynamic -import gleam/int - -pub type Snowflake = - String - -pub fn from_dynamic( - dyn: dynamic.Dynamic, -) -> Result(Snowflake, List(dynamic.DecodeError)) { - case dynamic.classify(dyn) { - "String" -> { - dynamic.string(dyn) - } - "Int" -> { - case dynamic.int(dyn) { - Ok(num) -> Ok(int.to_string(num)) - Error(errors) -> Error(errors) - } - } - // Should be a String or Int, this should not happen - _ -> - Error([ - dynamic.DecodeError( - expected: "String or Int", - found: dynamic.classify(dyn), - path: [], - ), - ]) - } -} diff --git a/src/discord_gleam/ws/event_loop.gleam b/src/discord_gleam/ws/event_loop.gleam index a8df216..4cae92a 100644 --- a/src/discord_gleam/ws/event_loop.gleam +++ b/src/discord_gleam/ws/event_loop.gleam @@ -20,7 +20,7 @@ pub type Msg { } pub type State { - State(has_received_hello: Bool, sequence: Int) + State(has_received_hello: Bool, s: Int) } pub fn main(bot: bot.Bot, event_handlers: List(event_handler.EventHandler)) { @@ -42,7 +42,7 @@ pub fn main(bot: bot.Bot, event_handlers: List(event_handler.EventHandler)) { logging.log(logging.Debug, "Creating builder") - let initial_state = State(has_received_hello: False, sequence: 0) + let initial_state = State(has_received_hello: False, s: 0) let builder = stratus.websocket( request: req, @@ -59,7 +59,7 @@ pub fn main(bot: bot.Bot, event_handlers: List(event_handler.EventHandler)) { let identify = identify.create_packet(bot.token) let _ = stratus.send_text_message(conn, identify) - let new_state = State(has_received_hello: True, sequence: 0) + let new_state = State(has_received_hello: True, s: 0) let heartbeat = hello.string_to_data(msg) @@ -68,7 +68,9 @@ pub fn main(bot: bot.Bot, event_handlers: List(event_handler.EventHandler)) { repeatedly.call(heartbeat, Nil, fn(_state, _count_) { let packet = "{\"op\": 1, \"d\": null, \"s\": " - <> int.to_string(state.sequence) + <> int.to_string(state.s) + // TODO: This is wrong, its always 0??? + // Might be an issue with state cause this is in a process <> "}" logging.log( @@ -88,7 +90,7 @@ pub fn main(bot: bot.Bot, event_handlers: List(event_handler.EventHandler)) { let generic_packet = generic.string_to_data(msg) let new_state = - State(has_received_hello: True, sequence: generic_packet.s) + State(has_received_hello: True, s: generic_packet.s) event_handler.handle_event(bot, msg, event_handlers)