diff options
| author | Zeyla Hellyer <[email protected]> | 2017-12-20 10:56:15 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-21 09:29:44 -0800 |
| commit | 7fa2ac09c8386ecbdeaf551265db046dc49debdd (patch) | |
| tree | 5a6f242c7779b8e2f0f2c0e89f9c41dc69c803fe /src | |
| parent | Fix docs for User::has_role (diff) | |
| download | serenity-7fa2ac09c8386ecbdeaf551265db046dc49debdd.tar.xz serenity-7fa2ac09c8386ecbdeaf551265db046dc49debdd.zip | |
Add `animated` to `Emoji` and `ReactionType`
Adds an animated structfield to `Emoji` and `ReactionType`'s `Custom`
variant, which defaults to false if not present.
A test has been added for deserializing it, taken from a REST API GET
Emojis response.
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/channel/reaction.rs | 20 | ||||
| -rw-r--r-- | src/model/guild/emoji.rs | 7 | ||||
| -rw-r--r-- | src/utils/message_builder.rs | 10 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index 8edc2e9..52eb6f2 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -127,6 +127,8 @@ pub enum ReactionType { /// [`Emoji`]: struct.Emoji.html /// [`Guild`]: struct.Guild.html Custom { + /// Whether the emoji is animated. + animated: bool, /// The Id of the custom [`Emoji`]. /// /// [`Emoji`]: struct.Emoji.html @@ -144,6 +146,7 @@ impl<'de> Deserialize<'de> for ReactionType { #[derive(Deserialize)] #[serde(field_identifier, rename_all = "snake_case")] enum Field { + Animated, Id, Name, } @@ -158,11 +161,19 @@ impl<'de> Deserialize<'de> for ReactionType { } fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> StdResult<Self::Value, V::Error> { + let mut animated = None; let mut id = None; let mut name = None; while let Some(key) = map.next_key()? { match key { + Field::Animated => { + if animated.is_some() { + return Err(DeError::duplicate_field("animated")); + } + + animated = Some(map.next_value()?); + }, Field::Id => { if id.is_some() { return Err(DeError::duplicate_field("id")); @@ -182,12 +193,14 @@ impl<'de> Deserialize<'de> for ReactionType { } } + let animated = animated.unwrap_or(false); let name = name.ok_or_else(|| DeError::missing_field("name"))?; Ok(if let Some(id) = id { ReactionType::Custom { - id: id, - name: name, + animated, + id, + name, } } else { ReactionType::Unicode(name.unwrap()) @@ -212,6 +225,7 @@ impl ReactionType { ReactionType::Custom { id, ref name, + .. } => format!("{}:{}", name.as_ref().map_or("", |s| s.as_str()), id), ReactionType::Unicode(ref unicode) => unicode.clone(), } @@ -247,6 +261,7 @@ impl From<char> for ReactionType { impl From<Emoji> for ReactionType { fn from(emoji: Emoji) -> ReactionType { ReactionType::Custom { + animated: emoji.animated, id: emoji.id, name: Some(emoji.name), } @@ -294,6 +309,7 @@ impl Display for ReactionType { ReactionType::Custom { id, ref name, + .. } => { f.write_char('<')?; f.write_char(':')?; diff --git a/src/model/guild/emoji.rs b/src/model/guild/emoji.rs index 4a2190f..7f2d400 100644 --- a/src/model/guild/emoji.rs +++ b/src/model/guild/emoji.rs @@ -19,6 +19,9 @@ use super::super::GuildId; /// guild it was created in. #[derive(Clone, Debug, Deserialize)] pub struct Emoji { + /// Whether the emoji is animated. + #[serde(default)] + pub animated: bool, /// The Id of the emoji. pub id: EmojiId, /// The name of the emoji. It must be at least 2 characters long and can @@ -56,6 +59,7 @@ impl Emoji { /// # use serenity::model::{Emoji, EmojiId}; /// # /// # let mut emoji = Emoji { + /// # animated: false, /// # id: EmojiId(7), /// # name: String::from("blobface"), /// # managed: false, @@ -93,6 +97,7 @@ impl Emoji { /// # use serenity::model::{Emoji, EmojiId}; /// # /// # let mut emoji = Emoji { + /// # animated: false, /// # id: EmojiId(7), /// # name: String::from("blobface"), /// # managed: false, @@ -137,6 +142,7 @@ impl Emoji { /// # use serenity::model::{Emoji, EmojiId}; /// # /// # let mut emoji = Emoji { + /// # animated: false, /// # id: EmojiId(7), /// # name: String::from("blobface"), /// # managed: false, @@ -172,6 +178,7 @@ impl Emoji { /// # use serenity::model::{Emoji, EmojiId}; /// # /// # let mut emoji = Emoji { + /// # animated: false, /// # id: EmojiId(7), /// # name: String::from("blobface"), /// # managed: false, diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs index 284ba1e..41d3c8b 100644 --- a/src/utils/message_builder.rs +++ b/src/utils/message_builder.rs @@ -18,6 +18,7 @@ use model::{ChannelId, Emoji, Mentionable, RoleId, UserId}; /// # /// # let user = UserId(1); /// # let emoji = Emoji { +/// # animated: false, /// # id: EmojiId(2), /// # name: "test".to_string(), /// # managed: false, @@ -142,6 +143,7 @@ impl MessageBuilder { /// use serenity::utils::MessageBuilder; /// /// let emoji = Emoji { + /// animated: false, /// id: EmojiId(302516740095606785), /// managed: true, /// name: "smugAnimeFace".to_string(), @@ -912,15 +914,15 @@ impl From<ContentModifier> for Content { mod private { use super::{Content, ContentModifier}; use std::fmt; - + pub trait A {} - + impl A for ContentModifier {} impl A for Content {} impl<T: fmt::Display> A for T {} } - + /// This trait only exists as way to bypass the shouting of the compiler. Specifically "conflicting /// implementations in core" and alike. /// However is not meant to be used outside. @@ -940,7 +942,7 @@ impl<T: fmt::Display> I for T { } } } - + impl I for ContentModifier { fn into(self) -> Content { self.to_content() } } |