diff --git a/src/api/types.rs b/src/api/types.rs index 00e723d..36e718c 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::from_value; -use serde_aux::field_attributes::deserialize_option_number_from_string; +use serde_aux::{field_attributes::deserialize_option_number_from_string, prelude::deserialize_string_from_number}; use crate::{api::limits::Limits, instance::Instance}; @@ -323,8 +323,8 @@ pub struct RoleObject { #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Hash)] pub struct UserObject { pub id: String, - username: String, - discriminator: String, + username: Option, + discriminator: Option, avatar: Option, bot: Option, system: Option, @@ -335,6 +335,7 @@ pub struct UserObject { email: Option, /// This field comes as either a string or a number as a string /// So we need to account for that + #[serde(default)] #[serde(deserialize_with = "deserialize_option_number_from_string")] flags: Option, premium_since: Option, @@ -401,7 +402,7 @@ pub struct Message { edited_timestamp: Option, tts: bool, mention_everyone: bool, - mentions: Vec, + mentions: Option>, mention_roles: Vec, mention_channels: Option>, pub attachments: Vec, @@ -434,7 +435,7 @@ pub struct MessageCreate { message: Message, guild_id: Option, member: Option, - mentions: Vec, + mentions: Option>, } #[derive(Debug, Serialize, Deserialize, Default)] @@ -513,7 +514,7 @@ pub struct MessageUpdate { message: PartialMessage, guild_id: Option, member: Option, - mentions: Vec<(UserObject, GuildMember)>, // Not sure if this is correct: https://discord.com/developers/docs/topics/gateway-events#message-create + mentions: Option>, // Not sure if this is correct: https://discord.com/developers/docs/topics/gateway-events#message-create } impl WebSocketEvent for MessageUpdate {} @@ -766,7 +767,7 @@ pub struct GuildMember { pub user: Option, pub nick: Option, pub avatar: Option, - pub roles: Vec, + pub roles: Vec, pub joined_at: String, pub premium_since: Option, pub deaf: bool, @@ -829,8 +830,13 @@ pub struct Tag { pub struct PermissionOverwrite { pub id: String, #[serde(rename = "type")] - pub overwrite_type: u8, + #[serde(deserialize_with = "deserialize_string_from_number")] + pub overwrite_type: String, + #[serde(default)] + #[serde(deserialize_with = "deserialize_string_from_number")] pub allow: String, + #[serde(default)] + #[serde(deserialize_with = "deserialize_string_from_number")] pub deny: String, } @@ -1009,7 +1015,7 @@ pub struct GatewayIdentifyConnectionProps { /// See https://discord.com/developers/docs/topics/gateway-events#presence-update-presence-update-event-fields pub struct PresenceUpdate { pub user: UserObject, - pub guild_id: String, + pub guild_id: Option, pub status: String, pub activities: Vec, pub client_status: ClientStatusObject, @@ -1608,7 +1614,7 @@ pub struct MessageACK { } impl WebSocketEvent for MessageACK {} -#[derive(Debug, Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, Clone)] pub struct GatewayPayload { pub op: u8, pub d: Option, diff --git a/src/gateway.rs b/src/gateway.rs index 055cd09..4298788 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -194,10 +194,10 @@ impl Gateway { // Dispatch // An event was dispatched, we need to look at the gateway event name t 0 => { - let gateway_payload_t = gateway_payload.t.unwrap(); + let gateway_payload_t = gateway_payload.clone().t.unwrap(); println!("GW: Received {}..", gateway_payload_t); - + // See https://discord.com/developers/docs/topics/gateway-events#receive-events match gateway_payload_t.as_str() { "READY" => { @@ -387,6 +387,8 @@ impl Gateway { let new_data: PresenceUpdate = serde_json::from_value(gateway_payload.d.unwrap()).unwrap(); self.events.lock().await.user.presence_update.update_data(new_data).await; } + // What is this? + "PASSIVE_UPDATE_V1" => {} "STAGE_INSTANCE_CREATE" => {} "STAGE_INSTANCE_UPDATE" => {} "STAGE_INSTANCE_DELETE" => {} @@ -408,7 +410,10 @@ impl Gateway { let new_data: WebhooksUpdate = serde_json::from_value(gateway_payload.d.unwrap()).unwrap(); self.events.lock().await.webhooks.update.update_data(new_data).await; } - _ => {panic!("Invalid gateway event ({})", &gateway_payload_t)} + _ => { + //panic!("Invalid gateway event ({})", &gateway_payload_t) + println!("New gateway event ({})", &gateway_payload_t); + } } } // Heartbeat @@ -429,7 +434,7 @@ impl Gateway { println!("GW: Received Heartbeat ACK"); } 2 | 3 | 4 | 6 | 8 => {panic!("Received Gateway op code that's meant to be sent, not received ({})", gateway_payload.op)} - _ => {panic!("Received Invalid Gateway op code ({})", gateway_payload.op)} + _ => {println!("Received new Gateway op code ({})", gateway_payload.op)} } // If we have an active heartbeat thread and we received a seq number we should let it know