Add StopScript command
This commit is contained in:
parent
cfd3f8562b
commit
360e869f11
10
src/bot.rs
10
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 {
|
||||
|
@ -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<Mutex<Vec<String>>>,
|
||||
bot_status: Arc<Mutex<BotStatus>>,
|
||||
stop_scripts: Arc<Mutex<bool>>,
|
||||
tick_counter: Arc<Mutex<u8>>,
|
||||
alert_second_counter: Arc<Mutex<u16>>,
|
||||
cleanup_second_counter: Arc<Mutex<u16>>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user