From 86b892e614cefc8f620ff4743f5742c4f2030ab8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 21 Dec 2024 22:16:45 -0800 Subject: [PATCH] script action --- src/main.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index fd39fa4..77b004d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,25 @@ async fn main(){ } } +enum ScriptActionParseResult{ + Pass, + Block, + Exit, + Delete, +} +struct ParseScriptActionErr; +impl std::str::FromStr for ScriptActionParseResult{ + type Err=ParseScriptActionErr; + fn from_str(s:&str)->Result{ + match s{ + "pass\n"=>Ok(Self::Pass), + "block\n"=>Ok(Self::Block), + "exit\n"=>Ok(Self::Exit), + "delete\n"=>Ok(Self::Delete), + _=>Err(ParseScriptActionErr), + } + } +} #[derive(Debug)] enum ReviewError{ Cookie(submissions_api::CookieError), @@ -37,6 +56,8 @@ enum ReviewError{ GetScriptFromHash(submissions_api::types::SingleItemError), NoScript, WriteCurrent(std::io::Error), + ActionIO(std::io::Error), + ReadCurrent(std::io::Error), } struct ReviewConfig{ @@ -57,17 +78,31 @@ async fn review(config:ReviewConfig)->Result<(),ReviewError>{ Policy:Some(submissions_api::types::Policy::None), }).await.map_err(ReviewError::GetPolicies)?; - for policy in unreviewed_policies{ + for unreviewed_policy in unreviewed_policies{ // download source code let script_response=api.get_script_from_hash(submissions_api::types::HashRequest{ - hash:policy.FromScriptHash.as_str(), + hash:unreviewed_policy.FromScriptHash.as_str(), }).await .map_err(ReviewError::GetScriptFromHash)? .ok_or(ReviewError::NoScript)?; let source=script_response.Source; //load source into current.lua - tokio::fs::write("current.lua",source).await.map_err(ReviewError::WriteCurrent)?; + tokio::fs::write("current.lua",source.as_str()).await.map_err(ReviewError::WriteCurrent)?; + + //prompt action in terminal + //wait for input + let script_action; + loop{ + print!("action: "); + std::io::Write::flush(&mut std::io::stdout()).map_err(ReviewError::ActionIO)?; + let mut action_string=String::new(); + std::io::stdin().read_line(&mut action_string).map_err(ReviewError::ActionIO)?; + if let Ok(parsed_script_action)=action_string.parse::(){ + script_action=parsed_script_action; + break; + } + } } Ok(())