1use crate::bindings::zaun::bot::presence as wit;
16use crate::types::Activity as WitActivity;
17use crate::types::HostError;
18
19pub use crate::types::ActivityType;
20pub use wit::Status;
21
22#[derive(Debug, Clone)]
24pub struct Activity(WitActivity);
25
26impl Activity {
27 fn new(kind: ActivityType, name: impl Into<String>) -> Self {
28 Self(WitActivity {
29 kind,
30 name: name.into(),
31 details: None,
32 state: None,
33 url: None,
34 started_at: None,
35 emoji: None,
36 })
37 }
38
39 pub fn playing(name: impl Into<String>) -> Self {
41 Self::new(ActivityType::Playing, name)
42 }
43
44 pub fn streaming(name: impl Into<String>, url: impl Into<String>) -> Self {
46 let mut a = Self::new(ActivityType::Streaming, name);
47 a.0.url = Some(url.into());
48 a
49 }
50
51 pub fn listening(name: impl Into<String>) -> Self {
53 Self::new(ActivityType::Listening, name)
54 }
55
56 pub fn watching(name: impl Into<String>) -> Self {
58 Self::new(ActivityType::Watching, name)
59 }
60
61 pub fn competing(name: impl Into<String>) -> Self {
63 Self::new(ActivityType::Competing, name)
64 }
65
66 pub fn custom(text: impl Into<String>) -> Self {
68 Self::new(ActivityType::Custom, text)
69 }
70
71 #[must_use]
73 pub fn details(mut self, details: impl Into<String>) -> Self {
74 self.0.details = Some(details.into());
75 self
76 }
77
78 #[must_use]
80 pub fn state(mut self, state: impl Into<String>) -> Self {
81 self.0.state = Some(state.into());
82 self
83 }
84
85 #[must_use]
87 pub fn started_at(mut self, ms: u64) -> Self {
88 self.0.started_at = Some(ms);
89 self
90 }
91
92 #[must_use]
94 pub fn emoji(mut self, emoji: impl Into<String>) -> Self {
95 self.0.emoji = Some(emoji.into());
96 self
97 }
98}
99
100pub fn set(status: Status, activity: impl Into<Option<Activity>>) {
102 wit::set(status, activity.into().as_ref().map(|a| &a.0));
103}
104
105pub fn set_status_text(text: impl Into<String>) -> Result<(), HostError> {
110 wit::set_status_text(Some(&text.into()), None, None)
111}
112
113pub fn set_status(
118 text: Option<&str>,
119 emoji: Option<&str>,
120 expires_at: Option<u64>,
121) -> Result<(), HostError> {
122 wit::set_status_text(text, emoji, expires_at)
123}
124
125pub fn clear_status() -> Result<(), HostError> {
130 wit::set_status_text(None, None, None)
131}