feat: new parser for mention everything (#411)

* feat: implement custom parser for mentions

* feat: handle backticks in codeblocks and escapes

* chore: remove fancy-regex

* fix: dont serialise empty role mentions

* chore: cleanup role mentions logic

* chore: update lockfile

* fix: actually use everyone and online mentions from content

* fix: broken merge

---------

Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
Paul Makles
2025-04-28 17:08:06 +01:00
committed by GitHub
parent 29b6ac3acf
commit f75d635c81
7 changed files with 334 additions and 97 deletions

View File

@@ -25,7 +25,6 @@ revolt-permissions = { version = "0.8.4", path = "../permissions" }
# Utility
regex = "1.11"
fancy-regex = "0.14"
indexmap = "1.9.3"
once_cell = "1.17.1"
num_enum = "0.6.1"

View File

@@ -1,8 +1,6 @@
use std::time::SystemTime;
use fancy_regex::Regex;
use indexmap::{IndexMap, IndexSet};
use once_cell::sync::Lazy;
use revolt_config::config;
#[cfg(feature = "validator")]
@@ -15,15 +13,6 @@ use iso8601_timestamp::Timestamp;
use super::{Channel, Embed, File, Member, MessageWebhook, User, Webhook, RE_COLOUR};
pub static RE_MENTION: Lazy<Regex> =
Lazy::new(|| Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap());
pub static RE_ROLE_MENTION: Lazy<Regex> =
Lazy::new(|| Regex::new(r"<%([0-9A-HJKMNP-TV-Z]{26})>|@online|@everyone").unwrap());
pub static RE_BLOCKS: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?s)(?<!\\)(?:(```.+?(?<!\\)```)|`[^`\n\r]+?(?<!\\)`)").unwrap());
auto_derived_partial!(
/// Message
pub struct Message {
@@ -65,6 +54,7 @@ auto_derived_partial!(
#[serde(skip_serializing_if = "Option::is_none")]
pub mentions: Option<Vec<String>>,
/// Array of role ids mentioned in this message
#[serde(skip_serializing_if = "Option::is_none")]
pub role_mentions: Option<Vec<String>>,
/// Array of message ids this message is replying to
#[serde(skip_serializing_if = "Option::is_none")]