From 915403cdaa0296ef1f189e9b4c566bbb444cd973 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Fri, 13 Jan 2023 17:30:46 +0800 Subject: [PATCH] Add wait command (for scripting) --- src/bot.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bot.rs b/src/bot.rs index bfddc62..5170395 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -14,6 +14,7 @@ use strum_macros::EnumIter; #[derive(Debug, Clone, PartialEq, PartialOrd, EnumIter)] pub enum Command { Help, + Wait, BotStatus, Whitelist, WhitelistAdd, @@ -62,6 +63,7 @@ pub async fn process_command( let mut command = Command::Unknown; match segments[0].to_lowercase().as_str() { "help" => command = Command::Help, + "wait" => command = Command::Wait, "bot_status" => command = Command::BotStatus, "whitelist" => command = Command::Whitelist, "whitelist_add" => command = Command::WhitelistAdd, @@ -115,6 +117,18 @@ pub async fn process_command( return format!("Commands (page {}): {}", page, paged_commands.join(", ")); } } + Command::Wait => { + if segments.len() < 1 { + return "Please tell me how long to wait!".to_string(); + } + + let duration = match segments[0].parse() { + Ok(duration) => duration, + Err(error) => return format!("Unable to parse duration: {}", error), + }; + tokio::time::sleep(std::time::Duration::from_millis(duration)).await; + return format!("I have successfully slept for {} ms!", duration); + } Command::BotStatus => { let bot_status = state.bot_status.lock().unwrap().to_owned(); let metadata = client.metadata();