Formatting from IRC -> Discord

This commit is contained in:
Yash Karandikar 2022-01-18 17:20:50 -06:00
parent 21402aa859
commit be42406ef9

View file

@ -203,6 +203,9 @@ impl EventHandler for Handler {
computed = computed.replace('\n', " ");
computed = computed.replace("\r\n", " "); // just in case
let chars = computed
.as_bytes()
.iter()
@ -473,6 +476,40 @@ async fn irc_loop(
.replace(&computed, format!("<@{}>", id))
.to_string();
}
let mut has_opened_bold = false;
let mut has_opened_italic = false;
for c in computed.clone().chars() {
if c == '\x02' {
computed = computed.replace('\x02', "**");
has_opened_bold = true;
}
if c == '\x1D' {
computed = computed.replace('\x1D', "*");
has_opened_italic = true;
}
if c == '\x0F' {
if has_opened_italic {
computed = computed.replace('\x0F', "*");
has_opened_italic = false;
} else if has_opened_bold {
computed = computed.replace('\x0F', "**");
has_opened_bold = false;
}
}
}
if has_opened_italic {
computed.push_str("*");
has_opened_italic = false;
}
if has_opened_bold {
computed.push_str("**");
has_opened_bold = false;
}
computed = CONTROL_CHAR_RE.replace_all(&computed, "").to_string();
}