diff --git a/src/lib.rs b/src/lib.rs index 4bde7d4..1bd02cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use crate::database::Database; use anyhow::{anyhow, Context}; use chrono::{DateTime, NaiveDateTime, TimeZone}; use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl}; -use lazy_regex::regex; +use lazy_regex::{regex, Lazy, Regex}; use log::{debug, error, info}; use reqwest::IntoUrl; use serenity::all::{CreateEmbed, CreateEmbedFooter, EditWebhookMessage, ExecuteWebhook}; @@ -46,17 +46,17 @@ impl DisbahnClient { } fn html_to_discord_markdown(input: &str) -> String { - let re_times = regex!(r#"^.*\s*"#i); - let re_bold = regex!(r#"((.|\n)*?)"#i); - let re_italic = regex!(r#"((.|\n)*?)"#i); - let re_strikethrough = regex!(r#"((.|\n)*?)"#i); - let re_newline = regex!(r#""#i); + static RE_TIMES: &Lazy = regex!(r#"^.*\s*"#i); + static RE_BOLD: &Lazy = regex!(r#"((.|\n)*?)"#i); + static RE_ITALIC: &Lazy = regex!(r#"((.|\n)*?)"#i); + static RE_STRIKETHROUGH: &Lazy = regex!(r#"((.|\n)*?)"#i); + static RE_NEWLINE: &Lazy = regex!(r#""#i); - let input = re_times.replace(input, ""); - let input = re_bold.replace_all(&input, "**$1**"); - let input = re_italic.replace_all(&input, "*$1*"); - let input = re_strikethrough.replace_all(&input, "~~$1~~"); - let input = re_newline.replace_all(&input, "\n"); + let input = RE_TIMES.replace(&input, ""); + let input = RE_BOLD.replace_all(&input, "**$1**"); + let input = RE_ITALIC.replace_all(&input, "*$1*"); + let input = RE_STRIKETHROUGH.replace_all(&input, "~~$1~~"); + let input = RE_NEWLINE.replace_all(&input, "\n"); input.to_string() }