discord-rpc-client/examples/discord_presence_subscribe.rs

39 lines
1009 B
Rust
Raw Normal View History

2022-02-03 09:52:53 -05:00
use discord_rpc_client::{models::Event, Client as DiscordRPC};
2018-04-10 08:26:41 -04:00
use simplelog::*;
2022-02-03 09:52:53 -05:00
use std::{thread, time};
2018-04-10 08:26:41 -04:00
#[tokio::main]
async fn main() -> discord_rpc_client::Result<()> {
TermLogger::init(
LevelFilter::Debug,
Config::default(),
TerminalMode::Mixed,
ColorChoice::Always,
)
.unwrap();
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
}