use std::process::id as pid; use models::prelude::Command; #[derive(Debug, Default, Serialize)] pub struct SetActivityArgs { pub pid: u32, pub activity: SetActivity, } impl SetActivityArgs { pub fn command(args: SetActivity) -> Command { Command::new("SET_ACTIVITY", Self { pid: pid(), activity: args }) } } #[derive(Debug, Default, Serialize)] pub struct SetActivity { #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(skip_serializing_if = "Option::is_none")] pub details: Option, #[serde(skip_serializing_if = "Option::is_none")] pub instance: Option, #[serde(skip_serializing_if = "Option::is_none")] pub timestamps: Option, #[serde(skip_serializing_if = "Option::is_none")] pub assets: Option, #[serde(skip_serializing_if = "Option::is_none")] pub party: Option, #[serde(skip_serializing_if = "Option::is_none")] pub secrets: Option, } impl SetActivity { pub fn new() -> Self { Self::default() } pub fn state(mut self, s: S) -> Self where S: Into { self.state = Some(s.into()); self } pub fn details(mut self, d: S) -> Self where S: Into { self.details = Some(d.into()); self } pub fn instance(mut self, i: bool) -> Self { self.instance = Some(i); self } pub fn timestamps(mut self, f: F) -> Self where F: FnOnce(ActivityTimestamps) -> ActivityTimestamps { self.timestamps = Some(f(ActivityTimestamps::default())); self } pub fn assets(mut self, f: F) -> Self where F: FnOnce(ActivityAssets) -> ActivityAssets { self.assets = Some(f(ActivityAssets::default())); self } pub fn party(mut self, f: F) -> Self where F: FnOnce(ActivityParty) -> ActivityParty { self.party = Some(f(ActivityParty::default())); self } pub fn secrets(mut self, f: F) -> Self where F: FnOnce(ActivitySecrets) -> ActivitySecrets { self.secrets = Some(f(ActivitySecrets::default())); self } } #[derive(Debug, Default, Serialize)] pub struct ActivityTimestamps { #[serde(skip_serializing_if = "Option::is_none")] pub start: Option, #[serde(skip_serializing_if = "Option::is_none")] pub end: Option, } impl ActivityTimestamps { pub fn start(mut self, i: u32) -> Self { self.start = Some(i); self } pub fn end(mut self, i: u32) -> Self { self.end = Some(i); self } } #[derive(Debug, Default, Serialize)] pub struct ActivityAssets { #[serde(skip_serializing_if = "Option::is_none")] pub large_image: Option, #[serde(skip_serializing_if = "Option::is_none")] pub large_text: Option, #[serde(skip_serializing_if = "Option::is_none")] pub small_image: Option, #[serde(skip_serializing_if = "Option::is_none")] pub small_text: Option, } impl ActivityAssets { pub fn large_image(mut self, i: S) -> Self where S: Into { self.large_image = Some(i.into()); self } pub fn large_text(mut self, t: S) -> Self where S: Into { self.large_text = Some(t.into()); self } pub fn small_image(mut self, i: S) -> Self where S: Into { self.small_image = Some(i.into()); self } pub fn small_text(mut self, t: S) -> Self where S: Into { self.small_text = Some(t.into()); self } } #[derive(Debug, Default, Serialize)] pub struct ActivityParty { #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub size: Option<[u32; 2]>, } impl ActivityParty { pub fn id(mut self, i: u32) -> Self { self.id = Some(i); self } pub fn size(mut self, current: u32, max: u32) -> Self { self.size = Some([current, max]); self } } #[derive(Debug, Default, Serialize)] pub struct ActivitySecrets { #[serde(skip_serializing_if = "Option::is_none")] pub join: Option, #[serde(skip_serializing_if = "Option::is_none")] pub spectate: Option, // NOTE: think of a better name for this #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "match")] pub shoubu: Option, } impl ActivitySecrets { pub fn join(mut self, secret: S) -> Self where S: Into { self.join = Some(secret.into()); self } pub fn spectate(mut self, secret: S) -> Self where S: Into { self.spectate = Some(secret.into()); self } pub fn game(mut self, secret: S) -> Self where S: Into { self.shoubu = Some(secret.into()); self } }