Add Voice StateUpdate and ServerUpdate events

This commit is contained in:
kozabrada123 2023-05-22 18:42:12 +02:00
parent 27ff0116d6
commit c56dc42cd7
2 changed files with 50 additions and 10 deletions

View File

@ -1232,15 +1232,42 @@ pub struct ClientInfo {
impl WebSocketEvent for SessionsReplace {}
#[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 {
/// See https://discord.com/developers/docs/topics/gateway-events#update-voice-state
///
/// Sent to the server
///
/// Not to be confused with [VoiceStateUpdate]
pub struct UpdateVoiceState {
pub guild_id: String,
pub channel_id: Option<String>,
pub self_mute: bool,
pub self_deaf: bool,
}
impl WebSocketEvent for GatewayVoiceStateUpdate {}
impl WebSocketEvent for UpdateVoiceState {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-state-update
///
/// Received from the server
///
/// Not to be confused with [UpdateVoiceState]
pub struct VoiceStateUpdate {
#[serde(flatten)]
pub state: VoiceState
}
impl WebSocketEvent for VoiceStateUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-server-update
pub struct VoiceServerUpdate {
pub token: String,
pub guild_id: String,
pub endpoint: Option<String>
}
impl WebSocketEvent for VoiceServerUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#webhooks-update

View File

@ -74,7 +74,7 @@ impl GatewayHandle {
self.send_json_event(3, to_send_value).await;
}
/// Sends a Request Guild Members to the server
/// 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();
@ -84,17 +84,17 @@ impl GatewayHandle {
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) {
/// Sends an update voice state to the server
pub async fn send_update_voice_state(&self, to_send: UpdateVoiceState) {
let to_send_value = serde_json::to_value(&to_send).unwrap();
println!("GW: Sending Voice State Update..");
println!("GW: Sending Update Voice State..");
self.send_json_event(4, to_send_value).await;
}
/// Sends a Call Sync
/// Sends a call sync to the server
pub async fn send_call_sync(&self, to_send: CallSync) {
let to_send_value = serde_json::to_value(&to_send).unwrap();
@ -439,8 +439,14 @@ impl Gateway {
let new_data: UserUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap();
self.events.lock().await.user.update.update_data(new_data).await;
}
"VOICE_STATE_UPDATE" => {}
"VOICE_SERVER_UPDATE" => {}
"VOICE_STATE_UPDATE" => {
let new_data: VoiceStateUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap();
self.events.lock().await.voice.state_update.update_data(new_data).await;
}
"VOICE_SERVER_UPDATE" => {
let new_data: VoiceServerUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap();
self.events.lock().await.voice.server_update.update_data(new_data).await;
}
"WEBHOOKS_UPDATE" => {
let new_data: WebhooksUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap();
self.events.lock().await.webhooks.update.update_data(new_data).await;
@ -643,6 +649,7 @@ mod events {
pub invite: Invite,
pub integration: Integration,
pub call: Call,
pub voice: Voice,
pub webhooks: Webhooks,
pub gateway_identify_payload: GatewayEvent<GatewayIdentifyPayload>,
pub gateway_resume: GatewayEvent<GatewayResume>,
@ -740,6 +747,12 @@ mod events {
pub delete: GatewayEvent<CallDelete>
}
#[derive(Default, Debug)]
pub struct Voice {
pub state_update: GatewayEvent<VoiceStateUpdate>,
pub server_update: GatewayEvent<VoiceServerUpdate>
}
#[derive(Default, Debug)]
pub struct Webhooks {
pub update: GatewayEvent<WebhooksUpdate>,