Skip to main content

tulpje_framework/handler/
component_interaction_handler.rs

1use std::{future::Future, pin::Pin};
2
3use super::super::context::ComponentInteractionContext;
4use crate::Error;
5
6pub(crate) type ComponentInteractionFunc<T> =
7    fn(ComponentInteractionContext<T>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
8
9#[derive(Clone)]
10pub struct ComponentInteractionHandler<T: Clone + Send + Sync> {
11    pub module: String,
12    pub custom_id: String,
13    pub func: ComponentInteractionFunc<T>,
14}
15
16impl<T: Clone + Send + Sync> ComponentInteractionHandler<T> {
17    #[tracing::instrument(name="component-interaction-handler", skip_all, fields(
18        module=self.module,
19        custom_id=self.custom_id
20    ))]
21    pub async fn run(&self, ctx: ComponentInteractionContext<T>) -> Result<(), Error> {
22        // can add more handling/parsing/etc here in the future
23        (self.func)(ctx).await
24    }
25}