|
- use serde::{Deserialize, Serialize};
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct InteractionRaw {
- #[serde(rename = "type")]
- pub type_: usize,
- pub token: Option<String>,
- pub member: Option<GuildMember>,
- pub id: Option<String>,
- pub guild_id: Option<String>,
- pub data: Option<ApplicationCommandInteractionData>,
- pub channel_id: Option<String>,
- pub version: Option<usize>,
- }
-
- impl InteractionRaw {
- pub fn interaction(&self) -> Interaction {
- match self.type_ {
- 1 => Interaction::Ping {},
- 2 => Interaction::Command {
- token: self.token.clone().unwrap(),
- member: self.member.clone().unwrap(),
- id: self.id.clone().unwrap(),
- guild_id: self.guild_id.clone().unwrap(),
- data: self.data.clone().unwrap(),
- channel_id: self.channel_id.clone().unwrap(),
- version: self.version.unwrap_or(1),
- },
- _ => Interaction::Invalid {},
- }
- }
- }
-
- pub enum Interaction {
- //#[serde(rename = "1")]
- Ping {},
- //#[serde(rename = "2")]
- Command {
- token: String,
- member: GuildMember,
- id: String,
- guild_id: String,
- data: ApplicationCommandInteractionData,
- channel_id: String,
- version: usize,
- },
- Invalid {},
- }
-
- impl Interaction {
- pub fn is_ping(&self) -> bool {
- match self {
- Self::Ping {..} => true,
- Self::Command {..} => false,
- Self::Invalid {..} => false,
- }
- }
-
- pub fn is_command(&self) -> bool {
- match self {
- Self::Ping {..} => false,
- Self::Command {..} => true,
- Self::Invalid {..} => false,
- }
- }
-
- pub fn is_invalid(&self) -> bool {
- match self {
- Self::Ping {..} => false,
- Self::Command {..} => false,
- Self::Invalid {..} => true,
- }
- }
-
- pub fn cmd(&self) -> Option<InteractionCommand> {
- match self {
- Self::Ping {..} => None,
- Self::Command { token, member, id, guild_id, data, channel_id, version } => Some(InteractionCommand {
- token: token.to_string(),
- member: member.clone(),
- id: id.to_string(),
- guild_id: guild_id.to_string(),
- data: data.clone(),
- channel_id: channel_id.to_string(),
- version: *version,
- }),
- Self::Invalid {..} => None,
- }
- }
- }
-
- pub struct InteractionCommand {
- pub token: String,
- pub member: GuildMember,
- pub id: String,
- pub guild_id: String,
- pub data: ApplicationCommandInteractionData,
- pub channel_id: String,
- pub version: usize,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct GuildMember {
- pub user: Option<User>,
- pub nick: Option<String>,
- pub role: Vec<String>,
- pub joined_at: String,
- pub premium_since: Option<String>,
- pub deaf: bool,
- pub mute: bool,
- pub pending: Option<bool>,
- pub permissions: Option<String>,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct User {
- pub id: String,
- pub username: String,
- pub discriminator: String,
- pub avatar: Option<String>,
- pub bot: Option<bool>,
- pub system: Option<bool>,
- pub mfa_enabled: Option<bool>,
- pub locale: Option<String>,
- pub verified: Option<String>,
- pub email: Option<String>,
- pub flags: Option<usize>,
- pub premium_type: Option<usize>,
- pub public_flags: Option<usize>,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct ApplicationCommandInteractionData {
- pub id: String,
- pub name: String,
- pub options: Option<Vec<ApplicationCommandInteractionData>>,
- }
-
- pub enum InteractionResponse {
- //#[serde(rename = "1")]
- Pong {},
- //#[serde(rename = "2")]
- Acknowledge {},
- //#[serde(rename = "3")]
- ChannelMessage {
- data: Option<InteractionApplicationCommandCallbackData>,
- },
- //#[serde(rename = "4")]
- ChannelMessageWithSource {
- data: Option<InteractionApplicationCommandCallbackData>,
- },
- //#[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,
- pub content: String,
- //pub embeds: Option<Vec<Embed>>,
- pub allowed_mentions: Option<String>,
- }
-
- // slash command management structures
- #[derive(Serialize, Deserialize, Clone)]
- pub struct ApplicationCommand {
- pub id: Option<String>,
- pub application_id: Option<String>,
- pub name: String,
- pub description: String,
- pub options: Option<Vec<ApplicationCommandOption>>,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- #[serde(tag = "type")]
- pub enum ApplicationCommandOption {
- #[serde(rename = "1")]
- SubCommand {
- name: String,
- description: String,
- required: bool,
- options: Option<Vec<ApplicationCommandOption>>,
- },
- #[serde(rename = "2")]
- SubCommandGroup {
- name: String,
- description: String,
- required: bool,
- options: Option<Vec<ApplicationCommandOption>>,
- },
- #[serde(rename = "3")]
- String {
- name: String,
- description: String,
- required: bool,
- choices: Option<Vec<ApplicationCommandOptionChoice>>,
- },
- #[serde(rename = "4")]
- Integer {
- name: String,
- description: String,
- required: bool,
- choices: Option<Vec<ApplicationCommandOptionChoice>>,
- },
- #[serde(rename = "5")]
- Boolean {
- name: String,
- description: String,
- required: bool,
- },
- #[serde(rename = "6")]
- User {
- name: String,
- description: String,
- required: bool,
- },
- #[serde(rename = "7")]
- Channel {
- name: String,
- description: String,
- required: bool,
- },
- #[serde(rename = "8")]
- Role {
- name: String,
- description: String,
- required: bool,
- },
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct ApplicationCommandOptionChoice {
- pub name: String,
- pub value: String,
- }
|