Add InteractionRunner to on_interaction_handlers

This commit is contained in:
2025-08-12 23:15:52 -03:00
parent 0cdbe63c55
commit 09b875da97
2 changed files with 11 additions and 15 deletions
+3 -3
View File
@@ -7,13 +7,13 @@ use twilight_http::Client;
use crate::{ use crate::{
framework::{ framework::{
commands::{Command, runner::CommandRunner}, commands::{runner::CommandRunner, Command},
events::traits::{ events::traits::{
OnInteractionHandler, OnMessageDeleteHandler, OnMessageEditHandler, OnMessageHandler, OnInteractionHandler, OnMessageDeleteHandler, OnMessageEditHandler, OnMessageHandler,
OnReadyHandler, OnReconnectHandler, OnServerCreateHandler, OnServerDeleteHandler, OnReadyHandler, OnReconnectHandler, OnServerCreateHandler, OnServerDeleteHandler,
OnServerUpdateHandler, OnServerUpdateHandler,
}, },
interactions::{components::Component, registry::ComponentRegistry}, interactions::{components::Component, registry::ComponentRegistry, runner::InteractionRunner},
runtime::Runtime, runtime::Runtime,
}, },
utils::Bye, utils::Bye,
@@ -97,7 +97,7 @@ impl<T: 'static + Send + Sync> Bot<T> {
components: Vec::new(), components: Vec::new(),
on_ready_handlers: Vec::new(), on_ready_handlers: Vec::new(),
on_reconnect_handlers: Vec::new(), on_reconnect_handlers: Vec::new(),
on_interaction_handlers: Vec::new(), on_interaction_handlers: vec![Arc::new(InteractionRunner)],
on_message_handlers: vec![Arc::new(CommandRunner)], on_message_handlers: vec![Arc::new(CommandRunner)],
on_message_edit_handlers: Vec::new(), on_message_edit_handlers: Vec::new(),
on_message_delete_handlers: Vec::new(), on_message_delete_handlers: Vec::new(),
+8 -12
View File
@@ -3,24 +3,20 @@ use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use twilight_model::gateway::payload::incoming::InteractionCreate; use twilight_model::gateway::payload::incoming::InteractionCreate;
use crate::{ use crate::framework::{
framework::{ events::traits::{EventResult, OnInteractionHandler},
events::traits::{EventResult, OnInteractionHandler}, runtime::Runtime,
runtime::Runtime,
},
state::State,
}; };
#[derive(Debug)] #[derive(Debug)]
pub struct InteractionRunner; pub struct InteractionRunner;
#[async_trait] #[async_trait]
impl OnInteractionHandler<State> for InteractionRunner { impl<T> OnInteractionHandler<T> for InteractionRunner
async fn on_interaction( where
&self, T: Send + Sync + 'static,
event: &InteractionCreate, {
rt: Arc<Runtime<State>>, async fn on_interaction(&self, event: &InteractionCreate, rt: Arc<Runtime<T>>) -> EventResult {
) -> EventResult {
Ok(rt.registry.execute(event, rt.clone()).await?) Ok(rt.registry.execute(event, rt.clone()).await?)
} }
} }