57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
//! Just for fun I thought I would add a Discord RPC client to the emulator.
|
|
//!
|
|
//! This will display information like the current value of PCX, architecture name and
|
|
//! GitHub repo links to show off the ISA. Perhaps in the future if we cross-compile to
|
|
//! WASM we could include a link to run this software in the browser.
|
|
//!
|
|
//!
|
|
//! # Configuration
|
|
//!
|
|
//! This may be disabled like so in your `.dsarc.toml` file:
|
|
//!
|
|
//! ```toml
|
|
//! [misc]
|
|
//! use_discord_rpc = false
|
|
//! ```
|
|
//!
|
|
//! Alternatively, you can hide this in your Discord settings.
|
|
|
|
use discord_presence::{Client, DiscordError};
|
|
|
|
#[derive(Debug)]
|
|
pub enum DiscordRpcError {
|
|
Client(DiscordError),
|
|
}
|
|
|
|
impl std::fmt::Display for DiscordRpcError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Client(why) => write!(f, "discord RPC error: {why}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for DiscordRpcError {}
|
|
|
|
impl From<DiscordError> for DiscordRpcError {
|
|
fn from(err: DiscordError) -> Self {
|
|
Self::Client(err)
|
|
}
|
|
}
|
|
|
|
/// Sets up the Discord RPC client.
|
|
#[expect(clippy::unreadable_literal)]
|
|
pub fn start_rpc() -> Result<Client, DiscordRpcError> {
|
|
let mut client = discord_presence::Client::new(1384303074088190042);
|
|
|
|
_ = client.on_ready(|ctx| {
|
|
eprintln!("The discord RPC client is ready. Got event {:?}", ctx.event);
|
|
});
|
|
|
|
client.start();
|
|
|
|
client.set_activity(|act| act)?;
|
|
|
|
Ok(client)
|
|
}
|