From c9318d7261a8cf3648f26b491e25df048dab60df Mon Sep 17 00:00:00 2001 From: shibedrill Date: Mon, 21 Oct 2024 23:09:54 -0400 Subject: [PATCH] Added names to objects --- src/main.rs | 3 +++ src/minecraft.rs | 13 +++++++++---- src/scpsl.rs | 13 +++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0245a5f..25f3c33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,14 +18,17 @@ async fn main() { let gamerzone = Minecraft::new( Url::try_from("https://api.mcstatus.io/v2/status/java/gamer.shibedrill.site").unwrap(), std::env::var("TOKEN_BOT_MC_GAMER").unwrap(), + "Gamer SMP".into(), ); let mchprs = Minecraft::new( Url::try_from("https://api.mcstatus.io/v2/status/java/mchprs.shibedrill.site").unwrap(), std::env::var("TOKEN_BOT_MC_MCHPRS").unwrap(), + "Project MCRV".into(), ); let scpsl = Scpsl::new( Url::try_from("https://api.scplist.kr/api/servers/81460").unwrap(), std::env::var("TOKEN_BOT_SCPSL").unwrap(), + "SCP: SL".into(), ); join!(scpsl.run(), mchprs.run(), gamerzone.run()); } diff --git a/src/minecraft.rs b/src/minecraft.rs index 9c85869..2b740da 100644 --- a/src/minecraft.rs +++ b/src/minecraft.rs @@ -25,11 +25,12 @@ pub struct Data { pub struct Minecraft { url: Url, token: String, + name: String, } impl Minecraft { - pub fn new(url: Url, token: String) -> Self { - Self { url, token } + pub fn new(url: Url, token: String, name: String) -> Self { + Self { url, token, name } } pub async fn get_status(&self) -> Result { @@ -94,9 +95,13 @@ pub async fn event_handler( .controller .get_status() .await - .inspect_err(|e| error!("Failed to get status: {}", e)) + .inspect_err(|e| error!("{}: Failed to get status: {}", data.controller.name, e)) .unwrap(); - info!("Got status: {}", status.to_string()); + info!( + "{}: Got status: {}", + data.controller.name, + status.to_string() + ); funcs::set_presence(ctx, status); tokio::time::sleep(std::time::Duration::from_secs(30)).await; diff --git a/src/scpsl.rs b/src/scpsl.rs index 935c925..2fa1ea3 100644 --- a/src/scpsl.rs +++ b/src/scpsl.rs @@ -17,13 +17,14 @@ pub struct Data { #[derive(Clone)] pub struct Scpsl { + name: String, url: Url, token: String, } impl Scpsl { - pub fn new(url: Url, token: String) -> Self { - Self { url, token } + pub fn new(url: Url, token: String, name: String) -> Self { + Self { url, token, name } } async fn get_status(&self) -> Result { let http_client = Client::new(); @@ -91,9 +92,13 @@ pub async fn event_handler( .controller .get_status() .await - .inspect_err(|e| error!("Failed to get status: {}", e)) + .inspect_err(|e| error!("{}: Failed to get status: {}", data.controller.name, e)) .unwrap(); - info!("Got status: {}", status.to_string()); + info!( + "{}: Got status: {}", + data.controller.name, + status.to_string() + ); funcs::set_presence(ctx, status); tokio::time::sleep(std::time::Duration::from_secs(30)).await;