forked from karx/dircord
Make avatar TTL configurable
This commit is contained in:
parent
3979987b3a
commit
a03899f3f8
|
@ -39,6 +39,7 @@ pub async fn irc_loop(
|
||||||
mapping: Arc<HashMap<String, u64>>,
|
mapping: Arc<HashMap<String, u64>>,
|
||||||
webhooks: HashMap<String, Webhook>,
|
webhooks: HashMap<String, Webhook>,
|
||||||
members: Arc<Mutex<Vec<Member>>>,
|
members: Arc<Mutex<Vec<Member>>>,
|
||||||
|
avatar_ttl: Option<u64>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let (send, recv) = unbounded_channel();
|
let (send, recv) = unbounded_channel();
|
||||||
tokio::spawn(msg_task(UnboundedReceiverStream::new(recv)));
|
tokio::spawn(msg_task(UnboundedReceiverStream::new(recv)));
|
||||||
|
@ -60,12 +61,11 @@ pub async fn irc_loop(
|
||||||
let mut channels_cache = None;
|
let mut channels_cache = None;
|
||||||
|
|
||||||
while let Some(orig_message) = stream.next().await.transpose()? {
|
while let Some(orig_message) = stream.next().await.transpose()? {
|
||||||
// FIXME: make this configurable
|
if ttl.elapsed().as_secs() > avatar_ttl.unwrap_or(1800) {
|
||||||
if ttl.elapsed().as_secs() > 5 {
|
|
||||||
println!("TTL reached");
|
|
||||||
avatar_cache.clear();
|
avatar_cache.clear();
|
||||||
ttl = Instant::now();
|
ttl = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Command::Response(response, args) = orig_message.command {
|
if let Command::Response(response, args) = orig_message.command {
|
||||||
use irc::client::prelude::Response;
|
use irc::client::prelude::Response;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct DircordConfig {
|
||||||
channels: HashMap<String, u64>,
|
channels: HashMap<String, u64>,
|
||||||
webhooks: Option<HashMap<String, String>>,
|
webhooks: Option<HashMap<String, String>>,
|
||||||
ref_content_limit: Option<u16>,
|
ref_content_limit: Option<u16>,
|
||||||
|
avatar_ttl: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! type_map_key {
|
macro_rules! type_map_key {
|
||||||
|
@ -153,7 +154,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
select! {
|
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(),
|
r = discord_client.start() => r.unwrap(),
|
||||||
_ = terminate_signal() => {
|
_ = terminate_signal() => {
|
||||||
for (_, &v) in channels.iter() {
|
for (_, &v) in channels.iter() {
|
||||||
|
|
Loading…
Reference in a new issue