forked from karx/dircord
Implement ignore for JOIN, PART and QUIT
This commit is contained in:
parent
0e18740c43
commit
c43c14f935
|
@ -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
|
||||
|
|
|
@ -42,6 +42,7 @@ pub async fn irc_loop(
|
|||
webhooks: HashMap<String, Webhook>,
|
||||
members: Arc<Mutex<Vec<Member>>>,
|
||||
cache_ttl: Option<u64>,
|
||||
ignore_useractions: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let (send, recv) = unbounded_channel();
|
||||
tokio::spawn(msg_task(UnboundedReceiverStream::new(recv)));
|
||||
|
@ -169,6 +170,7 @@ pub async fn irc_loop(
|
|||
})?;
|
||||
}
|
||||
} else if let Command::JOIN(ref channel, _, _) = orig_message.command {
|
||||
if !ignore_useractions {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let users = unwrap_or_continue!(channel_users.get_mut(channel));
|
||||
|
||||
|
@ -179,7 +181,9 @@ pub async fn irc_loop(
|
|||
http: http.clone(),
|
||||
message: format!("*{}* has joined the channel", nickname),
|
||||
})?;
|
||||
}
|
||||
} else if let Command::PART(ref channel, ref reason) = orig_message.command {
|
||||
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));
|
||||
|
@ -193,7 +197,9 @@ pub async fn irc_loop(
|
|||
http: http.clone(),
|
||||
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));
|
||||
|
@ -208,6 +214,7 @@ pub async fn irc_loop(
|
|||
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)));
|
||||
|
|
|
@ -39,6 +39,7 @@ struct DircordConfig {
|
|||
webhooks: Option<HashMap<String, String>>,
|
||||
ref_content_limit: Option<u16>,
|
||||
cache_ttl: Option<u64>,
|
||||
ignore_useractions: Option<bool>,
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue