Checkpoint
This commit is contained in:
@@ -6,13 +6,10 @@ use twilight_model::{gateway::payload::incoming::MessageCreate, id::Id};
|
||||
use twilight_validate::request::webhook_username;
|
||||
|
||||
use crate::{
|
||||
database::models::{Call, Channel},
|
||||
discord::{images, sanitizing::SanitizeDiscordMarkdown},
|
||||
framework::{
|
||||
database::models::{Call, Channel}, discord::{images, sanitizing::SanitizeDiscordMarkdown}, framework::{
|
||||
events::traits::{EventResult, OnMessageHandler},
|
||||
runtime::Runtime,
|
||||
},
|
||||
state::State,
|
||||
}, groups::calls::moderation::escape_message, state::State
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -155,74 +152,3 @@ fn get_display_profile(event: &MessageCreate) -> DisplayProfile {
|
||||
|
||||
DisplayProfile { name, avatar_url }
|
||||
}
|
||||
|
||||
fn escape_message(event: &MessageCreate) -> String {
|
||||
let mut message = event.content.to_string();
|
||||
|
||||
for mention in &event.mentions {
|
||||
message = message.replace(
|
||||
&format!("<@{}>", mention.id),
|
||||
&format!("**@{}**", mention.name.sanitize(true)),
|
||||
);
|
||||
}
|
||||
|
||||
for mention in &event.mention_roles {
|
||||
message = message.replace(&format!("<@&{mention}>"), "**@Role**");
|
||||
}
|
||||
|
||||
for mention in &event.mention_channels {
|
||||
message = message.replace(
|
||||
&format!("<#{}>", mention.id),
|
||||
&format!("**#{}**", mention.name.sanitize(true)),
|
||||
);
|
||||
}
|
||||
|
||||
let mut finder = LinkFinder::new();
|
||||
finder.url_must_have_scheme(false);
|
||||
|
||||
for link in finder.links(&message.clone()) {
|
||||
let url = link.as_str();
|
||||
|
||||
message = message.replace(url, &"\\#".repeat(url.len()));
|
||||
}
|
||||
|
||||
let replacements: HashMap<char, Option<char>> = [
|
||||
('@', Some('a')),
|
||||
('0', Some('o')),
|
||||
('1', Some('i')),
|
||||
('2', Some('z')),
|
||||
('3', Some('e')),
|
||||
('4', Some('a')),
|
||||
('5', Some('s')),
|
||||
('6', Some('b')),
|
||||
('7', Some('t')),
|
||||
('8', Some('g')),
|
||||
('9', Some('q')),
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
let normalized_unidecoded = unidecode::unidecode(&message)
|
||||
.to_lowercase()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<&str>>()
|
||||
.join(" ");
|
||||
let mut normalized = String::with_capacity(normalized_unidecoded.len());
|
||||
|
||||
for ch in normalized_unidecoded.chars() {
|
||||
if let Some(&replacement) = replacements.get(&ch) {
|
||||
if let Some(replacement) = replacement {
|
||||
normalized.push(replacement);
|
||||
}
|
||||
} else if ch.is_alphanumeric() || ch.is_whitespace() {
|
||||
normalized.push(ch);
|
||||
}
|
||||
|
||||
// skip everything else (punctuation not in map, zero-width, etc.)
|
||||
}
|
||||
|
||||
log::debug!("Escaped message: {normalized}");
|
||||
|
||||
message.sanitize(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user