diff --git a/src/infoops.rs b/src/infoops.rs index 96e1da9..83d2c57 100644 --- a/src/infoops.rs +++ b/src/infoops.rs @@ -16,29 +16,32 @@ pub enum InfoType { /// Sent by the Server to signal the successful creation of a voice channel. CHANNEL_ASSIGN = 1, - - CHANNEL_UPDATE = 2, - /// Sent by the client to signal the destruction of a voice channel. Be it /// a channel being deleted, or all members in it leaving. - CHANNEL_DESTROY = 3, + CHANNEL_DESTROY = 2, /// Sent by the client to create a voice state. - VST_CREATE = 4, + VST_CREATE = 3, + + /// Sent by the server to indicate the success of a VOICE_STATE_CREATE. + /// + /// Has the same fields as VOICE_STATE_CREATE, but with extras. + VST_DONE = 4, /// Sent by the client when a user is leaving a channel OR moving between channels /// in a guild. More on state transitions later on. - VST_UPDATE = 5, + VST_DESTROY= 5, + + /// Sent to update an existing voice state. Potentially unused. + VST_UPDATE = 6, - /// Voice state leave. - VST_LEAVE = 6 } /// Request a channel to be created inside the voice server. /// /// The Server MUST reply back with a CHANNEL_ASSIGN when resources are /// allocated for the channel. -#[derive(Deserialize, Serialize, Clone)] +#[derive(Deserialize, Serialize, Clone, Debug)] pub struct CHANNEL_REQ { /// Channel ID pub channel_id: String, @@ -48,7 +51,7 @@ pub struct CHANNEL_REQ { } /// Sent by the Server to signal the successful creation of a voice channel. -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] pub struct CHANNEL_ASSIGN { /// Channel ID pub channel_id: String, @@ -60,8 +63,21 @@ pub struct CHANNEL_ASSIGN { pub token: String } +/// Sent by the client to create a voice state. +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct VST_CREATE { + /// User ID + pub user_id: String, + + /// Channel ID + pub channel_id: String, + + /// Guild ID, not provided if dm / group dm + pub guild_id: Option +} + /// Info message data -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] #[serde(untagged)] pub enum InfoData { /// Request a channel to be created inside the voice server. @@ -93,16 +109,7 @@ pub enum InfoData { }, /// Sent by the client to create a voice state. - VST_CREATE { - /// User ID - user_id: String, - - /// Channel ID - channel_id: String, - - /// Guild ID, not provided if dm / group dm - guild_id: Option - }, + VST_CREATE(VST_CREATE), /// Sent by the server to indicate the success of a VST_CREATE. VST_DONE { @@ -124,10 +131,15 @@ pub enum InfoData { VST_DESTROY { /// Session ID for the voice state session_id: String + }, + + /// Sent to update an existing voice state. Potentially unused. + VST_UPDATE { + session_id: String } } -pub fn get_infotype(msg: Message) -> Result<(InfoType, InfoData), ()> { +pub async fn get_infotype(msg: Message) -> Result<(InfoType, InfoData), ()> { let message_json: Result = serde_json::from_str( msg.to_text().expect("Failed to convert message to str!") ); diff --git a/src/opcodes.rs b/src/opcodes.rs index 7c41185..996ab83 100644 --- a/src/opcodes.rs +++ b/src/opcodes.rs @@ -19,7 +19,7 @@ use tokio_tungstenite::tungstenite::Message; use crate::infoops::{InfoData, InfoType}; /// Op codes sent/received by Litecord -#[derive(FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq)] +#[derive(FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq, Debug)] #[repr(u8)] pub enum OpCode { /// Sent by the server when a connection is established. @@ -62,7 +62,7 @@ pub enum ErrorCode { } /// Sent by the client to identify itself. -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] pub struct IDENTIFY { /// HMAC SHA256 string of a shared secret and the HELLO nonce pub token: String @@ -71,7 +71,7 @@ pub struct IDENTIFY { /// Sent by either client or a server to send information between each other. /// /// The INFO message is extensible in which many request / response scenarios are laid on. -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] pub struct INFO { /// Info type #[serde(rename = "type")] @@ -82,7 +82,7 @@ pub struct INFO { } /// Message data for the socket -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] #[serde(untagged)] pub enum MessageData { /// Sent by the server when a connection is established.