diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 8ddbfff..c4aa7df 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -1,7 +1,7 @@ use crate::client::TwitchClient; use sysinfo::System; -use std::error::Error; +use std::{error::Error, thread::sleep, time::Duration}; use twitch_irc::message::PrivmsgMessage; pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Box> { @@ -10,6 +10,7 @@ pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Bo sys.refresh_all(); let pid = sysinfo::get_current_pid().unwrap(); + let channel = m.channel_login.to_owned(); if let Some(process) = sys.process(pid) { let process_memory = process.memory(); @@ -18,14 +19,24 @@ pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Bo let uptime_seconds = process.run_time(); let uptime_minute = uptime_seconds / 60; let remaining_seconds = uptime_seconds % 60; + let remaining_hour = uptime_minute % 60; + let is_moderator = m.badges.iter().any(|badge| badge.name == "moderator"); let host = System::name().unwrap(); let s = format!( - "🚀Pong! | ↑: {}m {}s | Host: {} | Mem: {:.2} MB", - uptime_minute, remaining_seconds, host, mem + "🚀Pong! | ↑: {}h {}m {}s | Host: {} | Mem: {:.2} MB", + uptime_minute, remaining_hour, remaining_seconds, host, mem ); - c.twitch_client.say(m.channel_login.to_owned(), s).await?; + + // need to make this check global for all commands eventually + + if is_moderator { + c.twitch_client.say(channel, s).await?; + } else { + sleep(Duration::from_secs(1)); + c.twitch_client.say(channel, s).await?; + } } Ok(()) }