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