tulpje_framework/
context.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::sync::Arc;

use twilight_http::{client::InteractionClient, Client};
use twilight_model::id::{marker::ApplicationMarker, Id};

pub mod autocomplete_context;
pub mod command_context;
pub mod component_interaction_context;
pub mod event_context;
pub mod modal_context;
pub mod task_context;

pub use command_context::CommandContext;
pub use component_interaction_context::ComponentInteractionContext;
pub use event_context::EventContext;
pub use modal_context::ModalContext;
pub use task_context::TaskContext;

#[derive(Debug)]
pub struct Context<T: Clone + Send + Sync> {
    pub application_id: Id<ApplicationMarker>,
    pub services: Arc<T>,
    pub client: Arc<Client>,
}

impl<T: Clone + Send + Sync> Context<T> {
    pub fn interaction(&self) -> InteractionClient<'_> {
        self.client.interaction(self.application_id)
    }
}

impl<T: Clone + Send + Sync> Clone for Context<T> {
    fn clone(&self) -> Self {
        Self {
            application_id: self.application_id,
            services: Arc::clone(&self.services),
            client: Arc::clone(&self.client),
        }
    }
}

pub enum InteractionContext<T: Clone + Send + Sync> {
    Command(CommandContext<T>),
    ComponentInteraction(ComponentInteractionContext<T>),
    Modal(ModalContext<T>),
}