#[cfg(feature = "model")]
use crate::builder::CreateEmbed;
#[cfg(feature = "model")]
use crate::internal::prelude::*;
#[cfg(feature = "model")]
use crate::json;
#[cfg(feature = "utils")]
use crate::utils::Colour;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Embed {
pub author: Option<EmbedAuthor>,
#[cfg(feature = "utils")]
#[serde(rename = "color")]
pub colour: Option<Colour>,
#[cfg(not(feature = "utils"))]
#[serde(default, rename = "color")]
pub colour: u32,
pub description: Option<String>,
#[serde(default)]
pub fields: Vec<EmbedField>,
pub footer: Option<EmbedFooter>,
pub image: Option<EmbedImage>,
#[serde(rename = "type")]
pub kind: Option<String>,
pub provider: Option<EmbedProvider>,
pub thumbnail: Option<EmbedThumbnail>,
pub timestamp: Option<String>,
pub title: Option<String>,
pub url: Option<String>,
pub video: Option<EmbedVideo>,
}
#[cfg(feature = "model")]
impl Embed {
#[inline]
pub fn fake<F>(f: F) -> Value
where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
{
let mut create_embed = CreateEmbed::default();
f(&mut create_embed);
let map = json::hashmap_to_json_map(create_embed.0);
Value::from(map)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedAuthor {
pub name: String,
pub url: Option<String>,
pub icon_url: Option<String>,
pub proxy_icon_url: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedField {
pub name: String,
pub value: String,
#[serde(default)]
pub inline: bool,
}
impl EmbedField {
pub fn new<T, U>(name: T, value: U, inline: bool) -> Self
where
T: Into<String>,
U: Into<String>,
{
Self::_new(name.into(), value.into(), inline)
}
fn _new(name: String, value: String, inline: bool) -> Self {
Self {
name,
value,
inline,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedFooter {
pub text: String,
pub icon_url: Option<String>,
pub proxy_icon_url: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedImage {
pub url: String,
pub proxy_url: Option<String>,
pub height: Option<u64>,
pub width: Option<u64>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedProvider {
pub name: Option<String>,
pub url: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedThumbnail {
pub url: String,
pub proxy_url: Option<String>,
pub height: Option<u64>,
pub width: Option<u64>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct EmbedVideo {
pub url: String,
pub proxy_url: Option<String>,
pub height: Option<u64>,
pub width: Option<u64>,
}