aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel/channel_id.rs
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-14 00:29:28 +0200
committeracdenisSK <[email protected]>2017-07-14 00:29:28 +0200
commitca0f113324c1ed64a8646c42ed742dd8021fbccd (patch)
tree69dbf3e9d1b39f2553d0ce8280e1adb49e7c3865 /src/model/channel/channel_id.rs
parentProvide the command into the checks (diff)
downloadserenity-ca0f113324c1ed64a8646c42ed742dd8021fbccd.tar.xz
serenity-ca0f113324c1ed64a8646c42ed742dd8021fbccd.zip
Add `ChannelId,PrivateChannel,GuildChannel::name` functions
Diffstat (limited to 'src/model/channel/channel_id.rs')
-rw-r--r--src/model/channel/channel_id.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index 21ce9f1..f83062c 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -2,6 +2,8 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
use ::model::*;
#[cfg(feature="model")]
+use std::borrow::Cow;
+#[cfg(feature="model")]
use std::fmt::Write as FmtWrite;
#[cfg(feature="model")]
use ::builder::{CreateMessage, EditChannel, GetMessages};
@@ -291,6 +293,27 @@ impl ChannelId {
}).collect::<Vec<Message>>())
}
+ /// Returns the name of whatever channel this id holds.
+ #[cfg(feature="model")]
+ pub fn name(&self) -> Option<String> {
+ use self::Channel::*;
+
+ Some(match match self.find() { Some(c) => c, None => return None, } {
+ Guild(channel) => {
+ channel.read().unwrap().name().to_string()
+ },
+ Group(channel) => {
+ match channel.read().unwrap().name() {
+ Cow::Borrowed(name) => name.to_string(),
+ Cow::Owned(name) => name,
+ }
+ },
+ Private(channel) => {
+ channel.read().unwrap().name()
+ }
+ })
+ }
+
/// Pins a [`Message`] to the channel.
///
/// [`Message`]: struct.Message.html