use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Identify {
pub token: String,
pub properties: ConnectionProperties,
#[serde(skip_serializing_if = "Option::is_none")]
pub presence: Option<PresenceUpdate>,
pub compress: Option<bool>,
pub capabilities: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub intents: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionProperties {
#[serde(rename = "$os")]
pub os: String,
#[serde(rename = "$browser")]
pub browser: String,
#[serde(rename = "$device")]
pub device: String,
#[serde(rename = "$system_locale")]
pub system_locale: String,
#[serde(rename = "$browser_version")]
pub browser_version: String,
#[serde(rename = "$os_version")]
pub os_version: String,
#[serde(rename = "$referrer")]
pub referrer: String,
#[serde(rename = "$referring_domain")]
pub referring_domain: String,
#[serde(rename = "$release_channel")]
pub release_channel: String,
#[serde(rename = "$client_build_number")]
pub client_build_number: u32,
}
impl ConnectionProperties {
pub fn default_client() -> Self {
Self {
os: "Mac OS X".to_string(),
browser: "Discord Client".to_string(),
device: "".to_string(),
system_locale: "en-US".to_string(),
browser_version: "1.135.0".to_string(),
os_version: "26.3.0".to_string(),
referrer: "".to_string(),
referring_domain: "".to_string(),
release_channel: "stable".to_string(),
client_build_number: 500334,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PresenceUpdate {
pub status: String,
pub since: Option<u64>,
pub activities: Vec<Activity>,
pub afk: bool,
}
impl Default for PresenceUpdate {
fn default() -> Self {
Self {
status: "online".to_string(),
since: None,
activities: vec![],
afk: false,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Activity {
pub name: String,
#[serde(rename = "type")]
pub kind: u8,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
}
impl Identify {
pub fn new(token: impl Into<String>) -> Self {
let intents = 3276799;
Self {
token: token.into(),
properties: ConnectionProperties::default_client(),
presence: Some(PresenceUpdate::default()),
compress: Some(false),
capabilities: 16381, intents: Some(intents),
}
}
}