From 11d371eee2993380ab542657baa1fe847c911aac Mon Sep 17 00:00:00 2001 From: kozabrada123 <“kozabrada123@users.noreply.github.com”> Date: Sat, 13 May 2023 15:59:46 +0200 Subject: [PATCH] Add rest of send events --- src/api/types.rs | 24 ++++++++++++++++++++++++ src/gateway.rs | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/api/types.rs b/src/api/types.rs index c91f53f..784cb73 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -803,6 +803,30 @@ pub struct GatewayReady { impl WebSocketEvent for GatewayReady {} +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://discord.com/developers/docs/topics/gateway-events#request-guild-members-request-guild-members-structure +pub struct GatewayRequestGuildMembers { + pub guild_id: String, + pub query: Option, + pub limit: u64, + pub presence: Option, + pub user_ids: Option, + pub nonce: Option, +} + +impl WebSocketEvent for GatewayRequestGuildMembers {} + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://discord.com/developers/docs/topics/gateway-events#update-voice-state-gateway-voice-state-update-structure +pub struct GatewayVoiceStateUpdate { + pub guild_id: String, + pub channel_id: Option, + pub self_mute: bool, + pub self_deaf: bool, +} + +impl WebSocketEvent for GatewayVoiceStateUpdate {} + #[derive(Debug, Default, Deserialize, Serialize)] pub struct GatewayHello { pub op: i32, diff --git a/src/gateway.rs b/src/gateway.rs index 1996ff1..964ac01 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -69,8 +69,30 @@ impl GatewayHandle { let to_send_value = serde_json::to_value(&to_send).unwrap(); + println!("GW: Sending Presence Update.."); + self.send_json_event(3, to_send_value).await; } + + /// Sends a Request Guild Members to the server + pub async fn send_request_guild_members(&self, to_send: GatewayRequestGuildMembers) { + + let to_send_value = serde_json::to_value(&to_send).unwrap(); + + println!("GW: Sending Request Guild Members.."); + + self.send_json_event(8, to_send_value).await; + } + + /// Sends a Request Guild Members to the server + pub async fn send_update_voice_state(&self, to_send: GatewayVoiceStateUpdate) { + + let to_send_value = serde_json::to_value(&to_send).unwrap(); + + println!("GW: Sending Voice State Update.."); + + self.send_json_event(4, to_send_value).await; + } } pub struct Gateway {