Sync info ops with documentation

This commit is contained in:
Evie Viau 2022-02-19 19:54:51 -05:00
parent 91be09e4c6
commit 00525cd79b
No known key found for this signature in database
GPG key ID: DBCFB51C41FF87FF
2 changed files with 38 additions and 26 deletions

View file

@ -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<String>
}
/// 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<String>
},
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<Value, serde_json::Error> = serde_json::from_str(
msg.to_text().expect("Failed to convert message to str!")
);

View file

@ -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.