-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimed.rs
More file actions
62 lines (48 loc) · 1.6 KB
/
Copy pathtimed.rs
File metadata and controls
62 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{
sync::{
Arc,
atomic::{AtomicUsize, Ordering},
},
time::Duration,
};
use filthy_rich::{PresenceRunner, errors::PresenceError, types::Activity};
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), PresenceError> {
// simple atomic counter
let count = Arc::new(AtomicUsize::new(0));
let mut runner = PresenceRunner::new("1463450870480900160")
.on_ready(|data| println!("Connected to user: {}", data.user.username()))
.on_activity_send(move |_| {
// increments the counter with every send_activity()
let val = count.fetch_add(1, Ordering::Relaxed) + 1;
println!("Activity {val} sent successfully.")
})
.show_errors() // enables verbose error logging
;
// create activities for later use
let activity_1 = Activity::new()
.details("this runs")
.state("for ten seconds")
.build()?;
let activity_2 = Activity::new()
.details("believe it")
.state("or not")
.build()?;
let closing_activity = Activity::new()
.details("closing presence in...")
.duration(Duration::from_secs(5))
.small_image("status")
.build()?;
// first run
let client = runner.run(true).await?;
client.set_activity(activity_1).await?;
sleep(Duration::from_secs(5)).await;
client.set_activity(activity_2).await?;
sleep(Duration::from_secs(5)).await;
client.set_activity(closing_activity).await?;
sleep(Duration::from_secs(5)).await;
client.close().await?;
println!("Stopped.");
Ok(())
}