#[cfg(feature = "model")] use builder::CreateEmbed; #[cfg(feature = "model")] use internal::prelude::*; #[cfg(feature = "utils")] use utils::Colour; #[cfg(feature = "model")] use utils; /// Represents a rich embed which allows using richer markdown, multiple fields /// and more. This was heavily inspired by [slack's attachments]. /// /// You can include an attachment in your own message by a user or a bot, or in /// a webhook. /// /// **Note**: Maximum amount of characters you can put is 256 in a field name, /// 1024 in a field value, and 2048 in a description. /// /// [slack's attachments]: https://api.slack.com/docs/message-attachments #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Embed { /// Information about the author of the embed. pub author: Option, /// The colour code of the embed. #[cfg(feature = "utils")] #[serde(default, rename = "color")] pub colour: Colour, /// The colour code of the embed. #[cfg(not(feature = "utils"))] #[serde(default, rename = "color")] pub colour: u32, /// The description of the embed. /// /// The maximum value for this field is 2048 unicode codepoints. pub description: Option, /// The array of fields. /// /// The maximum number of fields is 25. #[serde(default)] pub fields: Vec, /// Footer information for the embed. pub footer: Option, /// Image information of the embed. pub image: Option, /// The type of the embed. For embeds not generated by Discord's backend, /// this will always be "rich". #[serde(rename = "type")] pub kind: String, /// Provider information for the embed. /// /// For example, if the embed [`kind`] is `"video"`, the provider might /// contain information about YouTube. /// /// [`kind`]: #structfield.kind pub provider: Option, /// Thumbnail information of the embed. pub thumbnail: Option, /// Timestamp information. pub timestamp: Option, /// The title of the embed. pub title: Option, /// The URL of the embed. pub url: Option, /// The embed's video information. /// /// This is present if the [`kind`] is `"video"`. /// /// [`kind`]: #structfield.kind pub video: Option, } #[cfg(feature = "model")] impl Embed { /// Creates a fake Embed, giving back a `serde_json` map. /// /// This should only be useful in conjunction with [`Webhook::execute`]. /// /// [`Webhook::execute`]: ../webhook/struct.Webhook.html /// /// # Examples /// /// Create an embed: /// /// ```rust,no_run /// use serenity::model::channel::Embed; /// /// let embed = Embed::fake(|e| e /// .title("Embed title") /// .description("Making a basic embed") /// .field("A field", "Has some content.", false)); /// ``` #[inline] pub fn fake(f: F) -> Value where F: FnOnce(CreateEmbed) -> CreateEmbed { let map = utils::vecmap_to_json_map(f(CreateEmbed::default()).0); Value::Object(map) } } /// An author object in an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedAuthor { /// The URL of the author icon. /// /// This only supports HTTP(S). pub icon_url: Option, /// The name of the author. pub name: String, /// A proxied URL of the author icon. pub proxy_icon_url: Option, /// The URL of the author. pub url: Option, } /// A field object in an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedField { /// Indicator of whether the field should display as inline. pub inline: bool, /// The name of the field. /// /// The maximum length of this field is 512 unicode codepoints. pub name: String, /// The value of the field. /// /// The maxiumum length of this field is 1024 unicode codepoints. pub value: String, } impl EmbedField { /// Creates a new embed field. /// /// **Note**: Refer to the [`name`] and [`value`] documentation for maximum /// lengths. /// /// [`name`]: #structfield.name /// [`value`]: #structfield.value pub fn new(name: T, value: U, inline: bool) -> Self where T: Into, U: Into { Self::_new(name.into(), value.into(), inline) } fn _new(name: String, value: String, inline: bool) -> Self { Self { name, value, inline, } } } /// Footer information for an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedFooter { /// The URL of the footer icon. /// /// This only supports HTTP(S). pub icon_url: Option, /// A proxied URL of the footer icon. pub proxy_icon_url: Option, /// The associated text with the footer. pub text: String, } /// An image object in an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedImage { /// The height of the image. pub height: u64, /// A proxied URL of the image. pub proxy_url: String, /// Source URL of the image. /// /// This only supports HTTP(S). pub url: String, /// The width of the image. pub width: u64, } /// The provider of an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedProvider { /// The name of the provider. pub name: String, /// The URL of the provider. pub url: Option, } /// The dimensions and URL of an embed thumbnail. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedThumbnail { /// The height of the thumbnail in pixels. pub height: u64, /// A proxied URL of the thumbnail. pub proxy_url: String, /// The source URL of the thumbnail. /// /// This only supports HTTP(S). pub url: String, /// The width of the thumbnail in pixels. pub width: u64, } /// Video information for an embed. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EmbedVideo { /// The height of the video in pixels. pub height: u64, /// The source URL of the video. pub url: String, /// The width of the video in pixels. pub width: u64, }