aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-20 10:56:15 -0800
committerZeyla Hellyer <[email protected]>2017-12-20 11:06:24 -0800
commitf2fa349d831c1db59993341284049ffbd56dde3b (patch)
treeab31444f6e44d0102f938ef646ccee6da38ff411 /src
parentAdd variant adapters to Channel (#238) (diff)
downloadserenity-f2fa349d831c1db59993341284049ffbd56dde3b.tar.xz
serenity-f2fa349d831c1db59993341284049ffbd56dde3b.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. (cherry picked from commit 5286949f424e824784344ebb7b7af4e52fb819c3)
Diffstat (limited to 'src')
-rw-r--r--src/model/channel/reaction.rs22
-rw-r--r--src/model/guild/emoji.rs7
-rw-r--r--src/utils/message_builder.rs2
3 files changed, 29 insertions, 2 deletions
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index 5c1ee4d..0741cd7 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -170,6 +170,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
@@ -187,6 +189,7 @@ impl<'de> Deserialize<'de> for ReactionType {
#[derive(Deserialize)]
#[serde(field_identifier, rename_all = "snake_case")]
enum Field {
+ Animated,
Id,
Name,
}
@@ -201,11 +204,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"));
@@ -225,12 +236,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())
@@ -255,6 +268,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(),
}
@@ -290,6 +304,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),
}
@@ -299,6 +314,7 @@ impl From<Emoji> for ReactionType {
impl From<EmojiId> for ReactionType {
fn from(emoji_id: EmojiId) -> ReactionType {
ReactionType::Custom {
+ animated: false,
id: emoji_id,
name: None
}
@@ -308,6 +324,7 @@ impl From<EmojiId> for ReactionType {
impl From<EmojiIdentifier> for ReactionType {
fn from(emoji_id: EmojiIdentifier) -> ReactionType {
ReactionType::Custom {
+ animated: false,
id: emoji_id.id,
name: Some(emoji_id.name)
}
@@ -380,6 +397,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 9581f77..919c29d 100644
--- a/src/model/guild/emoji.rs
+++ b/src/model/guild/emoji.rs
@@ -17,6 +17,9 @@ use {CACHE, http};
/// 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
@@ -55,6 +58,7 @@ impl Emoji {
/// # use serenity::model::id::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::id::EmojiId;
/// #
/// # let mut emoji = Emoji {
+ /// # animated: false,
/// # id: EmojiId(7),
/// # name: String::from("blobface"),
/// # managed: false,
@@ -138,6 +143,7 @@ impl Emoji {
/// # use serenity::model::id::EmojiId;
/// #
/// # let mut emoji = Emoji {
+ /// # animated: false,
/// # id: EmojiId(7),
/// # name: String::from("blobface"),
/// # managed: false,
@@ -174,6 +180,7 @@ impl Emoji {
/// # use serenity::model::id::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 580be82..f7dcae1 100644
--- a/src/utils/message_builder.rs
+++ b/src/utils/message_builder.rs
@@ -20,6 +20,7 @@ use std::ops::Add;
/// #
/// # let user = UserId(1);
/// # let emoji = Emoji {
+/// # animated: false,
/// # id: EmojiId(2),
/// # name: "test".to_string(),
/// # managed: false,
@@ -145,6 +146,7 @@ impl MessageBuilder {
/// use serenity::utils::MessageBuilder;
///
/// let emoji = Emoji {
+ /// animated: false,
/// id: EmojiId(302516740095606785),
/// managed: true,
/// name: "smugAnimeFace".to_string(),