infinitely retry connections
This commit is contained in:
parent
a87a770da7
commit
a1dc28f25e
|
@ -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",
|
||||||
|
|
|
@ -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"
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -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,
|
loop {
|
||||||
|
if let Err(why) = cli
|
||||||
|
.firehose(Rules(
|
||||||
|
&compiled_rules,
|
||||||
cfg.clone(),
|
cfg.clone(),
|
||||||
Client::new(
|
Client::new(
|
||||||
user_agent(cfg.bot_owner_furbooru_account.clone()),
|
user_agent(cfg.bot_owner_furbooru_account.clone()),
|
||||||
cfg.furbooru_api_key.clone(),
|
cfg.furbooru_api_key.clone(),
|
||||||
)?,
|
)?,
|
||||||
))
|
))
|
||||||
.await?;
|
.await
|
||||||
|
{
|
||||||
Ok(())
|
log::error!("firehose error: {:#?}", why);
|
||||||
|
discord_webhook::execute(
|
||||||
|
cfg.discord_webhook_url.clone(),
|
||||||
|
Body::new(format!("firehose error:\n```\n{:#?}\n```", why))
|
||||||
|
).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue