infinitely retry connections

This commit is contained in:
Cadey Ratio 2020-07-06 13:22:02 -04:00
parent a87a770da7
commit a1dc28f25e
3 changed files with 25 additions and 16 deletions

2
Cargo.lock generated
View File

@ -1511,7 +1511,7 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
[[package]] [[package]]
name = "tron" name = "tron"
version = "0.2.5" version = "0.2.6"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "tron" name = "tron"
version = "0.2.5" version = "0.2.6"
authors = ["Christine Dodrill <me@christine.website>"] authors = ["Christine Dodrill <me@christine.website>"]
edition = "2018" edition = "2018"
repository = "https://tulpa.dev/cadey/tron" repository = "https://tulpa.dev/cadey/tron"

View File

@ -50,14 +50,14 @@ impl fmt::Display for Hit {
} }
// TODO(Xe): make this an actual struct for the love of god. // TODO(Xe): make this an actual struct for the love of god.
struct Rules(Vec<CompiledRule>, Config, furbooru::Client); struct Rules<'a>(&'a Vec<CompiledRule>, Config, furbooru::Client);
impl Rules { impl<'a> Rules<'a> {
fn check(&self, text: &String) -> Option<Vec<Hit>> { fn check(&self, text: &String) -> Option<Vec<Hit>> {
let mut result: Vec<Hit> = vec![]; let mut result: Vec<Hit> = vec![];
let mut found = false; let mut found = false;
for rule in &self.0 { for rule in self.0 {
if rule.regex.is_match(text) { if rule.regex.is_match(text) {
log::debug!("{:?} matches {}", text, rule.raw); log::debug!("{:?} matches {}", text, rule.raw);
found = true; found = true;
@ -83,7 +83,7 @@ impl Rules {
} }
#[async_trait] #[async_trait]
impl FirehoseAdaptor for Rules { impl<'a> FirehoseAdaptor for Rules<'a> {
async fn image_created(&self, img: Image) -> Result<()> { async fn image_created(&self, img: Image) -> Result<()> {
let url = format!("https://furbooru.org/{}", img.id); let url = format!("https://furbooru.org/{}", img.id);
log::debug!("got image {}", url); log::debug!("got image {}", url);
@ -242,15 +242,24 @@ async fn main() -> Result<()> {
cfg.furbooru_api_key.clone(), cfg.furbooru_api_key.clone(),
)?; )?;
log::info!("listening on the firehose"); log::info!("listening on the firehose");
cli.firehose(Rules(
compiled_rules,
cfg.clone(),
Client::new(
user_agent(cfg.bot_owner_furbooru_account.clone()),
cfg.furbooru_api_key.clone(),
)?,
))
.await?;
Ok(()) loop {
if let Err(why) = cli
.firehose(Rules(
&compiled_rules,
cfg.clone(),
Client::new(
user_agent(cfg.bot_owner_furbooru_account.clone()),
cfg.furbooru_api_key.clone(),
)?,
))
.await
{
log::error!("firehose error: {:#?}", why);
discord_webhook::execute(
cfg.discord_webhook_url.clone(),
Body::new(format!("firehose error:\n```\n{:#?}\n```", why))
).await?;
}
}
} }