rust/chat_sanitizer/src/lib.rs
author sheepluva
Sun, 08 Dec 2019 02:09:19 +0100
branchhedgeroid
changeset 15520 de08a3ae4f8d
parent 14510 ba29aa03db87
permissions -rw-r--r--
hedgeroid/frontlib: update proto and weapons number
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14508
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     1
pub mod bad_words;
14510
ba29aa03db87 Implement letter repeat check
unc0rr
parents: 14508
diff changeset
     2
pub mod letter_repeat;
14508
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     3
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     4
use unicode_skeleton::UnicodeSkeleton;
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     5
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     6
#[derive(PartialEq, Debug)]
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     7
enum Severity {
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     8
    Pass,
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     9
    Warn,
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    10
    Silence,
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    11
    Ban,
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    12
}
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    13
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    14
trait MessageChecker<T> {
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    15
    fn check(&self, player_id: T, message: &str) -> Severity;
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    16
    fn fix(&self, player_id: T, message: &str) -> Option<String> {
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    17
        None
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    18
    }
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    19
}
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    20
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    21
fn normalized_message(s: &str) -> String {
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    22
    s.chars()
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    23
        .flat_map(|c| c.to_lowercase())
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    24
        .skeleton_chars()
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    25
        .collect::<String>()
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
    26
}