Make avatar TTL configurable

This commit is contained in:
Yash Karandikar 2022-08-02 19:18:20 -05:00
parent 3979987b3a
commit a03899f3f8
2 changed files with 5 additions and 4 deletions

View file

@ -39,6 +39,7 @@ pub async fn irc_loop(
mapping: Arc<HashMap<String, u64>>,
webhooks: HashMap<String, Webhook>,
members: Arc<Mutex<Vec<Member>>>,
avatar_ttl: Option<u64>,
) -> 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;

View file

@ -38,6 +38,7 @@ struct DircordConfig {
channels: HashMap<String, u64>,
webhooks: Option<HashMap<String, String>>,
ref_content_limit: Option<u16>,
avatar_ttl: Option<u64>,
}
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() {