review command

This commit is contained in:
Quaternions 2024-12-21 22:15:45 -08:00
parent c2299102cd
commit 0799aa311f

View File

@ -10,9 +10,65 @@ struct Cli{
#[derive(Subcommand)]
enum Commands{
Review(ReviewCommand),
}
fn main(){
#[derive(Args)]
struct ReviewCommand{
#[arg(long)]
cookie:String,
}
#[tokio::main]
async fn main(){
let cli=Cli::parse();
match cli.command{
Commands::Review(command)=>review(ReviewConfig{
cookie:command.cookie,
}).await.unwrap(),
}
}
#[derive(Debug)]
enum ReviewError{
Cookie(submissions_api::CookieError),
Reqwest(submissions_api::ReqwestError),
GetPolicies(submissions_api::Error),
GetScriptFromHash(submissions_api::types::SingleItemError),
NoScript,
WriteCurrent(std::io::Error),
}
struct ReviewConfig{
cookie:String,
}
async fn review(config:ReviewConfig)->Result<(),ReviewError>{
// download unreviewed policies
// review them
let cookie=submissions_api::Cookie::new(&config.cookie).map_err(ReviewError::Cookie)?;
let api=submissions_api::external::Context::new("http://localhost:8083".to_owned(),cookie).map_err(ReviewError::Reqwest)?;
let unreviewed_policies=api.get_script_policies(submissions_api::types::GetScriptPoliciesRequest{
Page:1,
Limit:100,
FromScriptHash:None,
ToScriptID:None,
Policy:Some(submissions_api::types::Policy::None),
}).await.map_err(ReviewError::GetPolicies)?;
for policy in unreviewed_policies{
// download source code
let script_response=api.get_script_from_hash(submissions_api::types::HashRequest{
hash: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)?;
}
Ok(())
}