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
+19 -13
View File
@@ -8,20 +8,20 @@ use twilight_model::channel::message::{
use crate::framework::interactions::{InteractionError, context::InteractionContext};
type ComponentWithID<T> = (Option<String>, Arc<dyn Component<T>>);
type ComponentWithID<T, E> = (Option<String>, Arc<dyn Component<T, E>>);
pub struct ActionRow<T> {
components: Vec<ComponentWithID<T>>,
pub struct ActionRow<T, E> {
components: Vec<ComponentWithID<T, E>>,
}
impl<T> ActionRow<T> {
pub fn new(components: &[ComponentWithID<T>]) -> Self {
impl<T, E> ActionRow<T, E> {
pub fn new(components: &[ComponentWithID<T, E>]) -> Self {
Self {
components: components.to_vec(),
}
}
pub fn add(&mut self, id: Option<String>, component: Arc<dyn Component<T>>) {
pub fn add(&mut self, id: Option<String>, component: Arc<dyn Component<T, E>>) {
self.components.push((id, component));
}
@@ -41,19 +41,21 @@ impl<T> ActionRow<T> {
}
#[async_trait]
pub trait Component<T>: Send + Sync + Debug {
pub trait Component<T, E>: Send + Sync + Debug {
fn custom_id(&self) -> Option<String> {
Some(String::from("component"))
}
fn build(&self, id: Option<String>) -> TwilightComponent;
async fn execute(&self, ctx: InteractionContext<T>) -> Result<(), InteractionError>;
async fn execute(&self, ctx: InteractionContext<T, E>) -> Result<(), InteractionError>;
}
#[async_trait]
impl<T, S: Send + Sync + 'static> Component<S> for T
impl<T, S, E> Component<S, E> for T
where
T: Button<S>,
T: Button<S, E>,
S: Send + Sync + 'static,
E: Send + Sync + 'static,
{
fn custom_id(&self) -> Option<String> {
Button::id(self)
@@ -75,13 +77,17 @@ where
})
}
async fn execute(&self, ctx: InteractionContext<S>) -> Result<(), InteractionError> {
async fn execute(&self, ctx: InteractionContext<S, E>) -> Result<(), InteractionError> {
self.on_press(ctx).await
}
}
#[async_trait]
pub trait Button<S: Send + Sync + 'static>: Send + Sync + Debug {
pub trait Button<S, E>: Send + Sync + Debug
where
S: Send + Sync + 'static,
E: Send + Sync + 'static,
{
fn id(&self) -> Option<String> {
if self.url().is_none() {
Some(String::from("Button"))
@@ -99,7 +105,7 @@ pub trait Button<S: Send + Sync + 'static>: Send + Sync + Debug {
None
}
async fn on_press(&self, ctx: InteractionContext<S>) -> Result<(), InteractionError> {
async fn on_press(&self, ctx: InteractionContext<S, E>) -> Result<(), InteractionError> {
ctx.defer().await
}
}