diff options
| author | acdenisSK <[email protected]> | 2017-07-14 00:29:28 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-14 00:29:28 +0200 |
| commit | ca0f113324c1ed64a8646c42ed742dd8021fbccd (patch) | |
| tree | 69dbf3e9d1b39f2553d0ce8280e1adb49e7c3865 /src | |
| parent | Provide the command into the checks (diff) | |
| download | serenity-ca0f113324c1ed64a8646c42ed742dd8021fbccd.tar.xz serenity-ca0f113324c1ed64a8646c42ed742dd8021fbccd.zip | |
Add `ChannelId,PrivateChannel,GuildChannel::name` functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/channel/channel_id.rs | 23 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 5 | ||||
| -rw-r--r-- | src/model/channel/private_channel.rs | 5 |
3 files changed, 33 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 diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index a506187..995586e 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -400,6 +400,11 @@ impl GuildChannel { self.id.messages(f) } + /// Returns the name of the guild channel. + pub fn name(&self) -> &str { + &self.name + } + /// Calculates the permissions of a member. /// /// The Id of the argument must be a [`Member`] of the [`Guild`] that the diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 570a212..5d70a73 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -170,6 +170,11 @@ impl PrivateChannel { self.id.messages(f) } + /// Returns "DM with $username$". + pub fn name(&self) -> String { + format!("DM with {}", self.recipient.read().unwrap().tag()) + } + /// Gets the list of [`User`]s who have reacted to a [`Message`] with a /// certain [`Emoji`]. /// |