infinitely retry connections
This commit is contained in:
parent
a87a770da7
commit
a1dc28f25e
|
@ -1511,7 +1511,7 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
|
|||
|
||||
[[package]]
|
||||
name = "tron"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tron"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
authors = ["Christine Dodrill <me@christine.website>"]
|
||||
edition = "2018"
|
||||
repository = "https://tulpa.dev/cadey/tron"
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -50,14 +50,14 @@ impl fmt::Display for Hit {
|
|||
}
|
||||
|
||||
// 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>> {
|
||||
let mut result: Vec<Hit> = vec![];
|
||||
let mut found = false;
|
||||
|
||||
for rule in &self.0 {
|
||||
for rule in self.0 {
|
||||
if rule.regex.is_match(text) {
|
||||
log::debug!("{:?} matches {}", text, rule.raw);
|
||||
found = true;
|
||||
|
@ -83,7 +83,7 @@ impl Rules {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FirehoseAdaptor for Rules {
|
||||
impl<'a> FirehoseAdaptor for Rules<'a> {
|
||||
async fn image_created(&self, img: Image) -> Result<()> {
|
||||
let url = format!("https://furbooru.org/{}", img.id);
|
||||
log::debug!("got image {}", url);
|
||||
|
@ -242,15 +242,24 @@ async fn main() -> Result<()> {
|
|||
cfg.furbooru_api_key.clone(),
|
||||
)?;
|
||||
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?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue