rust/chat_sanitizer/src/bad_words.rs
changeset 14510 ba29aa03db87
parent 14508 831ecafd74c6
equal deleted inserted replaced
14509:6cc0fce249f9 14510:ba29aa03db87
    17         }
    17         }
    18     }
    18     }
    19 }
    19 }
    20 
    20 
    21 impl<T> MessageChecker<T> for BadWordsChecker<T> {
    21 impl<T> MessageChecker<T> for BadWordsChecker<T> {
    22     fn check(&self, player_id: T, message: &str) -> Severity {
    22     fn check(&self, _player_id: T, message: &str) -> Severity {
    23         let msg = normalized_message(message);
    23         let msg = normalized_message(message);
    24 
    24 
    25         // silly implementation, allows bad messages with a single good word
    25         // silly implementation, allows bad messages with a single good word
    26         for badword in &self.blacklist {
    26         for bad_word in &self.blacklist {
    27             if msg.contains(badword) {
    27             if msg.contains(bad_word) {
    28                 if !self.whitelist.iter().any(|goodword| msg.contains(goodword)) {
    28                 if !self
       
    29                     .whitelist
       
    30                     .iter()
       
    31                     .any(|good_word| msg.contains(good_word))
       
    32                 {
    29                     return Severity::Warn;
    33                     return Severity::Warn;
    30                 }
    34                 }
    31             }
    35             }
    32         }
    36         }
    33 
    37 
    46         assert_eq!(checker.check(0, "PooP"), Severity::Warn);
    50         assert_eq!(checker.check(0, "PooP"), Severity::Warn);
    47 
    51 
    48         // this one fails
    52         // this one fails
    49         //assert_eq!(checker.check(0, "poop 'fsck -y' poop"), Severity::Warn);
    53         //assert_eq!(checker.check(0, "poop 'fsck -y' poop"), Severity::Warn);
    50 
    54 
    51         // ideally this one shouldn't fail
    55         // ideally this one shouldn't fail, need a better confusables check
    52         // assert_eq!(checker.check(0, "P00P"), Severity::Warn);
    56         // assert_eq!(checker.check(0, "P00P"), Severity::Warn);
    53     }
    57     }
    54 }
    58 }