diff --git a/sample_config.toml b/sample_config.toml index c35f3bf..71432f7 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -1,12 +1,13 @@ token = "..." # REQUIRED: discord bot token nickname = "dircord" # REQUIRED: IRC nickname -server = "karx.xyz"" +server = "karx.xyz" port = 6697 tls = true # OPTIONAL: DEFAULT: false mode = "+B" # OPTIONAL: DEFAULT: none raw_prefix = "++" # OPTIONAL: DEFAULT: ++ ref_content_limit = 512 # OPTIONAL: where to truncate replied messages. Defaults to ~512 minus the prefix cache_ttl = 1800 # OPTIONAL: how long to store caches, in seconds. Defaults to 1800 (30 minutes) +ignore_useractions = false # OPTIONAL: Ignores certain user actions (JOIN, PART, QUIT). DEFAULT: false [channels] # irc channel name -> discord channel id diff --git a/src/irc_discord.rs b/src/irc_discord.rs index 42e8446..2fd4ed1 100644 --- a/src/irc_discord.rs +++ b/src/irc_discord.rs @@ -42,6 +42,7 @@ pub async fn irc_loop( webhooks: HashMap, members: Arc>>, cache_ttl: Option, + ignore_useractions: bool, ) -> anyhow::Result<()> { let (send, recv) = unbounded_channel(); tokio::spawn(msg_task(UnboundedReceiverStream::new(recv))); @@ -169,32 +170,21 @@ pub async fn irc_loop( })?; } } else if let Command::JOIN(ref channel, _, _) = orig_message.command { - let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); - let users = unwrap_or_continue!(channel_users.get_mut(channel)); + if !ignore_useractions { + let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); + let users = unwrap_or_continue!(channel_users.get_mut(channel)); - users.push(nickname.to_string()); + users.push(nickname.to_string()); - send.send(QueuedMessage::Raw { - channel_id, - http: http.clone(), - message: format!("*{}* has joined the channel", nickname), - })?; + send.send(QueuedMessage::Raw { + channel_id, + http: http.clone(), + message: format!("*{}* has joined the channel", nickname), + })?; + } } else if let Command::PART(ref channel, ref reason) = orig_message.command { - let users = unwrap_or_continue!(channel_users.get_mut(channel)); - let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); - let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname)); - - users.swap_remove(pos); - - let reason = reason.as_deref().unwrap_or("Connection closed"); - - send.send(QueuedMessage::Raw { - channel_id, - http: http.clone(), - message: format!("*{}* has quit ({})", nickname, reason), - })?; - } else if let Command::QUIT(ref reason) = orig_message.command { - for (channel, users) in &mut channel_users { + if !ignore_useractions { + let users = unwrap_or_continue!(channel_users.get_mut(channel)); let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname)); @@ -208,6 +198,23 @@ pub async fn irc_loop( message: format!("*{}* has quit ({})", nickname, reason), })?; } + } else if let Command::QUIT(ref reason) = orig_message.command { + if !ignore_useractions { + for (channel, users) in &mut channel_users { + let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); + let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname)); + + users.swap_remove(pos); + + let reason = reason.as_deref().unwrap_or("Connection closed"); + + send.send(QueuedMessage::Raw { + channel_id, + http: http.clone(), + message: format!("*{}* has quit ({})", nickname, reason), + })?; + } + } } else if let Command::NICK(ref new_nick) = orig_message.command { for (channel, users) in &mut channel_users { let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel))); diff --git a/src/main.rs b/src/main.rs index 2123b89..22c2357 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,7 @@ struct DircordConfig { webhooks: Option>, ref_content_limit: Option, cache_ttl: Option, + ignore_useractions: Option, } macro_rules! type_map_key { @@ -154,7 +155,7 @@ async fn main() -> anyhow::Result<()> { } select! { - r = irc_loop(irc_client, http.clone(), cache.clone(), channels.clone(), webhooks_transformed, members, conf.cache_ttl) => r.unwrap(), + r = irc_loop(irc_client, http.clone(), cache.clone(), channels.clone(), webhooks_transformed, members, conf.cache_ttl, conf.ignore_useractions.unwrap_or(false)) => r.unwrap(), r = discord_client.start() => r.unwrap(), _ = terminate_signal() => { for (_, &v) in channels.iter() {