Make permissions checking and notification separate functions
This commit is contained in:
@@ -7,4 +7,8 @@ use crate::framework::commands::{CommandError, context::CommandContext};
|
||||
#[async_trait]
|
||||
pub trait Permission<S: Send + Sync + 'static>: Debug {
|
||||
async fn check(&self, ctx: &CommandContext<S>) -> Result<bool, CommandError>;
|
||||
|
||||
async fn on_handle_denied(&self, _ctx: &CommandContext<S>) -> Result<(), CommandError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ impl<T: Send + Sync + 'static> OnMessageHandler<T> for CommandRunner {
|
||||
.await
|
||||
.inspect_err(|e| log::error!("Permission check failed: {e}"))?
|
||||
{
|
||||
permission.on_handle_denied(&ctx).await?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user