diff --git a/src/bot.rs b/src/bot.rs index 393cfc2..2908f5a 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -48,6 +48,7 @@ pub enum Command { DropStack, LeaveBed, Script, + StopScript, Latency, MobLocations, ToggleBotStatusMessages, @@ -105,6 +106,7 @@ pub async fn process_command( "drop_stack" | "throw_stack" => command = Command::DropStack, "leave_bed" => command = Command::LeaveBed, "script" | "run" => command = Command::Script, + "stop_script" | "stop_scripts" | "stop_run" => command = Command::StopScript, "latency" | "ping" => command = Command::Latency, "mob_locations" => command = Command::MobLocations, "toggle_alert_messages" => command = Command::ToggleAlertMessages, @@ -878,11 +880,19 @@ pub async fn process_command( Err(error) => return format!("Unable to read script: {}", error), }; for line in script.split("\n") { + if *state.stop_scripts.lock().unwrap() == true { + *state.stop_scripts.lock().unwrap() = false; + break; + } process_command(&line.to_string(), &executor, client, state.clone()).await; } return "Finished executing script!".to_string(); } + Command::StopScript => { + *state.stop_scripts.lock().unwrap() = true; + return "Successfully told all executing scripts to stop!".to_string(); + } Command::Latency => { let mut player = &state.bot_configuration.username; if segments.len() > 0 { diff --git a/src/main.rs b/src/main.rs index cb5c438..e6fbad3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,6 +110,7 @@ async fn main() { bot_configuration: bot_configuration.clone(), whitelist: Arc::new(Mutex::new(bot_configuration.clone().whitelist)), bot_status: Arc::new(Mutex::new(BotStatus::default())), + stop_scripts: Arc::new(Mutex::new(false)), tick_counter: Arc::new(Mutex::new(0)), alert_second_counter: Arc::new(Mutex::new(0)), cleanup_second_counter: Arc::new(Mutex::new(0)), @@ -214,6 +215,7 @@ pub struct State { bot_configuration: BotConfiguration, whitelist: Arc>>, bot_status: Arc>, + stop_scripts: Arc>, tick_counter: Arc>, alert_second_counter: Arc>, cleanup_second_counter: Arc>,