From faa0c126075e45a2c5276c4f181ae1616d43deac Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Fri, 13 Jan 2023 16:23:00 +0800 Subject: [PATCH] Add scripting system (part 2) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/bot.rs | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5d5242..7a0a221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,13 +665,13 @@ name = "errornowatcher" version = "0.1.0" dependencies = [ "anyhow", + "async-recursion", "azalea", "azalea-block", "azalea-core", "azalea-protocol", "chrono", "colored", - "futures", "serde", "strum", "strum_macros", diff --git a/Cargo.toml b/Cargo.toml index 4b87e07..0a49b98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,4 @@ colored = "2.0.0" chrono = "0.4.23" strum = "0.24.1" strum_macros = "0.24.1" -futures = "0.3.25" +async-recursion = "1.0.0" diff --git a/src/bot.rs b/src/bot.rs index da92739..6588e35 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,4 +1,5 @@ use crate::{logging::log_error, State}; +use async_recursion::async_recursion; use azalea::{ pathfinder::BlockPosGoal, prelude::*, BlockPos, SprintDirection, Vec3, WalkDirection, }; @@ -7,7 +8,6 @@ use azalea_protocol::packets::game::{ self, serverbound_interact_packet::InteractionHand, ServerboundGamePacket, }; use chrono::{Local, TimeZone}; -use futures::future::{BoxFuture, FutureExt}; use strum::IntoEnumIterator; use strum_macros::EnumIter; @@ -44,12 +44,13 @@ pub enum Command { Unknown, } +#[async_recursion] pub async fn process_command( command: &String, executor: &String, client: &mut Client, state: &mut State, -) -> BoxFuture<'static, String> { +) -> String { let mut segments: Vec = command .split(" ") .map(|segment| segment.to_string()) @@ -649,12 +650,9 @@ pub async fn process_command( Ok(script) => script, Err(error) => return format!("Unable to read script: {}", error), }; - async move { - for line in script.split("\n") { - process_command(&line.to_string(), &executor, client, state).await; - } + for line in script.split("\n") { + process_command(&line.to_string(), &executor, client, state).await; } - .boxed(); return "Finished executing script!".to_string(); }