Skip to content

Commit

Permalink
Fix deserialization of Guild::application_id
Browse files Browse the repository at this point in the history
Fix the deserialization of the `Guild::application_id` structfield.
Additionally, create a new ID type for it.

A test has been added for this.
  • Loading branch information
Zeyla Hellyer committed Dec 15, 2017
1 parent 8c9baa7 commit 99d17d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 2 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/resources/guild_some_application_id.json
Original file line number Diff line number Diff line change
@@ -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":[]}
6 changes: 6 additions & 0 deletions tests/test_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 99d17d2

Please sign in to comment.