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    pub async fn run(&self, ctx: ComponentInteractionContext<T>) -> Result<(), Error> {
18        // can add more handling/parsing/etc here in the future
19        (self.func)(ctx).await
20    }
21}