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
+14 -7
View File
@@ -8,6 +8,7 @@ use twilight_util::builder::embed::{
use crate::{
constants::{COLOR_RED, COLOR_WHITE},
discord::{images, sanitizing::SanitizeDiscordMarkdown},
extras::Extras,
framework::{
commands::{Command, context::CommandContext},
runtime::Runtime,
@@ -17,8 +18,8 @@ use crate::{
};
pub(super) fn get_command_help_embed(
command: &Arc<dyn Command<State>>,
ctx: &CommandContext<'_, State>,
command: &Arc<dyn Command<State, Extras>>,
ctx: &CommandContext<'_, State, Extras>,
) -> Embed {
let name = format!("{}{}", ctx.prefix, command.name());
let arguments = command
@@ -79,7 +80,11 @@ pub(super) fn get_command_help_embed(
.build()
}
pub(super) fn get_all_command_help_embed<T>(prefix: &str, rt: Arc<Runtime<T>>) -> Embed {
pub(super) fn get_all_command_help_embed(
prefix: &str,
rt: &Runtime<State, Extras>,
extras: &Extras,
) -> Embed {
EmbedBuilder::new()
.author(EmbedAuthorBuilder::new(rt.app.name.clone()).icon_url(ImageSource::url(images::get_avatar_url(
rt.app.bot.as_ref().unwrap().avatar,
@@ -96,22 +101,24 @@ pub(super) fn get_all_command_help_embed<T>(prefix: &str, rt: Arc<Runtime<T>>) -
))
.unwrap())
.color(COLOR_WHITE)
.field(EmbedFieldBuilder::new("Commands", get_commands_table(rt)).build())
.field(EmbedFieldBuilder::new("Commands", get_commands_table(rt, extras)).build())
.footer(EmbedFooterBuilder::new(format!("v{} - Use {}help <command> to get more information about a specific command.", env!("CARGO_PKG_VERSION"), prefix)))
.build()
}
pub(super) fn get_commands_table<T>(rt: Arc<Runtime<T>>) -> String {
pub(super) fn get_commands_table<T>(rt: &Runtime<T, Extras>, extras: &Extras) -> String {
let mut table = String::new();
for command in rt.commands.iter() {
table.push_str(&format!("{:<12}", command.name()));
if command.show_in_help(rt, extras) {
table.push_str(&format!("{:<13}", command.name()));
}
}
format!("```\n{table}\n```")
}
pub(super) fn get_command_not_found_embed<T>(rt: Arc<Runtime<T>>, name: String) -> Embed {
pub(super) fn get_command_not_found_embed<T>(rt: &Runtime<T, Extras>, name: String) -> Embed {
EmbedBuilder::new()
.color(COLOR_RED)
.author(EmbedAuthorBuilder::new(rt.app.name.clone()).icon_url(ImageSource::url(images::get_avatar_url(