remove unneeded results array
parent
ef1fdb5f36
commit
16c1e7da0a
74
src/main.rs
74
src/main.rs
|
@ -89,65 +89,61 @@ fn run(
|
|||
let statuses = client.statuses(&acc.id, None)?;
|
||||
|
||||
let regex = Regex::new(regex).unwrap();
|
||||
let mut results = Vec::new();
|
||||
let mut count = 0;
|
||||
|
||||
if verbose {
|
||||
println!("Searching...");
|
||||
}
|
||||
println!("\n\nResults:\n");
|
||||
|
||||
// Search through statuses
|
||||
for status in statuses.items_iter() {
|
||||
// Add it to results if it matches and it isn't a retoot
|
||||
// or if it matches and isn't a retoot
|
||||
if status_matches(&status, ®ex) && (include_retoots || status.reblog.is_none()) {
|
||||
results.push(status);
|
||||
print_status(&status, verbose);
|
||||
count += 1;
|
||||
}
|
||||
|
||||
// If there's a limit of results, check it and exit
|
||||
if let Some(max) = max_statuses {
|
||||
if results.len() >= max {
|
||||
if count >= max {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("\n\nResults:\n");
|
||||
|
||||
// Print results
|
||||
for status in &results {
|
||||
if !status.spoiler_text.is_empty() {
|
||||
println!("CW: {}", status.spoiler_text);
|
||||
}
|
||||
println!("Content: {}", status.content);
|
||||
// Print actual url if it's a retoot
|
||||
if let Some(retoot) = &status.reblog {
|
||||
if let Some(url) = &retoot.url {
|
||||
println!("Url: {}", url);
|
||||
}
|
||||
} else if let Some(url) = &status.url {
|
||||
println!("Url: {}", url);
|
||||
}
|
||||
|
||||
// Print some extra info
|
||||
if verbose {
|
||||
println!("Created at: {}", status.created_at);
|
||||
if let Some(retoot) = &status.reblog {
|
||||
println!("Is retoot: yes ({})", retoot.account.acct);
|
||||
} else {
|
||||
// We don't want to print these if it's a retoot
|
||||
println!("Favs: {}", status.favourites_count);
|
||||
println!("Retoots: {}", status.reblogs_count);
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("Found {} results", results.len());
|
||||
println!("Found {} results", count);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_status(status: &Status, verbose: bool) {
|
||||
if !status.spoiler_text.is_empty() {
|
||||
println!("CW: {}", status.spoiler_text);
|
||||
}
|
||||
println!("Content: {}", status.content);
|
||||
// Print actual url if it's a retoot
|
||||
if let Some(retoot) = &status.reblog {
|
||||
if let Some(url) = &retoot.url {
|
||||
println!("Url: {}", url);
|
||||
}
|
||||
} else if let Some(url) = &status.url {
|
||||
println!("Url: {}", url);
|
||||
}
|
||||
|
||||
// Print some extra info
|
||||
if verbose {
|
||||
println!("Created at: {}", status.created_at);
|
||||
if let Some(retoot) = &status.reblog {
|
||||
println!("Is retoot: yes ({})", retoot.account.acct);
|
||||
} else {
|
||||
// We don't want to print these if it's a retoot
|
||||
println!("Favs: {}", status.favourites_count);
|
||||
println!("Retoots: {}", status.reblogs_count);
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
fn status_matches(status: &Status, regex: &Regex) -> bool {
|
||||
regex.is_match(&status.content) || regex.is_match(&status.spoiler_text)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue