Add automated warning and banning
This commit is contained in:
@@ -85,7 +85,6 @@
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use linkify::LinkFinder;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use twilight_model::gateway::payload::incoming::MessageCreate;
|
||||
@@ -101,8 +100,9 @@ use crate::discord::sanitizing::SanitizeDiscordMarkdown;
|
||||
/// * `event`: The incoming message event to escape.
|
||||
///
|
||||
/// Returns:
|
||||
/// [`String`] - The escaped and censored message.
|
||||
pub fn escape_message(event: &MessageCreate) -> String {
|
||||
/// [`(String, Vec<Arc<dyn Rule>>)`] - The escaped and censored message, and a vector of the rules
|
||||
/// broken.
|
||||
pub fn escape_message(event: &MessageCreate) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
let mut message = event.content.to_string();
|
||||
|
||||
for mention in &event.mentions {
|
||||
@@ -123,20 +123,11 @@ pub fn escape_message(event: &MessageCreate) -> String {
|
||||
);
|
||||
}
|
||||
|
||||
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 (censored, _) = moderate_message(&message);
|
||||
let (censored, rules) = moderate_message(&message);
|
||||
|
||||
log::debug!("Escaped and normalized message: {censored:?}");
|
||||
|
||||
censored
|
||||
(censored, rules)
|
||||
}
|
||||
|
||||
/// A normalized message and its mappings to the original message's individual grapheme clusters.
|
||||
@@ -157,6 +148,8 @@ pub struct NormalizedMessage {
|
||||
}
|
||||
|
||||
/// Generates a normalized message out of the original message string.
|
||||
///
|
||||
/// TODO: Replace * in the message with wildcards to match censored words.
|
||||
///
|
||||
/// Arguments:
|
||||
/// * `message`: The original message to normalize.
|
||||
@@ -165,6 +158,7 @@ pub struct NormalizedMessage {
|
||||
/// [`NormalizedMessage`] - The normalized message and its mappings to the original string.
|
||||
pub fn normalize(message: String) -> NormalizedMessage {
|
||||
let replacements: HashMap<char, char> = [
|
||||
('$', 's'),
|
||||
('@', 'a'),
|
||||
('0', 'o'),
|
||||
('1', 'i'),
|
||||
|
||||
Reference in New Issue
Block a user