discord-rpc-client/examples/discord_presence_subscribe.rs

35 lines
908 B
Rust
Raw Normal View History

#[macro_use]
extern crate tracing;
2022-02-03 09:52:53 -05:00
use discord_rpc_client::{models::Event, Client as DiscordRPC};
use std::{thread, time};
2018-04-10 08:26:41 -04:00
#[tokio::main]
async fn main() -> discord_rpc_client::Result<()> {
tracing_subscriber::fmt::init();
2018-04-10 08:26:41 -04:00
let drpc = DiscordRPC::default();
2018-04-10 08:26:41 -04:00
drpc.connect(425407036495495169).await?;
2018-04-10 08:26:41 -04:00
2022-02-03 09:52:53 -05:00
drpc.subscribe(Event::ActivityJoin, |j| j.secret("123456"))
.await
2018-04-10 08:26:41 -04:00
.expect("Failed to subscribe to event");
2022-02-03 09:52:53 -05:00
drpc.subscribe(Event::ActivitySpectate, |s| s.secret("123456"))
.await
2018-04-10 08:26:41 -04:00
.expect("Failed to subscribe to event");
drpc.subscribe(Event::ActivityJoinRequest, |s| s)
.await
2018-04-10 08:26:41 -04:00
.expect("Failed to subscribe to event");
drpc.unsubscribe(Event::ActivityJoinRequest, |j| j)
.await
2018-04-10 08:26:41 -04:00
.expect("Failed to unsubscribe from event");
2022-02-03 09:52:53 -05:00
loop {
tokio::time::sleep(time::Duration::from_millis(500)).await;
2022-02-03 09:52:53 -05:00
}
2018-04-10 08:26:41 -04:00
}