From f124ba75a54e306b8748e40d0534c710d8c1ee09 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Tue, 18 Jan 2022 09:42:14 -0600 Subject: [PATCH] Support codeblocks Discord -> IRC --- src/main.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main.rs b/src/main.rs index 0ed24aa..955dd0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,30 @@ impl EventHandler for Handler { let attachments: Vec = msg.attachments.iter().map(|a| a.url.clone()).collect(); + if msg.content.starts_with("```") { + let mut lines = msg.content.split("\n").collect::>(); + // remove the backticks + lines.remove(lines.len() - 1); + lines.remove(0); + + if user_id != msg.author.id && !msg.author.bot && msg.channel_id == channel_id { + for line in lines { + send_irc_message(&sender, &channel, &format!("<{}> {}", new_nick, line)) + .await + .unwrap(); + } + + for attachment in attachments { + send_irc_message(&sender, &channel, &format!("<{}> {}", new_nick, attachment)) + .await + .unwrap(); + } + } + + return; + } + + lazy_static! { static ref PING_RE_1: Regex = Regex::new(r"<@[0-9]+>").unwrap(); static ref PING_RE_2: Regex = Regex::new(r"<@![0-9]+>").unwrap();