aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-03-01 09:03:44 -0800
committerZeyla Hellyer <[email protected]>2017-03-01 09:03:44 -0800
commit9ef55224757dff6dec8576bd1ad11db24a10891e (patch)
treef87ed7d63b56e4652faf4a068355d6657b5fa380 /src
parentFix some clippy lints (diff)
downloadserenity-9ef55224757dff6dec8576bd1ad11db24a10891e.tar.xz
serenity-9ef55224757dff6dec8576bd1ad11db24a10891e.zip
Add Message::guild()
Diffstat (limited to 'src')
-rw-r--r--src/model/channel.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 60e608d..4f67e75 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -1529,6 +1529,22 @@ impl Message {
self.channel_id.get_reaction_users(self.id, reaction_type, limit, after)
}
+ /// Returns the associated `Guild` for the message if one is in the cache.
+ ///
+ /// Returns `None` if the guild's Id could not be found via [`guild_id`] or
+ /// if the Guild itself is not cached.
+ ///
+ /// Requires the `cache` feature be enabled.
+ ///
+ /// [`guild_id`]: #method.guild_id
+ #[cfg(feature="cache")]
+ pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> {
+ match self.guild_id().map(|guild_id| CACHE.read().unwrap().get_guild(guild_id)) {
+ Some(Some(x)) => Some(x),
+ _ => None,
+ }
+ }
+
/// Retrieves the Id of the guild that the message was sent in, if sent in
/// one.
///