Add a sensible defaults for Identify and its props
This commit is contained in:
parent
94e9af8e8a
commit
5b08ddfcfb
|
@ -1,7 +1,7 @@
|
|||
use crate::types::events::{PresenceUpdate, WebSocketEvent};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct GatewayIdentifyPayload {
|
||||
pub token: String,
|
||||
pub properties: GatewayIdentifyConnectionProps,
|
||||
|
@ -22,6 +22,21 @@ pub struct GatewayIdentifyPayload {
|
|||
pub capabilities: Option<i32>,
|
||||
}
|
||||
|
||||
impl Default for GatewayIdentifyPayload {
|
||||
fn default() -> Self {
|
||||
Self::common()
|
||||
}
|
||||
}
|
||||
|
||||
impl GatewayIdentifyPayload {
|
||||
/// Uses the most common, 25% data along with client capabilities
|
||||
///
|
||||
/// Basically pretends to be an official client on windows 10, with chrome 113.0.0.0
|
||||
pub fn common() -> Self {
|
||||
Self { token: "".to_string(), properties: GatewayIdentifyConnectionProps::default(), compress: Some(false), large_threshold: None, shard: None, presence: None, intents: None, capabilities: Some(8189) }
|
||||
}
|
||||
}
|
||||
|
||||
impl GatewayIdentifyPayload {
|
||||
/// Creates an identify payload with the same default capabilities as the official client
|
||||
pub fn default_w_client_capabilities() -> Self {
|
||||
|
@ -40,9 +55,97 @@ impl GatewayIdentifyPayload {
|
|||
|
||||
impl WebSocketEvent for GatewayIdentifyPayload {}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct GatewayIdentifyConnectionProps {
|
||||
/// Almost always sent
|
||||
///
|
||||
/// ex: "Linux", "Windows"
|
||||
pub os: String,
|
||||
/// Almost always sent
|
||||
///
|
||||
/// ex: "Firefox", "Chrome"
|
||||
pub browser: String,
|
||||
/// Sometimes not sent, acceptable to be ""
|
||||
///
|
||||
/// Speculation:
|
||||
/// Only sent for mobile devices
|
||||
///
|
||||
/// ex: "BlackBerry", "Windows Phone", "Android", "iPhone", "iPad", ""
|
||||
pub device: String,
|
||||
/// Almost always sent, most commonly en-US
|
||||
///
|
||||
/// ex: "en-US"
|
||||
pub system_locale: String,
|
||||
/// Almost always sent
|
||||
///
|
||||
/// ex: any user agent, most common is "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
|
||||
pub browser_user_agent: String,
|
||||
/// Almost always sent
|
||||
///
|
||||
/// ex: "113.0.0.0"
|
||||
pub browser_version: String,
|
||||
/// Sometimes not sent, acceptable to be ""
|
||||
///
|
||||
/// ex: "10" (For os = "Windows")
|
||||
pub os_version: String,
|
||||
/// Sometimes not sent, acceptable to be ""
|
||||
pub referrer: String,
|
||||
/// Sometimes not sent, acceptable to be ""
|
||||
pub referring_domain: String,
|
||||
/// Sometimes not sent, acceptable to be ""
|
||||
pub referrer_current: String,
|
||||
/// Almost always sent, most commonly "stable"
|
||||
pub release_channel: String,
|
||||
/// Almost always sent, identifiable if default is 0, should be around 199933
|
||||
pub client_build_number: u64,
|
||||
//pub client_event_source: Option<?>
|
||||
}
|
||||
|
||||
impl Default for GatewayIdentifyConnectionProps {
|
||||
/// Uses the most common, 25% data
|
||||
fn default() -> Self {
|
||||
Self::common()
|
||||
}
|
||||
}
|
||||
|
||||
impl GatewayIdentifyConnectionProps {
|
||||
|
||||
/// Returns a minimal, least data possible default
|
||||
fn minimal() -> Self {
|
||||
Self {
|
||||
os: "".to_string(),
|
||||
browser: "".to_string(),
|
||||
device: "".to_string(),
|
||||
system_locale: "en-US".to_string(),
|
||||
browser_user_agent: "".to_string(),
|
||||
browser_version: "".to_string(),
|
||||
os_version: "".to_string(),
|
||||
referrer: "".to_string(),
|
||||
referring_domain: "".to_string(),
|
||||
referrer_current: "".to_string(),
|
||||
release_channel: "stable".to_string(),
|
||||
client_build_number: 199933,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the most common connection props so we can't be tracked
|
||||
pub fn common() -> Self {
|
||||
let mut default = Self::default();
|
||||
|
||||
// See https://www.useragents.me/#most-common-desktop-useragents
|
||||
// 25% of the web
|
||||
default.browser_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36".to_string();
|
||||
default.browser = "Chrome".to_string();
|
||||
default.browser_version = "113.0.0.0".to_string();
|
||||
|
||||
default.system_locale = "en-US".to_string();
|
||||
|
||||
default.os = "Windows".to_string();
|
||||
default.os_version = "10".to_string();
|
||||
|
||||
default.client_build_number = 199933;
|
||||
default.release_channel = "stable".to_string();
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue