feat: test mod check

This commit is contained in:
notohh 2024-06-20 07:10:29 -04:00
parent 938413509f
commit e03b144d9f
Signed by: notohh
GPG key ID: BD47506D475EE86D

View file

@ -1,7 +1,7 @@
use crate::client::TwitchClient; use crate::client::TwitchClient;
use sysinfo::System; use sysinfo::System;
use std::error::Error; use std::{error::Error, thread::sleep, time::Duration};
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Box<dyn Error>> { pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Box<dyn Error>> {
@ -10,6 +10,7 @@ pub async fn ping_command(m: &PrivmsgMessage, c: &TwitchClient) -> Result<(), Bo
sys.refresh_all(); sys.refresh_all();
let pid = sysinfo::get_current_pid().unwrap(); let pid = sysinfo::get_current_pid().unwrap();
let channel = m.channel_login.to_owned();
if let Some(process) = sys.process(pid) { if let Some(process) = sys.process(pid) {
let process_memory = process.memory(); 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_seconds = process.run_time();
let uptime_minute = uptime_seconds / 60; let uptime_minute = uptime_seconds / 60;
let remaining_seconds = 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 host = System::name().unwrap();
let s = format!( let s = format!(
"🚀Pong! | ↑: {}m {}s | Host: {} | Mem: {:.2} MB", "🚀Pong! | ↑: {}h {}m {}s | Host: {} | Mem: {:.2} MB",
uptime_minute, remaining_seconds, host, mem 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(()) Ok(())
} }