twilight_model/gateway/payload/outgoing/
identify.rs

1use super::update_presence::UpdatePresencePayload;
2use crate::gateway::{intents::Intents, opcode::OpCode, ShardId};
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
6pub struct Identify {
7    pub d: IdentifyInfo,
8    pub op: OpCode,
9}
10
11impl Identify {
12    pub const fn new(info: IdentifyInfo) -> Self {
13        Self {
14            d: info,
15            op: OpCode::Identify,
16        }
17    }
18}
19
20#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
21pub struct IdentifyInfo {
22    pub compress: bool,
23    pub intents: Intents,
24    pub large_threshold: u64,
25    pub presence: Option<UpdatePresencePayload>,
26    pub properties: IdentifyProperties,
27    pub shard: Option<ShardId>,
28    pub token: String,
29}
30
31#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
32pub struct IdentifyProperties {
33    pub browser: String,
34    pub device: String,
35    pub os: String,
36}
37
38impl IdentifyProperties {
39    pub fn new(
40        browser: impl Into<String>,
41        device: impl Into<String>,
42        os: impl Into<String>,
43    ) -> Self {
44        Self {
45            browser: browser.into(),
46            device: device.into(),
47            os: os.into(),
48        }
49    }
50}