Struct rustrict::Context

source ·
pub struct Context { /* private fields */ }
Expand description

Context is useful for taking moderation actions on a per-user basis i.e. each user would get their own Context.

Implementations§

source§

impl Context

source

pub fn new() -> Self

source

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).

source

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.

source

pub fn muted_for(&self) -> Duration

Returns how long the user is muted for (possibly Duration::ZERO).

source

pub fn muted_until(&self) -> Option<Instant>

Returns the latest instant the user is muted (possibly in the past).

source

pub fn restricted_for(&self) -> Duration

Returns how long the user is restricted to Type::SAFE for (possibly Duration::ZERO).

source

pub fn restricted_until(&self) -> Option<Instant>

Returns the latest instant the user is restricted (possibly in the past).

source

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.

source

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.

source

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.

source

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.

source

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.

source

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).

source

pub fn exonerate(&mut self)

Clear suspicion and reports, and automatic mutes (not manual mute or rate limit).

source

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).

source

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).

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Context

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.