diff options
| author | acdenisSK <[email protected]> | 2017-10-24 18:10:10 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-10-24 18:10:10 +0200 |
| commit | ef60c3cd5b93d61ff8200f5f6871b449bf7dccb5 (patch) | |
| tree | ff9ec9e09dc363c05c6b582380a120ca47290a9f /src/model/user.rs | |
| parent | Remove `on_` prefix to EventHandler tymethods (diff) | |
| parent | Fall back to `str::parse` if `parse_username` fails (diff) | |
| download | serenity-ef60c3cd5b93d61ff8200f5f6871b449bf7dccb5.tar.xz serenity-ef60c3cd5b93d61ff8200f5f6871b449bf7dccb5.zip | |
Merge v0.4.2
Diffstat (limited to 'src/model/user.rs')
| -rw-r--r-- | src/model/user.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/model/user.rs b/src/model/user.rs index 0d8388d..1bf69e4 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -349,7 +349,7 @@ impl Default for OnlineStatus { } /// Information about a user. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash)] +#[derive(Clone, Debug, Deserialize)] pub struct User { /// The unique Id of the user. Can be used to calculate the account's /// cration date. @@ -371,6 +371,22 @@ pub struct User { pub name: String, } +use std::hash::{Hash, Hasher}; + +impl PartialEq for User { + fn eq(&self, other: &Self) -> bool { + self.id == other.id + } +} + +impl Eq for User {} + +impl Hash for User { + fn hash<H: Hasher>(&self, hasher: &mut H) { + self.id.hash(hasher); + } +} + #[cfg(feature = "model")] impl User { /// Returns the formatted URL of the user's icon, if one exists. @@ -584,7 +600,11 @@ impl User { CACHE.read() .guilds .get(&_guild_id) - .map(|g| g.read().roles.contains_key(&role_id)) + .map(|g| { + g.read().unwrap().members.get(&self.id) + .map(|m| m.roles.contains(&role_id)) + .unwrap_or(false) + }) .unwrap_or(false) } else { true |