rust/chat_sanitizer/src/lib.rs
author Wuzzy <Wuzzy2@mail.ru>
Sat, 18 May 2019 16:55:27 +0200
changeset 15003 d84136589c04
parent 14505 ba29aa03db87
permissions -rw-r--r--
Backed out changeset 6a928999fefd (onPreciseLocal causes desyncs)
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
}