Skip to main content

indefinite/
indefinite.rs

1use filthy_rich::{
2    PresenceRunner,
3    errors::PresenceError,
4    types::{Activity, ActivityType, StatusDisplayType},
5};
6
7#[tokio::main]
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}