Skip to content

Commit

Permalink
Add Message::member structfield
Browse files Browse the repository at this point in the history
Adds the `Message::member` structfield, which contains a partial amount
of member data (deaf and mute status, role IDs, and joined_at).
  • Loading branch information
Zeyla Hellyer committed May 22, 2018
1 parent 6c19bc9 commit 0e1e8fb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct Message {
/// message or a system message.
#[serde(rename = "type")]
pub kind: MessageType,
/// A partial amount of data about the user's member data, if this message
/// was sent in a guild.
pub member: Option<PartialMember>,
/// Indicator of whether the message mentions everyone.
pub mention_everyone: bool,
/// Array of [`Role`]s' Ids mentioned in the message.
Expand Down
22 changes: 20 additions & 2 deletions src/model/guild/member.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use model::prelude::*;
use chrono::{DateTime, FixedOffset};
use std::fmt::{
Display,
Formatter,
Display,
Formatter,
Result as FmtResult
};
use super::deserialize_sync_user;
Expand Down Expand Up @@ -462,3 +462,21 @@ impl Display for Member {
Display::fmt(&self.user.read().mention(), f)
}
}

/// A partial amount of data for a member.
///
/// This is used in [`Message`]s from [`Guild`]s.
///
/// [`Guild`]: struct.Guild.html
/// [`Message`]: ../channel/struct.Message.html
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PartialMember {
/// Indicator of whether the member can hear in voice channels.
pub deaf: bool,
/// Timestamp representing the date when the member joined.
pub joined_at: Option<DateTime<FixedOffset>>,
/// Indicator of whether the member can speak in voice channels.
pub mute: bool,
/// Vector of Ids of [`Role`]s given to the member.
pub roles: Vec<RoleId>,
}
29 changes: 29 additions & 0 deletions tests/resources/message_create_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": 0,
"tts": false,
"timestamp": "2017-01-01T01:01:01.100000+00:00",
"pinned": false,
"nonce": -6000000000000000,
"mentions": [],
"mention_roles": [],
"mention_everyone": false,
"id": "300000000000000000",
"embeds": [],
"edited_timestamp": null,
"content": "fake",
"channel_id": "100000000000000000",
"author": {
"username": "fake",
"id": "300000000000000000",
"discriminator": "1234",
"bot": true,
"avatar": "f133549aac3208319a9fbc3c12345678"
},
"member": {
"joined_at": "2017-11-19T18:55:33.00000+00:00",
"roles": [381891844067557378, 391753382181863425, 381925348956438528],
"deaf": false,
"mute": false
},
"attachments": []
}
3 changes: 3 additions & 0 deletions tests/test_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ fn message_create() {

// negative nonce
p!(MessageCreateEvent, "message_create_2");

// message from guild with partial member data
p!(MessageCreateEvent, "message_create_3");
}

#[test]
Expand Down

0 comments on commit 0e1e8fb

Please sign in to comment.