Finish adding call rule detectors

Missing language detectors (whatlang and lingua have terrible accuracy for short messages) and more words and phrases to the lists
This commit is contained in:
2025-08-15 02:25:37 -03:00
parent 77182d9633
commit 281542a5c2
3 changed files with 141 additions and 3 deletions
+6 -1
View File
@@ -8,4 +8,9 @@ fuh
fuck you
f u
f you
fuck u
fuck u
damn
dmn
shit
sht
ass
@@ -0,0 +1 @@
blood
+134 -2
View File
@@ -13,7 +13,7 @@
//! | 5 | Suggestive language | "slap your ass", "sexy" | Block immediately + penalty |
//! | 6 | Advertising | "discord.gg/payphone" | Block immediately + penalty |
//! | 7 | Sensitive topics and triggering content | "blood", "knife", "suicide method" | Block immediately + penalty |
//! | 8 | Non-english chats | | Block immediately + penalty |
//! | 8 | Non-english chats | | Soft censor + warn |
//! | 9 | E-dating | "let me hit" | Block immediately + penalty |
//! | 10 | Mild swear words | "damn", "shit", "ass" | Soft censor + warn |
//! | 11 | Casual insults and teasing | "stupid", "dumb" | Soft censor + warn |
@@ -551,6 +551,134 @@ impl Rule for SuggestiveLanguageRule {
}
}
struct AdvertisingRule;
impl Rule for AdvertisingRule {
fn name(&self) -> &'static str {
"Advertising"
}
fn action(&self) -> &'static Action {
&Action::BlockAndPenalty
}
fn detect(&self, original: &str, _normalized: &str) -> (Vec<String>, Vec<String>) {
let mut detections = Vec::new();
for link in LinkFinder::new()
.url_must_have_scheme(false)
.links(original)
{
let link_str = link.as_str();
if link_str.contains("discord.gg") || link_str.contains("discord.com") {
detections.push(link_str.to_string());
}
}
(detections, vec![])
}
}
struct SensitiveTopicsAndTriggeringContentRule(Regex);
impl SensitiveTopicsAndTriggeringContentRule {
fn new() -> Self {
let phrases: Vec<&str> = parse_phrases_file(include_str!(
"lists/sensitive-topics-and-triggering-content.txt"
));
let regex = regex_from_phrases_list(&phrases);
Self(regex)
}
}
impl Rule for SensitiveTopicsAndTriggeringContentRule {
fn name(&self) -> &'static str {
"Sensitive Topics and Triggering Content"
}
fn action(&self) -> &'static Action {
&Action::BlockAndPenalty
}
fn detect(&self, _original: &str, normalized: &str) -> (Vec<String>, Vec<String>) {
(
vec![],
self.0
.find_iter(normalized)
.map(|m| normalized[m.start()..m.end()].to_string())
.collect(),
)
}
}
pub struct MildSwearWordsRule(Regex);
impl MildSwearWordsRule {
fn new() -> Self {
let phrases: Vec<&str> = parse_phrases_file(include_str!("lists/mild-swear-words.txt"));
let regex = regex_from_phrases_list(&phrases);
Self(regex)
}
}
impl Rule for MildSwearWordsRule {
fn name(&self) -> &'static str {
"Mild Swear Words"
}
fn action(&self) -> &'static Action {
&Action::SoftCensorAndWarn
}
fn detect(&self, _original: &str, normalized: &str) -> (Vec<String>, Vec<String>) {
(
vec![],
self.0
.find_iter(normalized)
.map(|m| normalized[m.start()..m.end()].to_string())
.collect(),
)
}
}
pub struct CasualInsultsAndTeasing(Regex);
impl CasualInsultsAndTeasing {
fn new() -> Self {
let phrases: Vec<&str> =
parse_phrases_file(include_str!("lists/casual-insults-and-teasing.txt"));
let regex = regex_from_phrases_list(&phrases);
Self(regex)
}
}
impl Rule for CasualInsultsAndTeasing {
fn name(&self) -> &'static str {
"Casual Insults and Teasing"
}
fn action(&self) -> &'static Action {
&Action::SoftCensorAndWarn
}
fn detect(&self, _original: &str, normalized: &str) -> (Vec<String>, Vec<String>) {
(
vec![],
self.0
.find_iter(normalized)
.map(|m| normalized[m.start()..m.end()].to_string())
.collect(),
)
}
}
struct LinksRule;
impl Rule for LinksRule {
@@ -581,8 +709,12 @@ pub static RULES: Lazy<Vec<Arc<dyn Rule>>> = Lazy::new(|| {
vec![
Arc::new(HateSpeechAndSlursRule::new()),
Arc::new(ThreatsAndSelfHarmRule::new()),
Arc::new(SuggestiveLanguageRule::new()),
Arc::new(ExplicitSexualLanguageRule::new()),
Arc::new(SuggestiveLanguageRule::new()),
Arc::new(AdvertisingRule),
Arc::new(SensitiveTopicsAndTriggeringContentRule::new()),
Arc::new(MildSwearWordsRule::new()),
Arc::new(CasualInsultsAndTeasing::new()),
Arc::new(LinksRule),
]
});