1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
use crate::{
BoxFuture,
Command,
};
use serenity::{
client::Context,
model::application::CommandInteraction,
};
pub type CheckFn = for<'a> fn(
&'a Context,
&'a CommandInteraction,
&'a Command,
) -> BoxFuture<'a, Result<(), Reason>>;
/// the reason a check failed
pub struct Reason {
/// The user-facing reason for a failure
pub user: Option<String>,
/// Info for logging
pub log: Option<String>,
}
impl Reason {
/// Create a new reason where nothing is known
pub fn new_unknown() -> Self {
Self {
user: None,
log: None,
}
}
/// Create a new reason that has user data
pub fn new_user<S>(user: S) -> Self
where
S: Into<String>,
{
Self {
user: Some(user.into()),
log: None,
}
}
}