pikadick_slash_framework/
check.rs

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