aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-01 20:12:27 -0800
committerAustin Hellyer <[email protected]>2016-12-01 20:12:27 -0800
commitbceb049bb2b804dac975567bb7eac6afcfc28574 (patch)
tree46952aef055b1b39c381ae4405b313cb5f722b4c /src/model
parentAdd 'fooyoo' to Colour struct (diff)
downloadserenity-bceb049bb2b804dac975567bb7eac6afcfc28574.tar.xz
serenity-bceb049bb2b804dac975567bb7eac6afcfc28574.zip
Add Message::guild_id()
Searches the Cache for the Id of the guild that the message was posted to - if any - and if the guild and channel data are cached. Requires the `cache` and `method` feature flags be enabled.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 13cf506..99fa8c5 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -33,6 +33,8 @@ use ::utils::builder::{CreateEmbed, CreateInvite, EditChannel};
use ::client::CACHE;
#[cfg(all(feature = "methods"))]
use ::client::rest;
+#[cfg(all(feature = "cache", feature = "methods"))]
+use ::ext::cache::ChannelRef;
impl Attachment {
/// If this attachment is an image, then a tuple of the width and height
@@ -528,6 +530,21 @@ impl Message {
}
}
+ /// Retrieves the Id of the guild that the message was sent in, if sent in
+ /// one.
+ ///
+ /// Returns `None` if the channel data or guild data does not exist in the
+ /// cache.
+ #[cfg(all(feature = "cache", feature = "methods"))]
+ pub fn guild_id(&self) -> Option<GuildId> {
+ let cache = CACHE.read().unwrap();
+
+ match cache.get_channel(self.channel_id) {
+ Some(ChannelRef::Guild(channel)) => Some(channel.guild_id),
+ _ => None,
+ }
+ }
+
/// Checks the length of a string to ensure that it is within Discord's
/// maximum message length limit.
///