use std::error::Error;
use std::fmt;
use futures::future::BoxFuture;
use crate::client::Context;
use crate::framework::standard::{Args, CommandOptions};
use crate::model::channel::Message;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Reason {
Unknown,
User(String),
Log(String),
UserAndLog { user: String, log: String },
}
impl Error for Reason {}
pub type CheckFunction = for<'fut> fn(
&'fut Context,
&'fut Message,
&'fut mut Args,
&'fut CommandOptions,
) -> BoxFuture<'fut, Result<(), Reason>>;
pub struct Check {
pub name: &'static str,
pub function: CheckFunction,
pub check_in_help: bool,
pub display_in_help: bool,
}
impl fmt::Debug for Check {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Check")
.field("name", &self.name)
.field("function", &"<fn>")
.field("check_in_help", &self.check_in_help)
.field("display_in_help", &self.display_in_help)
.finish()
}
}
impl fmt::Display for Reason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unknown => f.write_str("Unknown"),
Self::User(reason) => write!(f, "User {reason}"),
Self::Log(reason) => write!(f, "Log {reason}"),
Self::UserAndLog {
user,
log,
} => {
write!(f, "UserAndLog {{user: {user}, log: {log}}}")
},
}
}
}
impl PartialEq for Check {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}