#[cfg(feature = "serde_support")]
use serde::{Serialize, Serializer};
#[cfg(feature = "serde_support")]
use serde_json::Result as JsonResult;
use std::collections::HashMap;
#[cfg_attr(feature = "serde_support", derive(Serialize))]
pub struct DiscordInteractionOption {
#[cfg_attr(feature = "serde_support", serde(serialize_with = "serialize_discord_interaction_option_type", rename = "type"))]
pub option_type: DiscordInteractionOptionType,
pub name: String,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub name_localizations: Option<HashMap<String, String>>,
pub description: String,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub description_localizations: Option<HashMap<String, String>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub required: Option<bool>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub choices: Option<Vec<DiscordInteractionChoice>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub options: Option<Vec<DiscordInteractionOption>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none", serialize_with = "serialize_discord_interaction_channel_type"))]
pub channel_types: Option<Vec<DiscordInteractionChannelType>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub min_value: Option<f64>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub max_value: Option<f64>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub min_length: Option<u32>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub max_length: Option<u32>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub autocomplete: Option<bool>,
}
#[derive(Copy, Clone)]
pub enum DiscordInteractionOptionType {
SubCommand = 1,
SubCommandGroup = 2,
String = 3,
Integer = 4,
Boolean = 5,
User = 6,
Channel = 7,
Role = 8,
Mentionable = 9,
Number = 10,
}
#[cfg(feature = "serde_support")]
fn serialize_discord_interaction_option_type<S>(
value: &DiscordInteractionOptionType,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u8(*value as u8)
}
#[derive(Copy, Clone)]
pub enum DiscordInteractionChannelType {
GuildText = 0,
DM = 1,
GuildVoice = 2,
GroupDM = 3,
GuildCategory = 4,
GuildAnnouncement = 5,
AnnouncementThread = 10,
PublicThread = 11,
PrivateThread = 12,
GuildStageVoice = 13,
GuildDirectory = 14,
GuildForum = 15,
}
#[cfg(feature = "serde_support")]
fn serialize_discord_interaction_channel_type<S>(
value: &Option<Vec<DiscordInteractionChannelType>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if value.is_none() {
return serializer.serialize_none();
}
let mut vec = Vec::new();
for channel_type in value.as_ref().unwrap() {
vec.push(*channel_type as u8);
}
serializer.serialize_some(&vec)
}
#[cfg_attr(feature = "serde_support", derive(Serialize))]
pub enum InteractionArgument {
SubCommand(String),
SubCommandGroup(String),
String(String),
Integer(i64),
Boolean(bool),
User(String),
Channel(String),
Role(String),
Mentionable(String),
Number(f64),
}
#[cfg_attr(feature = "serde_support", derive(Serialize))]
pub enum ChoiceValue {
Str(String),
Int(i32),
Float(f64),
}
#[cfg_attr(feature = "serde_support", derive(Serialize))]
pub struct DiscordInteractionChoice {
pub name: String,
pub value: ChoiceValue,
}
#[cfg_attr(feature = "serde_support", derive(Serialize))]
pub struct DiscordInteraction {
pub name: String,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub name_localizations: Option<HashMap<String, String>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub description: Option<String>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub description_localizations: Option<HashMap<String, String>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub options: Option<Vec<DiscordInteractionOption>>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub default_member_permissions: Option<String>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none"))]
pub dm_permission: Option<bool>,
pub default_permission: bool,
#[cfg_attr(feature = "serde_support", serde(skip_serializing_if = "Option::is_none", serialize_with="serialize_discord_interaction_type", rename="type"))]
pub interaction_type: Option<DiscordInteractionType>,
pub nsfw: bool,
}
#[derive(Copy, Clone)]
pub enum DiscordInteractionType {
ChatInput = 1,
User = 2,
Message = 3,
}
#[cfg(feature = "serde_support")]
fn serialize_discord_interaction_type<S>(
value: &Option<DiscordInteractionType>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if value.is_none() {
return serializer.serialize_none();
}
serializer.serialize_u8(value.unwrap() as u8)
}
#[cfg(feature = "serde_support")]
pub fn base_command_to_json(base_command: &DiscordInteraction) -> JsonResult<String> {
serde_json::to_string(base_command)
}