aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-15 14:33:21 -0800
committerZeyla Hellyer <[email protected]>2017-12-15 14:34:10 -0800
commit99d17d2975143b0d588c969f7ae6f8d11e62a9e1 (patch)
tree74ea2a369180ee343b285cb1c0394f1c8161313a
parentChange type of a couple Guild/PartialGuild fields (diff)
downloadserenity-99d17d2975143b0d588c969f7ae6f8d11e62a9e1.tar.xz
serenity-99d17d2975143b0d588c969f7ae6f8d11e62a9e1.zip
Fix deserialization of `Guild::application_id`
Fix the deserialization of the `Guild::application_id` structfield. Additionally, create a new ID type for it. A test has been added for this.
-rw-r--r--src/model/guild/mod.rs4
-rw-r--r--src/model/mod.rs2
-rw-r--r--tests/resources/guild_some_application_id.json1
-rw-r--r--tests/test_deser.rs6
4 files changed, 11 insertions, 2 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index b50988b..32b5ee2 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -49,7 +49,7 @@ pub struct Guild {
/// channel before being moved to an AFK channel -- if one exists.
pub afk_timeout: u64,
/// Application ID of the guild creator if it is bot-created.
- pub application_id: Option<u64>,
+ pub application_id: Option<ApplicationId>,
/// All voice and text channels contained within a guild.
///
/// This contains all channels regardless of permissions (i.e. the ability
@@ -1427,7 +1427,7 @@ impl<'de> Deserialize<'de> for Guild {
.and_then(u64::deserialize)
.map_err(DeError::custom)?;
let application_id = match map.remove("application_id") {
- Some(v) => serde_json::from_value::<Option<u64>>(v)
+ Some(v) => serde_json::from_value::<Option<ApplicationId>>(v)
.map_err(DeError::custom)?,
None => None,
};
diff --git a/src/model/mod.rs b/src/model/mod.rs
index 7a7a007..1dd5192 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -105,6 +105,8 @@ macro_rules! id_u64 {
}
id_u64! {
+ /// An identifier for an Application.
+ ApplicationId;
/// An identifier for a Channel
ChannelId;
/// An identifier for an Emoji
diff --git a/tests/resources/guild_some_application_id.json b/tests/resources/guild_some_application_id.json
new file mode 100644
index 0000000..d046a3f
--- /dev/null
+++ b/tests/resources/guild_some_application_id.json
@@ -0,0 +1 @@
+{"afk_channel_id":null,"afk_timeout":300,"application_id":"245571012924538880","channels":[{"guild_id":334866293213888514,"id":"334866293213888514","last_message_id":"334866823763722242","name":"general","permission_overwrites":[],"position":0,"topic":null,"type":0},{"bitrate":64000,"guild_id":334866293213888514,"id":"334866293213888515","name":"General","permission_overwrites":[],"position":0,"type":2,"user_limit":0}],"default_message_notifications":0,"emojis":[],"explicit_content_filter":0,"features":[],"icon":null,"id":"334866293213888514","joined_at":"2017-07-13T01:19:05.876000+00:00","large":false,"member_count":1,"members":[{"deaf":false,"guild_id":334866293213888514,"joined_at":"2017-07-13T01:19:05.876000+00:00","mute":false,"roles":[],"user":{"avatar":"96fd89e899fbb203b9851df3e7dcbf5d","bot":true,"discriminator":"9653","id":"245571012924538880","username":"nano"}}],"mfa_level":0,"name":"helo","owner_id":"245571012924538880","presences":[{"game":{"name":"nano help [1/1]","type":0},"status":"online","user":{"id":"245571012924538880"}}],"region":"eu-central","roles":[{"color":0,"hoist":false,"id":"334866293213888514","managed":false,"mentionable":false,"name":"@everyone","permissions":104324161,"position":0}],"splash":null,"system_channel_id":null,"verification_level":0,"voice_states":[]}
diff --git a/tests/test_deser.rs b/tests/test_deser.rs
index 5288da2..4d6c176 100644
--- a/tests/test_deser.rs
+++ b/tests/test_deser.rs
@@ -58,6 +58,12 @@ fn guild_channel_1_rest() {
p!(GuildChannel, "guild_channel_rest_1");
}
+// A guild that has some application ID.
+#[test]
+fn guild_some_application_id() {
+ p!(Guild, "guild_some_application_id");
+}
+
// A Discord API GUILD_CREATE.
#[test]
fn guild_create() {