Add leaderboard command and XP winning system

This commit is contained in:
2025-08-21 02:14:56 -03:00
parent 4563c49245
commit 0318f002fc
11 changed files with 281 additions and 36 deletions
+13 -3
View File
@@ -83,7 +83,7 @@
//!
//! All of which would be detected.
use std::{collections::HashMap, sync::Arc};
use std::{collections::HashMap, fmt::Debug, sync::Arc};
use itertools::Itertools;
use linkify::LinkFinder;
@@ -128,6 +128,7 @@ pub fn escape_message(event: &Message) -> (String, Vec<Arc<dyn Rule>>) {
let (censored, rules) = moderate_message(&message);
log::debug!("Escaped and normalized message: {censored:?}");
log::debug!("Rules broken: {rules:?}");
(censored, rules)
}
@@ -377,7 +378,7 @@ pub enum Action {
/// Trait implemented by all rules.
#[allow(dead_code)]
pub trait Rule: Send + Sync {
pub trait Rule: Send + Sync + Debug {
/// The rule's human-readable name.
fn name(&self) -> &'static str;
@@ -447,6 +448,7 @@ fn find_with_exceptions(message: &str, pattern: &Regex, exceptions: &[String]) -
.collect()
}
#[derive(Debug)]
struct HateSpeechAndSlursRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -483,6 +485,7 @@ impl Rule for HateSpeechAndSlursRule {
}
}
#[derive(Debug)]
struct ThreatsAndSelfHarmRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -519,6 +522,7 @@ impl Rule for ThreatsAndSelfHarmRule {
}
}
#[derive(Debug)]
struct ExplicitSexualLanguageRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -555,6 +559,7 @@ impl Rule for ExplicitSexualLanguageRule {
}
}
#[derive(Debug)]
struct ExplicitSexualLanguageTypoRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -591,6 +596,7 @@ impl Rule for ExplicitSexualLanguageTypoRule {
}
}
#[derive(Debug)]
struct SuggestiveLanguageRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -627,6 +633,7 @@ impl Rule for SuggestiveLanguageRule {
}
}
#[derive(Debug)]
struct AdvertisingRule;
impl Rule for AdvertisingRule {
@@ -656,6 +663,7 @@ impl Rule for AdvertisingRule {
}
}
#[derive(Debug)]
struct SensitiveTopicsAndTriggeringContentRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -693,6 +701,7 @@ impl Rule for SensitiveTopicsAndTriggeringContentRule {
}
}
#[derive(Debug)]
pub struct MildSwearWordsRule {
pattern: Regex,
exceptions: Vec<String>,
@@ -728,6 +737,7 @@ impl Rule for MildSwearWordsRule {
}
}
#[derive(Debug)]
pub struct CasualInsultsAndTeasing {
pattern: Regex,
exceptions: Vec<String>,
@@ -763,7 +773,7 @@ impl Rule for CasualInsultsAndTeasing {
)
}
}
#[derive(Debug)]
struct LinksRule;
impl Rule for LinksRule {