aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-20 06:49:05 -0800
committerAustin Hellyer <[email protected]>2016-11-20 06:49:05 -0800
commited08f98bf45062af34ee729d59a4ace486957878 (patch)
treea23a4f460bf33dd879479e8b8aec69185e1e8e64 /src/model
parentRework contextual presence methods (diff)
downloadserenity-ed08f98bf45062af34ee729d59a4ace486957878.tar.xz
serenity-ed08f98bf45062af34ee729d59a4ace486957878.zip
Add Member::roles()
The roles method will search through the state and find full role data for the member. This is essentially a shorthand for it. This does perform a clone of the role data, but this will be optimized in the future.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/guild.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/model/guild.rs b/src/model/guild.rs
index 538aa02..1c4ffe4 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -923,6 +923,26 @@ impl Member {
},
}
}
+
+ /// Retrieves the full role data for the user's roles.
+ ///
+ /// This is shorthand for manually searching through the state.
+ ///
+ /// If role data can not be found for the member, then `None` is returned.
+ #[cfg(all(feature = "methods", feature = "state"))]
+ pub fn roles(&self) -> Option<Vec<Role>> {
+ STATE.lock().unwrap()
+ .guilds
+ .values()
+ .find(|g| g.members
+ .values()
+ .any(|m| m.user.id == self.user.id && m.joined_at == *self.joined_at))
+ .map(|g| g.roles
+ .values()
+ .filter(|r| self.roles.contains(&r.id))
+ .cloned()
+ .collect())
+ }
}
impl fmt::Display for Member {