# HG changeset patch # User unc0rr # Date 1626296510 -7200 # Node ID d9db7b763bd1d759cc29acf4da4055e2a49ad826 # Parent ad79e5c0885c793cabe4e92c13d3f2c28a4890c4 Publish join and part commands as well diff -r ad79e5c0885c -r d9db7b763bd1 tools/ubot/src/main.rs --- a/tools/ubot/src/main.rs Sat Jul 10 12:03:50 2021 +0200 +++ b/tools/ubot/src/main.rs Wed Jul 14 23:01:50 2021 +0200 @@ -41,51 +41,84 @@ } async fn handle_irc(pub_channel: &lapin::Channel, irc_message: &Message) -> AHResult<()> { - if let Command::PRIVMSG(msgtarget, message) = &irc_message.command { - let target = irc_message - .response_target() - .expect("Really expected PRIVMSG would have a source"); - let target = if target.starts_with('#') { - &target[1..] - } else { - &target - }; + match &irc_message.command { + Command::PRIVMSG(msgtarget, message) => { + let target = irc_message + .response_target() + .expect("Really expected PRIVMSG would have a source"); + let target = if target.starts_with('#') { + &target[1..] + } else { + &target + }; - let who = irc_message.source_nickname().unwrap_or(msgtarget); + let who = irc_message.source_nickname().unwrap_or(msgtarget); - if message.starts_with("!") { - if let Some((cmd, param)) = message.split_once(' ') { - pub_channel - .basic_publish( - "irc", - &format!("cmd.{}.{}", &cmd[1..], target), - BasicPublishOptions::default(), - format!("{}\n{}", who, param).as_bytes().to_vec(), - BasicProperties::default(), - ) - .await?; + if message.starts_with("!") { + if let Some((cmd, param)) = message.split_once(' ') { + pub_channel + .basic_publish( + "irc", + &format!("cmd.{}.{}", &cmd[1..], target), + BasicPublishOptions::default(), + format!("{}\n{}", who, param).as_bytes().to_vec(), + BasicProperties::default(), + ) + .await?; + } else { + pub_channel + .basic_publish( + "irc", + &format!("cmd.{}.{}", &message[1..], target), + BasicPublishOptions::default(), + who.as_bytes().to_vec(), + BasicProperties::default(), + ) + .await?; + } } else { pub_channel .basic_publish( "irc", - &format!("cmd.{}.{}", &message[1..], target), + &format!("msg.{}", target), BasicPublishOptions::default(), - who.as_bytes().to_vec(), + format!("{}\n{}", who, message).as_bytes().to_vec(), BasicProperties::default(), ) .await?; } - } else { + } + Command::JOIN(channel, _, _) => { pub_channel .basic_publish( "irc", - &format!("msg.{}", target), + &format!("join.{}", &channel[1..]), BasicPublishOptions::default(), - format!("{}\n{}", who, message).as_bytes().to_vec(), + irc_message + .source_nickname() + .expect("Hey, who joined?") + .as_bytes() + .to_vec(), BasicProperties::default(), ) .await?; } + Command::PART(channel, _) => { + pub_channel + .basic_publish( + "irc", + &format!("part.{}", &channel[1..]), + BasicPublishOptions::default(), + irc_message + .source_nickname() + .expect("Hey, who left?") + .as_bytes() + .to_vec(), + BasicProperties::default(), + ) + .await?; + } + _ => (), } Ok(())