diff options
| author | Andrej <[email protected]> | 2018-02-02 13:30:25 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2018-02-02 13:30:25 +0100 |
| commit | 2e1eb4c35b488ac68a33e76502d0c8f56a72c4b6 (patch) | |
| tree | f153d987dbb0ba6023f1367eaf1656b1de81fd59 | |
| parent | Bump to v0.5.1 (diff) | |
| download | archived-serenity-2e1eb4c35b488ac68a33e76502d0c8f56a72c4b6.tar.xz archived-serenity-2e1eb4c35b488ac68a33e76502d0c8f56a72c4b6.zip | |
Add video url specifier for CreateEmbed (#269)
| -rw-r--r-- | src/builder/create_embed.rs | 25 | ||||
| -rw-r--r-- | tests/test_create_embed.rs | 12 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index f420a8c..24a7513 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -164,26 +164,29 @@ impl CreateEmbed { CreateEmbed(self.0) } - /// Set the image associated with the embed. This only supports HTTP(S). - pub fn image(mut self, url: &str) -> Self { - let image = json!({ + fn url_object(mut self, name: &'static str, url: &str) -> Self { + let obj = json!({ "url": url.to_string() }); - self.0.insert("image", image); + self.0.insert(name, obj); CreateEmbed(self.0) } - /// Set the thumbnail of the embed. This only supports HTTP(S). - pub fn thumbnail(mut self, url: &str) -> Self { - let thumbnail = json!({ - "url": url.to_string(), - }); + /// Set the image associated with the embed. This only supports HTTP(S). + pub fn image(self, url: &str) -> Self { + self.url_object("image", url) + } - self.0.insert("thumbnail", thumbnail); + /// Set the video associated with the embed. This only supports HTTP(S). + pub fn video(self, url: &str) -> Self { + self.url_object("video", url) + } - CreateEmbed(self.0) + /// Set the thumbnail of the embed. This only supports HTTP(S). + pub fn thumbnail(self, url: &str) -> Self { + self.url_object("thumbnail", url) } /// Set the timestamp. diff --git a/tests/test_create_embed.rs b/tests/test_create_embed.rs index 1db1be0..0a738f8 100644 --- a/tests/test_create_embed.rs +++ b/tests/test_create_embed.rs @@ -6,7 +6,7 @@ extern crate serde_json; extern crate serenity; use serde_json::Value; -use serenity::model::channel::{Embed, EmbedField, EmbedFooter, EmbedImage}; +use serenity::model::channel::{Embed, EmbedField, EmbedFooter, EmbedImage, EmbedVideo}; use serenity::builder::CreateEmbed; use serenity::utils::{self, Colour}; @@ -45,13 +45,18 @@ fn test_from_embed() { timestamp: None, title: Some("hakase".to_string()), url: Some("https://i.imgur.com/XfWpfCV.gif".to_string()), - video: None, + video: Some(EmbedVideo { + height: 213, + url: "https://i.imgur.com/XfWpfCV.mp4".to_string(), + width: 224, + }), }; let builder = CreateEmbed::from(embed) .colour(0xFF0011) .description("This is a hakase description") .image("https://i.imgur.com/XfWpfCV.gif") + .video("https://i.imgur.com/XfWpfCV.mp4") .title("still a hakase") .url("https://i.imgur.com/XfWpfCV.gif"); @@ -78,6 +83,9 @@ fn test_from_embed() { "image": { "url": "https://i.imgur.com/XfWpfCV.gif", }, + "video": { + "url": "https://i.imgur.com/XfWpfCV.mp4", + }, "footer": { "text": "This is a hakase footer", "icon_url": "https://i.imgur.com/XfWpfCV.gif", |