Prevent banned users from using call commands
This commit is contained in:
@@ -3,7 +3,7 @@ use std::fmt::Debug;
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::framework::commands::{arguments::Argument, context::CommandContext};
|
||||
use crate::framework::commands::{arguments::Argument, context::CommandContext, permissions::Permission};
|
||||
|
||||
pub mod arguments;
|
||||
pub mod context;
|
||||
@@ -38,8 +38,8 @@ pub trait Command<T>: Send + Sync + Debug {
|
||||
fn arguments(&self) -> &'static [Argument] {
|
||||
&[]
|
||||
}
|
||||
fn permissions(&self) -> &'static [Box<dyn permissions::Permission<T> + Send + Sync>] {
|
||||
&[]
|
||||
fn permissions(&self) -> Vec<Box<dyn Permission<T> + Send + Sync + 'static>> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
/// Returns the command name + all its aliases.
|
||||
|
||||
@@ -39,9 +39,7 @@ impl<T: Send + Sync + 'static> OnMessageHandler<T> for CommandRunner {
|
||||
.await
|
||||
.inspect_err(|e| log::error!("Permission check failed: {e}"))?
|
||||
{
|
||||
return Err(
|
||||
format!("The check for permission {permission:?} failed").into()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ use twilight_model::id::Id;
|
||||
use crate::{
|
||||
database::models::{Call, Channel},
|
||||
discord::sanitizing::SanitizeDiscordMarkdown,
|
||||
framework::commands::{Command, CommandError, context::CommandContext},
|
||||
groups::calls::get_display_profile,
|
||||
framework::commands::{
|
||||
Command, CommandError, context::CommandContext, permissions::Permission,
|
||||
},
|
||||
groups::calls::{get_display_profile, permissions::NotBannedPermission},
|
||||
state::State,
|
||||
utils::Bye,
|
||||
};
|
||||
@@ -38,6 +40,10 @@ impl Command<State> for CallCommand {
|
||||
&["c"]
|
||||
}
|
||||
|
||||
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||
vec![Box::new(NotBannedPermission)]
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
ctx: CommandContext<'_, State>,
|
||||
@@ -124,6 +130,10 @@ impl Command<State> for SkipCommand {
|
||||
&["s", "next"]
|
||||
}
|
||||
|
||||
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||
vec![Box::new(NotBannedPermission)]
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
ctx: CommandContext<'_, State>,
|
||||
@@ -226,6 +236,10 @@ impl Command<State> for HangupCommand {
|
||||
&["h", "hang"]
|
||||
}
|
||||
|
||||
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||
vec![Box::new(NotBannedPermission)]
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
ctx: CommandContext<'_, State>,
|
||||
@@ -324,6 +338,10 @@ impl Command<State> for FriendRequestCommand {
|
||||
"Shows your username to the other party and asks them to send you a friend request on Discord."
|
||||
}
|
||||
|
||||
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||
vec![Box::new(NotBannedPermission)]
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
ctx: CommandContext<'_, State>,
|
||||
|
||||
Reference in New Issue
Block a user