From a03899f3f8ab080905d2a80685c2af7888b3b476 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Tue, 2 Aug 2022 19:18:20 -0500 Subject: [PATCH] Make avatar TTL configurable --- src/irc_discord.rs | 6 +++--- src/main.rs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/irc_discord.rs b/src/irc_discord.rs index dda2667..cc4f3d8 100644 --- a/src/irc_discord.rs +++ b/src/irc_discord.rs @@ -39,6 +39,7 @@ pub async fn irc_loop( mapping: Arc>, webhooks: HashMap, members: Arc>>, + avatar_ttl: Option, ) -> anyhow::Result<()> { let (send, recv) = unbounded_channel(); tokio::spawn(msg_task(UnboundedReceiverStream::new(recv))); @@ -60,12 +61,11 @@ pub async fn irc_loop( let mut channels_cache = None; while let Some(orig_message) = stream.next().await.transpose()? { - // FIXME: make this configurable - if ttl.elapsed().as_secs() > 5 { - println!("TTL reached"); + if ttl.elapsed().as_secs() > avatar_ttl.unwrap_or(1800) { avatar_cache.clear(); ttl = Instant::now(); } + if let Command::Response(response, args) = orig_message.command { use irc::client::prelude::Response; diff --git a/src/main.rs b/src/main.rs index 2dd11da..95b0f1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ struct DircordConfig { channels: HashMap, webhooks: Option>, ref_content_limit: Option, + avatar_ttl: Option, } macro_rules! type_map_key { @@ -153,7 +154,7 @@ async fn main() -> anyhow::Result<()> { } select! { - r = irc_loop(irc_client, http.clone(), cache.clone(), channels.clone(), webhooks_transformed, members) => r.unwrap(), + r = irc_loop(irc_client, http.clone(), cache.clone(), channels.clone(), webhooks_transformed, members, conf.avatar_ttl) => r.unwrap(), r = discord_client.start() => r.unwrap(), _ = terminate_signal() => { for (_, &v) in channels.iter() {