tulpje_framework/
context.rs

1use std::sync::Arc;
2
3use twilight_http::{Client, client::InteractionClient};
4use twilight_model::id::{Id, marker::ApplicationMarker};
5
6pub mod autocomplete_context;
7pub mod command_context;
8pub mod component_interaction_context;
9pub mod event_context;
10pub mod modal_context;
11pub mod task_context;
12
13pub use command_context::CommandContext;
14pub use component_interaction_context::ComponentInteractionContext;
15pub use event_context::EventContext;
16pub use modal_context::ModalContext;
17pub use task_context::TaskContext;
18
19#[derive(Debug)]
20pub struct Context<T: Clone + Send + Sync> {
21    pub application_id: Id<ApplicationMarker>,
22    pub services: Arc<T>,
23    pub client: Arc<Client>,
24}
25
26impl<T: Clone + Send + Sync> Context<T> {
27    pub fn interaction(&self) -> InteractionClient<'_> {
28        self.client.interaction(self.application_id)
29    }
30}
31
32impl<T: Clone + Send + Sync> Clone for Context<T> {
33    fn clone(&self) -> Self {
34        Self {
35            application_id: self.application_id,
36            services: Arc::clone(&self.services),
37            client: Arc::clone(&self.client),
38        }
39    }
40}
41
42pub enum InteractionContext<T: Clone + Send + Sync> {
43    Command(CommandContext<T>),
44    ComponentInteraction(ComponentInteractionContext<T>),
45    Modal(ModalContext<T>),
46}