diff --git a/src/lib.rs b/src/lib.rs index 955f40f..2bab7ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,7 +211,7 @@ impl SteamGuardAccount { /// /// Host: https://steamcommunity.com /// Steam Endpoint: `POST /mobileconf/ajaxop` - fn send_confirmation_ajax(&self, conf: Confirmation, operation: String) -> anyhow::Result<()> { + fn send_confirmation_ajax(&self, conf: &Confirmation, operation: String) -> anyhow::Result<()> { ensure!(operation == "allow" || operation == "cancel"); let url = "https://steamcommunity.com".parse::().unwrap(); @@ -241,6 +241,14 @@ impl SteamGuardAccount { ensure!(resp.success); Ok(()) } + + pub fn accept_confirmation(&self, conf: &Confirmation) -> anyhow::Result<()> { + self.send_confirmation_ajax(conf, "allow".into()) + } + + pub fn deny_confirmation(&self, conf: &Confirmation) -> anyhow::Result<()> { + self.send_confirmation_ajax(conf, "cancel".into()) + } } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index abb7efe..fb1129c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,7 +124,7 @@ fn main() { debug!("selected accounts: {:?}", selected_accounts.iter().map(|a| a.account_name.clone()).collect::>()); - if matches.is_present("trade") { + if let Some(trade_matches) = matches.subcommand_matches("trade") { info!("trade"); for a in selected_accounts.iter_mut() { let mut account = a; // why is this necessary? @@ -133,9 +133,16 @@ fn main() { loop { match account.get_trade_confirmations() { Ok(confs) => { - for conf in confs { + for conf in &confs { println!("{}", conf.description()); } + if trade_matches.is_present("accept-all") { + info!("accepting all confirmations"); + for conf in &confs { + let result = account.accept_confirmation(conf); + debug!("accept confirmation result: {:?}", result); + } + } break; } Err(_) => {