Skip to main content

timed/
timed.rs

1use anyhow::Result;
2use std::time::Duration;
3
4use filthy_rich::DiscordIPC;
5use tokio::time::sleep;
6
7#[tokio::main]
8async fn main() -> Result<()> {
9    let mut client = DiscordIPC::new("1463450870480900160");
10
11    // first run
12    client.run().await.unwrap();
13
14    client.set_activity("this runs", "for ten seconds").await?;
15    sleep(Duration::from_secs(5)).await;
16    client.set_activity("believe it", "or not").await?;
17    sleep(Duration::from_secs(5)).await;
18
19    client.clear_activity().await?;
20
21    // if you want to drop the connection here:
22    // client.close().await?;
23
24    // optional sleep
25    sleep(Duration::from_secs(2)).await;
26
27    // if you closed the connection, you must run it afterwards:
28    // client.run().await?;
29
30    // 2nd run
31    client.set_activity("this is the", "second run").await?;
32    sleep(Duration::from_secs(5)).await;
33    client
34        .set_activity("which also runs for", "ten seconds")
35        .await?;
36    sleep(Duration::from_secs(5)).await;
37
38    Ok(())
39}