Add support for extras, conditionally displaying commands in the help command, and start working on moderation commands

This commit is contained in:
2025-08-22 18:06:52 -03:00
parent 55ae1c8937
commit 8868b18be3
41 changed files with 1075 additions and 368 deletions
+15 -9
View File
@@ -5,12 +5,13 @@ use deadpool_redis::{cluster::PoolError, redis::RedisError};
use thiserror::Error;
use twilight_http::response::DeserializeBodyError;
use crate::framework::commands::{
use crate::framework::{commands::{
arguments::Argument, context::CommandContext, permissions::Permission,
};
}, runtime::Runtime};
pub mod arguments;
pub mod context;
pub mod extras;
pub mod messages;
pub mod permissions;
pub mod runner;
@@ -21,7 +22,7 @@ pub enum CommandError {
MessageSendingFailed,
#[error("A database query failed")]
DatabaseQueryFailed,
DatabaseFailed,
#[error("A database operation failed due to an inconsistent state")]
DatabaseInconsistentState,
@@ -35,9 +36,6 @@ pub enum CommandError {
#[error(transparent)]
DiscordDeserializationFailed(#[from] DeserializeBodyError),
#[error("The cache's state was inconsistent.")]
CacheStateInconsistent,
#[error(transparent)]
RedisPoolFailed(#[from] PoolError),
@@ -46,21 +44,29 @@ pub enum CommandError {
}
#[async_trait]
pub trait Command<T>: Send + Sync + Debug {
pub trait Command<T, E>: Send + Sync + Debug {
fn name(&self) -> &'static str;
fn aliases(&self) -> &'static [&'static str] {
&[]
}
fn description(&self) -> &'static str {
"A Payphone command."
}
fn arguments(&self) -> &'static [Argument] {
&[]
}
fn permissions(&self) -> Vec<Box<dyn Permission<T> + Send + Sync + 'static>> {
fn permissions(&self) -> Vec<Box<dyn Permission<T, E> + Send + Sync + 'static>> {
vec![]
}
fn show_in_help(&self, rt: &Runtime<T, E>, extras: &E) -> bool {
true
}
/// Returns the command name + all its aliases.
///
/// Returns:
@@ -71,7 +77,7 @@ pub trait Command<T>: Send + Sync + Debug {
all
}
async fn execute(&self, ctx: CommandContext<'_, T>, args: &str) -> Result<(), CommandError>;
async fn execute(&self, ctx: CommandContext<'_, T, E>, args: &str) -> Result<(), CommandError>;
}
pub struct CommandParts<'a> {