From a0bb30686c1a9431aef23c2e8594791f64035194 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Mon, 13 Feb 2017 16:40:18 -0800 Subject: [PATCH] Add 'say' to Group, GuildChannel, PrivateChannel --- src/client/context.rs | 2 +- src/model/channel.rs | 68 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/client/context.rs b/src/client/context.rs index d4744a4953f..2954d2ce0a0 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -1,7 +1,7 @@ use serde_json::builder::ObjectBuilder; use std::sync::{Arc, Mutex}; use super::gateway::Shard; -use super::rest::{self, GuildPagination}; +use super::rest; use super::login_type::LoginType; use typemap::ShareMap; use ::utils::builder::EditProfile; diff --git a/src/model/channel.rs b/src/model/channel.rs index 834fa9b3bf5..2c4240509f3 100644 --- a/src/model/channel.rs +++ b/src/model/channel.rs @@ -330,6 +330,21 @@ impl Channel { } } + /// Sends a message with just the given message content in the channel. + /// + /// # Errors + /// + /// Returns a [`ClientError::MessageTooLong`] if the content of the message + /// is over the above limit, containing the number of unicode code points + /// over the limit. + /// + /// [`ChannelId`]: ../model/struct.ChannelId.html + /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong + #[inline] + pub fn say(&self, content: &str) -> Result { + self.id().say(content) + } + /// Performs a search request to the API for the inner channel's /// [`Message`]s. /// @@ -733,8 +748,7 @@ impl ChannelId { rest::get_pins(self.0) } - /// Sends a message with just the given message content in the channel that - /// a message was received from. + /// Sends a message with just the given message content in the channel. /// /// # Errors /// @@ -742,13 +756,8 @@ impl ChannelId { /// is over the above limit, containing the number of unicode code points /// over the limit. /// - /// Returns a [`ClientError::NoChannelId`] when there is no [`ChannelId`] - /// directly available; i.e. when not under the context of one of the above - /// events. - /// /// [`ChannelId`]: ../model/struct.ChannelId.html /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong - /// [`ClientError::NoChannelId`]: enum.ClientError.html#NoChannelId #[inline] pub fn say(&self, content: &str) -> Result { self.send_message(|m| m.content(content)) @@ -1115,6 +1124,21 @@ impl Group { rest::remove_group_recipient(self.channel_id.0, user.0) } + /// Sends a message with just the given message content in the channel. + /// + /// # Errors + /// + /// Returns a [`ClientError::MessageTooLong`] if the content of the message + /// is over the above limit, containing the number of unicode code points + /// over the limit. + /// + /// [`ChannelId`]: ../model/struct.ChannelId.html + /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong + #[inline] + pub fn say(&self, content: &str) -> Result { + self.channel_id.say(content) + } + /// Performs a search request to the API for the group's channel's /// [`Message`]s. /// @@ -1718,6 +1742,21 @@ impl PrivateChannel { self.id.pins() } + /// Sends a message with just the given message content in the channel. + /// + /// # Errors + /// + /// Returns a [`ClientError::MessageTooLong`] if the content of the message + /// is over the above limit, containing the number of unicode code points + /// over the limit. + /// + /// [`ChannelId`]: ../model/struct.ChannelId.html + /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong + #[inline] + pub fn say(&self, content: &str) -> Result { + self.id.say(content) + } + /// Performs a search request to the API for the channel's [`Message`]s. /// /// Refer to the documentation for the [`Search`] builder for examples and @@ -2136,6 +2175,21 @@ impl GuildChannel { self.id.pins() } + /// Sends a message with just the given message content in the channel. + /// + /// # Errors + /// + /// Returns a [`ClientError::MessageTooLong`] if the content of the message + /// is over the above limit, containing the number of unicode code points + /// over the limit. + /// + /// [`ChannelId`]: ../model/struct.ChannelId.html + /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong + #[inline] + pub fn say(&self, content: &str) -> Result { + self.id.say(content) + } + /// Performs a search request for the channel's [`Message`]s. /// /// Refer to the documentation for the [`Search`] builder for examples and