Skip to content

Commit

Permalink
fix 4
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover authored Apr 23, 2024
1 parent 45d2fad commit 3bcba83
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/user/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ impl GlassModeration {
/// If the user is muted, it returns an error.
pub fn process(&self, input: &str) -> Result<&str, Box<dyn Error>> {
if self.is_muted { return Err("User is muted".into()); }

let (censored, analysis) = Censor::from_str(input)
.with_censor_threshold(Type::SEVERE)
.with_censor_first_character_threshold(Type::OFFENSIVE & Type::SEVERE)
.with_ignore_false_positives(false)
.with_ignore_self_censoring(false)
.with_censor_replacement('*')
.censor_and_analyze();

if analysis.is(Type::OFFENSIVE & Type::SEVERE) {
self.warn();
Err("Message is inappropriate".into())
Expand All @@ -61,7 +63,7 @@ impl GlassModeration {
}

/// Warns the user, adding a report if there are 5 warnings.
pub fn warn(&self) {
pub fn warn(&mut self) {
self.warnings += 1;
if self.warnings >= 5 {
self.warnings = 0;
Expand All @@ -70,16 +72,16 @@ impl GlassModeration {
}

/// Reports the user, muting them if there are 10 warnings.
pub fn report(&self) {
pub fn report(&mut self) {
self.reports += 1;
if self.reports >= 10 {
self.is_muted = true;
}
}

/// Mutes the user.
pub fn mute(&self) { self.is_muted = true; }
pub fn mute(&mut self) { self.is_muted = true; }

/// Unmutes the user.
pub fn unmute(&self) { self.is_muted = false; }
pub fn unmute(&mut self) { self.is_muted = false; }
}

0 comments on commit 3bcba83

Please sign in to comment.