Add target option to run-bot
This commit is contained in:
parent
b1753d8775
commit
25d3846e1c
13
src/main.rs
13
src/main.rs
|
@ -98,6 +98,8 @@ enum Commands {
|
||||||
RunBot {
|
RunBot {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long, action)]
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
|
#[clap(short, long, value_parser)]
|
||||||
|
target: Option<String>,
|
||||||
},
|
},
|
||||||
/// Print details about the currently authed user
|
/// Print details about the currently authed user
|
||||||
Whoami,
|
Whoami,
|
||||||
|
@ -112,7 +114,7 @@ fn main() -> StdError<()> {
|
||||||
Commands::ScrapeWeb => do_scrape_web(),
|
Commands::ScrapeWeb => do_scrape_web(),
|
||||||
Commands::ListTweets => do_list_tweets(),
|
Commands::ListTweets => do_list_tweets(),
|
||||||
Commands::Whoami => do_whoami(),
|
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<reqwest::header::HeaderMap>) -> StdError<reqwest::
|
||||||
Ok(c.build()?)
|
Ok(c.build()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_bot(dry_run: bool) -> StdError<()> {
|
fn run_bot(dry_run: bool, target: Option<String>) -> StdError<()> {
|
||||||
let all = scrape_web()?;
|
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())
|
.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");
|
event!(Level::INFO, title, filename, "Picked random thing");
|
||||||
let client = get_client(None)?;
|
let client = get_client(None)?;
|
||||||
event!(Level::INFO, "Fetching metadata...");
|
event!(Level::INFO, "Fetching metadata...");
|
||||||
|
|
Loading…
Reference in New Issue