pub struct Context { /* private fields */ }context only.Expand description
Context is useful for taking moderation actions on a per-user basis i.e. each user would get their own Context.
§Recommendation
Use this as a reference implementation e.g. by copying and adapting it.
Implementations§
Source§impl Context
impl Context
pub fn new() -> Self
Sourcepub fn process(&mut self, message: String) -> Result<String, BlockReason>
pub fn process(&mut self, message: String) -> Result<String, BlockReason>
Takes user message, returns censored message trimmed of whitespace (if it should be sent)
or BlockReason (explaining why it should be blocked entirely).
Sourcepub fn process_with_options(
&mut self,
message: String,
options: &ContextProcessingOptions,
) -> Result<String, BlockReason>
pub fn process_with_options( &mut self, message: String, options: &ContextProcessingOptions, ) -> Result<String, BlockReason>
Takes user message, returns censored message trimmed of whitespace (if it should be sent)
or BlockReason (explaining why it should be blocked entirely).
Takes a set of options for fine-tuning the processing.
Sourcepub fn muted_for(&self) -> Duration
pub fn muted_for(&self) -> Duration
Returns how long the user is muted for (possibly Duration::ZERO).
Sourcepub fn last_message(&self) -> Option<Instant>
pub fn last_message(&self) -> Option<Instant>
Returns the instant of the last processed message.
Sourcepub fn muted_until(&self) -> Option<Instant>
pub fn muted_until(&self) -> Option<Instant>
Returns the latest instant the user is muted (possibly in the past).
Sourcepub fn restricted_for(&self) -> Duration
pub fn restricted_for(&self) -> Duration
Returns how long the user is restricted to Type::SAFE for (possibly Duration::ZERO).
Sourcepub fn restricted_until(&self) -> Option<Instant>
pub fn restricted_until(&self) -> Option<Instant>
Returns the latest instant the user is restricted (possibly in the past).
Sourcepub fn mute_for(&mut self, duration: Duration)
pub fn mute_for(&mut self, duration: Duration)
Manually mute this user’s messages for a duration. Overwrites any previous manual mute.
Passing Duration::ZERO will therefore un-mute.
Sourcepub fn mute_until(&mut self, instant: Instant)
pub fn mute_until(&mut self, instant: Instant)
Manually mute this user’s messages until an instant. Overwrites any previous manual mute. Passing an instant in the past will therefore un-mute.
Sourcepub fn restrict_for(&mut self, duration: Duration)
pub fn restrict_for(&mut self, duration: Duration)
Manually restrict this user’s messages to known safe phrases for a duration. Overwrites any
previous manual restriction. Passing Duration::ZERO will therefore un-restrict.
Sourcepub fn restrict_until(&mut self, instant: Instant)
pub fn restrict_until(&mut self, instant: Instant)
Manually restrict this user’s messages to known safe phrases until an instant. Overwrites any previous manual restriction. Passing an instant in the past will therefore un-restrict.
Sourcepub fn report(&mut self)
pub fn report(&mut self)
Call if another user “reports” this user’s message(s). The function of reports is for suspicion of bad behavior to be confirmed faster.
Sourcepub fn reports(&self) -> usize
pub fn reports(&self) -> usize
Returns number of reports received via Self::report(). It is not guaranteed that the full
range of usize of reports will be counted (currently only u8::MAX are counted).
Sourcepub fn exonerate(&mut self)
pub fn exonerate(&mut self)
Clear suspicion, reports, inappropriate counter, and automatic mutes (not manual mute or rate limit).
Sourcepub fn total(&self) -> usize
pub fn total(&self) -> usize
Returns total number of messages processed. It is not guaranteed that the full
range of usize of messages will be counted (currently only u16::MAX are counted).
Sourcepub fn total_inappropriate(&self) -> usize
pub fn total_inappropriate(&self) -> usize
Returns total number of messages processed that were Type::INAPPROPRIATE. It is not
guaranteed that the full range of usize of messages will be counted (currently only
u16::MAX are counted).