implement --accept-all
This commit is contained in:
parent
489842cc78
commit
d4c1758f1b
2 changed files with 18 additions and 3 deletions
10
src/lib.rs
10
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::<Url>().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)]
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -124,7 +124,7 @@ fn main() {
|
|||
|
||||
debug!("selected accounts: {:?}", selected_accounts.iter().map(|a| a.account_name.clone()).collect::<Vec<String>>());
|
||||
|
||||
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(_) => {
|
||||
|
|
Loading…
Reference in a new issue