use std::sync::Arc; use twilight_model::{ gateway::payload::incoming::InteractionCreate, http::interaction::{InteractionResponse, InteractionResponseType}, id::{Id, marker::InteractionMarker}, }; use crate::framework::{ commands::messages::OriginalMessageUpdater, interactions::InteractionError, runtime::Runtime, }; pub struct InteractionContext { pub event: InteractionCreate, pub rt: Arc>, pub prefix: String, } impl InteractionContext { pub fn new(event: InteractionCreate, rt: Arc>, prefix: String) -> Self { Self { event, rt, prefix } } pub async fn defer(&self) -> Result<(), InteractionError> { self.rt .http .interaction(self.rt.app.id) .create_response( self.event.id, &self.event.token, &InteractionResponse { data: None, kind: InteractionResponseType::DeferredUpdateMessage, }, ) .await .map_err(|_| InteractionError::DeferringFailed)?; Ok(()) } pub fn original_message(&self) -> Option> { self.event.message.as_ref().map(|_| OriginalMessage { interaction_id: self.event.id, interaction_token: self.event.token.clone(), rt: self.rt.clone(), }) } } pub struct OriginalMessage { interaction_id: Id, interaction_token: String, rt: Arc>, } impl OriginalMessage where T: Send + Sync + 'static, { pub fn edit(&self) -> OriginalMessageUpdater { OriginalMessageUpdater::new( self.interaction_id, self.interaction_token.clone(), self.rt.clone(), ) } }