diff --git a/Cargo.lock b/Cargo.lock index 5b6fb10..3eb1429 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,21 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -184,10 +199,10 @@ name = "dircord" version = "0.1.0" dependencies = [ "anyhow", + "fancy-regex", "irc", "lazy_static", "pulldown-cmark", - "regex", "serde", "serenity", "tokio", @@ -288,6 +303,16 @@ dependencies = [ "syn", ] +[[package]] +name = "fancy-regex" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0678ab2d46fa5195aaf59ad034c083d351377d4af57f3e073c074d0da3e3c766" +dependencies = [ + "bit-set", + "regex", +] + [[package]] name = "flate2" version = "1.0.22" diff --git a/Cargo.toml b/Cargo.toml index 2405286..0e94380 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ anyhow = "1.0.52" irc = "0.15" toml = "0.5" serde = "1.0" -regex = "1.5.4" lazy_static = "1.4" pulldown-cmark = "0.9.1" +fancy-regex = "0.10.0" [dependencies.tokio] version = "1.15.0" diff --git a/src/main.rs b/src/main.rs index b3d5a56..5b2367d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use irc::{ proto::Command, }; -use regex::{Captures, Replacer}; +use fancy_regex::{Captures, Replacer}; use pulldown_cmark::Parser; @@ -518,7 +518,7 @@ macro_rules! regex { ($(static $name:ident = $regex:literal;)*) => { ::lazy_static::lazy_static! { $( - static ref $name: ::regex::Regex = ::regex::Regex::new($regex).unwrap(); + static ref $name: ::fancy_regex::Regex = ::fancy_regex::Regex::new($regex).unwrap(); )* } }; @@ -559,13 +559,13 @@ fn irc_to_discord_processing( regex! { static PING_NICK_1 = r"^([\w+]+)(?::|,)"; - static PING_RE_2 = r"@([\w\S]+)"; + static PING_RE_2 = r"(?<=\s)@([\w\S]+)"; static CONTROL_CHAR_RE = r"\x1f|\x02|\x12|\x0f|\x16|\x03(?:\d{1,2}(?:,\d{1,2})?)?"; static WHITESPACE_RE = r"^\s"; static CHANNEL_RE = r"#([A-Za-z-*]+)"; } - if WHITESPACE_RE.is_match(message) && !PING_RE_2.is_match(message) { + if WHITESPACE_RE.is_match(message).unwrap() && !PING_RE_2.is_match(message).unwrap() { return format!("`{}`", message); } @@ -669,7 +669,7 @@ async fn discord_to_irc_processing( // FIXME: the await makes it impossible to use `replace_all`, idk how to fix this for caps in CHANNEL_RE.captures_iter(&computed.clone()) { - let replacement = match ChannelId(caps[1].parse().unwrap()).to_channel(&ctx).await { + let replacement = match ChannelId(caps.unwrap()[1].parse().unwrap()).to_channel(&ctx).await { Ok(Channel::Guild(gc)) => Cow::Owned(format!("#{}", gc.name)), Ok(Channel::Category(cat)) => Cow::Owned(format!("#{}", cat.name)), _ => Cow::Borrowed("#deleted-channel"),