rust/chat_sanitizer/src/lib.rs
author Wuzzy <Wuzzy2@mail.ru>
Mon, 30 Sep 2019 16:02:39 +0200
changeset 15443 e7c059ac6e54
parent 14510 ba29aa03db87
permissions -rw-r--r--
Frontend: Increase user name length to 40 to keep it consistent with server

pub mod bad_words;
pub mod letter_repeat;

use unicode_skeleton::UnicodeSkeleton;

#[derive(PartialEq, Debug)]
enum Severity {
    Pass,
    Warn,
    Silence,
    Ban,
}

trait MessageChecker<T> {
    fn check(&self, player_id: T, message: &str) -> Severity;
    fn fix(&self, player_id: T, message: &str) -> Option<String> {
        None
    }
}

fn normalized_message(s: &str) -> String {
    s.chars()
        .flat_map(|c| c.to_lowercase())
        .skeleton_chars()
        .collect::<String>()
}