From 25d3846e1c6272a1b1559bc17ca852876f2450d8 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Tue, 13 Sep 2022 18:48:16 +0100 Subject: [PATCH] Add target option to run-bot --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb9d400..2927627 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,6 +98,8 @@ enum Commands { RunBot { #[clap(short, long, action)] dry_run: bool, + #[clap(short, long, value_parser)] + target: Option, }, /// Print details about the currently authed user Whoami, @@ -112,7 +114,7 @@ fn main() -> StdError<()> { Commands::ScrapeWeb => do_scrape_web(), Commands::ListTweets => do_list_tweets(), Commands::Whoami => do_whoami(), - Commands::RunBot { dry_run } => run_bot(*dry_run), + Commands::RunBot { dry_run, target } => run_bot(*dry_run, target.to_owned()), } } @@ -194,11 +196,14 @@ fn get_client(headers: Option) -> StdError StdError<()> { +fn run_bot(dry_run: bool, target: Option) -> StdError<()> { let all = scrape_web()?; - let (title, filename) = all + let (title, filename) = if let Some(target) = target { + all.iter().find(|(title, _)| title.to_lowercase().contains(&target.to_lowercase())) + } else { + all .choose(&mut rand::thread_rng()) - .ok_or("got no images m8")?; + }.ok_or("got no images m8")?; event!(Level::INFO, title, filename, "Picked random thing"); let client = get_client(None)?; event!(Level::INFO, "Fetching metadata...");