rust/chat_sanitizer/src/lib.rs
author sheepluva
Sat, 04 Jul 2020 22:18:54 +0200
changeset 15667 02042ee48fde
parent 14505 ba29aa03db87
permissions -rw-r--r--
fix accidential resurrection of removed code of merge 63e2b7b2ec47 code was originally removed in 93429d8f6b3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14503
831ecafd74c6 Start chat_sanitizer package inspired by chat bot on pokerth server
unc0rr
parents:
diff changeset
     1
pub mod bad_words;
14505
ba29aa03db87 Implement letter repeat check
unc0rr
parents: 14503
diff changeset
     2
pub mod letter_repeat;
14503
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
}