Skip to content

Commit

Permalink
Add 'say' to Group, GuildChannel, PrivateChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyla Hellyer committed Feb 14, 2017
1 parent 585af23 commit a0bb306
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client/context.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
68 changes: 61 additions & 7 deletions src/model/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> {
self.id().say(content)
}

/// Performs a search request to the API for the inner channel's
/// [`Message`]s.
///
Expand Down Expand Up @@ -733,22 +748,16 @@ 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
///
/// 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.
///
/// 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<Message> {
self.send_message(|m| m.content(content))
Expand Down Expand Up @@ -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<Message> {
self.channel_id.say(content)
}

/// Performs a search request to the API for the group's channel's
/// [`Message`]s.
///
Expand Down Expand Up @@ -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<Message> {
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
Expand Down Expand Up @@ -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<Message> {
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
Expand Down

0 comments on commit a0bb306

Please sign in to comment.