Checkpoint

This commit is contained in:
2025-08-12 11:41:10 -03:00
parent cd7f4c1cc9
commit 79f0ca08b2
+23 -20
View File
@@ -70,12 +70,13 @@ pub fn escape_message(event: &MessageCreate) -> String {
}
#[derive(Debug)]
struct NormalizedMessage {
pub struct NormalizedMessage {
/// The normalized message content.
message: String,
/// Mappings from original indices to normalized indices, or None if it was removed.
mappings: HashMap<(usize, usize), Option<(usize, usize)>>,
/// Mappings from normalized start indices to original start indices (indices are grapheme
/// indices).
mappings: Vec<usize>,
}
pub fn normalize(message: String) -> NormalizedMessage {
@@ -97,9 +98,7 @@ pub fn normalize(message: String) -> NormalizedMessage {
.collect();
let mut normalized = String::with_capacity(message.len());
let mut mappings = HashMap::new();
let mut last_i = 0;
let mut mappings = Vec::new();
for (i, mut ch) in message
.grapheme_indices(true)
@@ -111,18 +110,12 @@ pub fn normalize(message: String) -> NormalizedMessage {
let unidecoded = unidecode(&ch);
let ui_start = normalized.len();
let ui_end = ui_start + unidecoded.len();
if unidecoded.chars().all(|c| c.is_ascii_alphanumeric()) {
// If the character is alphanumeric, we can keep it.
normalized.push_str(&unidecoded);
mappings.insert((last_i, i), Some((ui_start, ui_end)));
} else {
mappings.insert((last_i, i), None);
for char in unidecoded.chars() {
if char.is_alphanumeric() {
normalized.push(char);
mappings.push(i);
}
}
last_i = i;
}
NormalizedMessage {
@@ -170,10 +163,20 @@ pub fn analyze_message(message: &str) -> Vec<(Vec<String>, Arc<dyn Rule>)> {
results
}
pub fn censor_message(original: &str, normalized: NormalizedMessage, analysis: &[(Vec<String>, Arc<dyn Rule>)]) -> String {
let mut censored = String::with_capacity(original.len());
pub fn censor_message(
original: &str,
normalized: NormalizedMessage,
analysis: &[(Vec<String>, Arc<dyn Rule>)],
) -> String {
let mut censored = original.to_string();
todo!();
for (findings, rule) in analysis {
for finding in findings {
while let Some(start) = normalized.message.find(finding) {
let end = start + finding.len();
}
}
}
censored
}