|
|
@@ -1,5 +1,30 @@ |
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)] |
|
|
|
pub struct InteractionRaw { |
|
|
|
#[serde(rename = "type")] |
|
|
|
pub type_: usize, |
|
|
|
pub token: Option<String>, |
|
|
|
pub id: Option<String>, |
|
|
|
pub guild_id: Option<String>, |
|
|
|
pub channel_id: Option<String>, |
|
|
|
} |
|
|
|
|
|
|
|
impl InteractionRaw { |
|
|
|
pub fn interaction(&self) -> Interaction { |
|
|
|
match self.type_ { |
|
|
|
1 => Interaction::Ping {}, |
|
|
|
2 => Interaction::Command { |
|
|
|
token: self.token.clone().unwrap(), |
|
|
|
id: self.id.clone().unwrap(), |
|
|
|
guild_id: self.guild_id.clone().unwrap(), |
|
|
|
channel_id: self.channel_id.clone().unwrap(), |
|
|
|
}, |
|
|
|
_ => Interaction::Invalid {}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)] |
|
|
|
#[serde(tag = "type")] |
|
|
|
pub enum Interaction { |
|
|
@@ -15,6 +40,7 @@ pub enum Interaction { |
|
|
|
channel_id: String, |
|
|
|
//version: usize, |
|
|
|
}, |
|
|
|
Invalid {}, |
|
|
|
} |
|
|
|
|
|
|
|
impl Interaction { |
|
|
@@ -22,29 +48,47 @@ impl Interaction { |
|
|
|
match self { |
|
|
|
Self::Ping {..} => true, |
|
|
|
Self::Command {..} => false, |
|
|
|
Self::Invalid {..} => false, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)] |
|
|
|
#[serde(tag = "type")] |
|
|
|
pub enum InteractionResponse { |
|
|
|
#[serde(rename = "1")] |
|
|
|
//#[serde(rename = "1")] |
|
|
|
Pong {}, |
|
|
|
#[serde(rename = "2")] |
|
|
|
//#[serde(rename = "2")] |
|
|
|
Acknowledge {}, |
|
|
|
#[serde(rename = "3")] |
|
|
|
//#[serde(rename = "3")] |
|
|
|
ChannelMessage { |
|
|
|
data: Option<InteractionApplicationCommandCallbackData>, |
|
|
|
}, |
|
|
|
#[serde(rename = "4")] |
|
|
|
//#[serde(rename = "4")] |
|
|
|
ChannelMessageWithSource { |
|
|
|
data: Option<InteractionApplicationCommandCallbackData>, |
|
|
|
}, |
|
|
|
#[serde(rename = "5")] |
|
|
|
//#[serde(rename = "5")] |
|
|
|
AcknowledgeWithSource {}, |
|
|
|
} |
|
|
|
|
|
|
|
impl InteractionResponse { |
|
|
|
pub fn raw(&self) -> InteractionResponseRaw { |
|
|
|
match self { |
|
|
|
InteractionResponse::Pong { .. } => InteractionResponseRaw {type_: 1, data:None}, |
|
|
|
InteractionResponse::Acknowledge { .. } => InteractionResponseRaw {type_: 2, data:None}, |
|
|
|
InteractionResponse::ChannelMessage { data, .. } => InteractionResponseRaw {type_: 3, data: data.clone()}, |
|
|
|
InteractionResponse::ChannelMessageWithSource { data, .. } => InteractionResponseRaw {type_: 4, data: data.clone()}, |
|
|
|
InteractionResponse::AcknowledgeWithSource { .. } => InteractionResponseRaw {type_: 5, data:None}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)] |
|
|
|
pub struct InteractionResponseRaw { |
|
|
|
#[serde(rename = "type")] |
|
|
|
pub type_: usize, |
|
|
|
pub data: Option<InteractionApplicationCommandCallbackData>, |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)] |
|
|
|
pub struct InteractionApplicationCommandCallbackData { |
|
|
|
pub tts: bool, |
|
|
|