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 async_trait::async_trait;
|
||||||
use thiserror::Error;
|
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 arguments;
|
||||||
pub mod context;
|
pub mod context;
|
||||||
@@ -38,8 +38,8 @@ pub trait Command<T>: Send + Sync + Debug {
|
|||||||
fn arguments(&self) -> &'static [Argument] {
|
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.
|
/// Returns the command name + all its aliases.
|
||||||
|
|||||||
@@ -39,9 +39,7 @@ impl<T: Send + Sync + 'static> OnMessageHandler<T> for CommandRunner {
|
|||||||
.await
|
.await
|
||||||
.inspect_err(|e| log::error!("Permission check failed: {e}"))?
|
.inspect_err(|e| log::error!("Permission check failed: {e}"))?
|
||||||
{
|
{
|
||||||
return Err(
|
return Ok(());
|
||||||
format!("The check for permission {permission:?} failed").into()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ use twilight_model::id::Id;
|
|||||||
use crate::{
|
use crate::{
|
||||||
database::models::{Call, Channel},
|
database::models::{Call, Channel},
|
||||||
discord::sanitizing::SanitizeDiscordMarkdown,
|
discord::sanitizing::SanitizeDiscordMarkdown,
|
||||||
framework::commands::{Command, CommandError, context::CommandContext},
|
framework::commands::{
|
||||||
groups::calls::get_display_profile,
|
Command, CommandError, context::CommandContext, permissions::Permission,
|
||||||
|
},
|
||||||
|
groups::calls::{get_display_profile, permissions::NotBannedPermission},
|
||||||
state::State,
|
state::State,
|
||||||
utils::Bye,
|
utils::Bye,
|
||||||
};
|
};
|
||||||
@@ -38,6 +40,10 @@ impl Command<State> for CallCommand {
|
|||||||
&["c"]
|
&["c"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||||
|
vec![Box::new(NotBannedPermission)]
|
||||||
|
}
|
||||||
|
|
||||||
async fn execute(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
ctx: CommandContext<'_, State>,
|
ctx: CommandContext<'_, State>,
|
||||||
@@ -124,6 +130,10 @@ impl Command<State> for SkipCommand {
|
|||||||
&["s", "next"]
|
&["s", "next"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||||
|
vec![Box::new(NotBannedPermission)]
|
||||||
|
}
|
||||||
|
|
||||||
async fn execute(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
ctx: CommandContext<'_, State>,
|
ctx: CommandContext<'_, State>,
|
||||||
@@ -226,6 +236,10 @@ impl Command<State> for HangupCommand {
|
|||||||
&["h", "hang"]
|
&["h", "hang"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn permissions(&self) -> Vec<Box<dyn Permission<State> + Send + Sync + 'static>> {
|
||||||
|
vec![Box::new(NotBannedPermission)]
|
||||||
|
}
|
||||||
|
|
||||||
async fn execute(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
ctx: CommandContext<'_, State>,
|
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."
|
"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(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
ctx: CommandContext<'_, State>,
|
ctx: CommandContext<'_, State>,
|
||||||
|
|||||||
Reference in New Issue
Block a user