aboutsummaryrefslogtreecommitdiff
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
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)
-rw-r--r--src/model/channel/reaction.rs22
-rw-r--r--src/model/guild/emoji.rs7
-rw-r--r--src/utils/message_builder.rs2
-rw-r--r--tests/resources/emoji_animated.json14
-rw-r--r--tests/test_deser.rs5
-rw-r--r--tests/test_formatters.rs1
-rw-r--r--tests/test_msg_builder.rs1
7 files changed, 50 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(),
diff --git a/tests/resources/emoji_animated.json b/tests/resources/emoji_animated.json
new file mode 100644
index 0000000..18173bb
--- /dev/null
+++ b/tests/resources/emoji_animated.json
@@ -0,0 +1,14 @@
+{
+ "managed": false,
+ "name": "abc",
+ "roles": [],
+ "user": {
+ "username": "zeyla",
+ "discriminator": "5479",
+ "id": "114941315417899012",
+ "avatar": "d8c3dacd468ef9e48ca28add856fbfe2"
+ },
+ "require_colons": true,
+ "animated": false,
+ "id": "300000000000000000"
+}
diff --git a/tests/test_deser.rs b/tests/test_deser.rs
index ae9536b..e547e9d 100644
--- a/tests/test_deser.rs
+++ b/tests/test_deser.rs
@@ -35,6 +35,11 @@ fn channel_update() {
p!(ChannelUpdateEvent, "channel_update_1");
}
+#[test]
+fn emoji_animated() {
+ p!(Emoji, "emoji_animated");
+}
+
// A game with null type.
#[test]
fn game() {
diff --git a/tests/test_formatters.rs b/tests/test_formatters.rs
index e44c550..9fcc044 100644
--- a/tests/test_formatters.rs
+++ b/tests/test_formatters.rs
@@ -35,6 +35,7 @@ fn test_mention() {
nsfw: false,
})));
let emoji = Emoji {
+ animated: false,
id: EmojiId(5),
name: "a".to_string(),
managed: true,
diff --git a/tests/test_msg_builder.rs b/tests/test_msg_builder.rs
index bbb0dd7..c291bf5 100644
--- a/tests/test_msg_builder.rs
+++ b/tests/test_msg_builder.rs
@@ -33,6 +33,7 @@ fn no_free_formatting() {
fn mentions() {
let content_emoji = MessageBuilder::new()
.emoji(&Emoji {
+ animated: false,
id: EmojiId(32),
name: "Rohrkatze".to_string(),
managed: false,