aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel/guild_channel.rs
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-27 06:42:48 +0200
committeracdenisSK <[email protected]>2017-07-27 07:30:23 +0200
commit550030264952f0e0043b63f4582bb817ef8bbf37 (patch)
treeb921e2f78fd603a5ca671623083a32806fd16090 /src/model/channel/guild_channel.rs
parentUse a consistent indentation style (diff)
downloadserenity-550030264952f0e0043b63f4582bb817ef8bbf37.tar.xz
serenity-550030264952f0e0043b63f4582bb817ef8bbf37.zip
rustfmt
Diffstat (limited to 'src/model/channel/guild_channel.rs')
-rw-r--r--src/model/channel/guild_channel.rs140
1 files changed, 71 insertions, 69 deletions
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index 678e601..250e112 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -1,20 +1,20 @@
use chrono::{DateTime, FixedOffset};
-use ::model::*;
+use model::*;
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use std::fmt::{Display, Formatter, Result as FmtResult};
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use std::mem;
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(feature="model")]
-use ::builder::{CreateInvite, CreateMessage, EditChannel, GetMessages};
-#[cfg(feature="model")]
-use ::http::{self, AttachmentType};
-#[cfg(feature="cache")]
-use ::internal::prelude::*;
-#[cfg(all(feature="model", feature="utils"))]
-use ::utils as serenity_utils;
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(feature = "model")]
+use builder::{CreateInvite, CreateMessage, EditChannel, GetMessages};
+#[cfg(feature = "model")]
+use http::{self, AttachmentType};
+#[cfg(feature = "cache")]
+use internal::prelude::*;
+#[cfg(all(feature = "model", feature = "utils"))]
+use utils as serenity_utils;
/// Represents a guild's text or voice channel. Some methods are available only
/// for voice channels and some are only available for text channels.
@@ -36,7 +36,7 @@ pub struct GuildChannel {
/// incremented by one.
pub guild_id: GuildId,
/// The type of the channel.
- #[serde(rename="type")]
+ #[serde(rename = "type")]
pub kind: ChannelType,
/// The Id of the last message sent in the channel.
///
@@ -69,19 +69,16 @@ pub struct GuildChannel {
/// Used to tell if the channel is not safe for work.
/// Note however, it's recommended to use [`is_nsfw`] as it's gonna be more accurate.
///
- /// [`is_nsfw`]: struct.GuildChannel.html#method.is_nsfw
-
+ /// [`is_nsfw`]: struct.GuildChannel.html#method.is_nsfw
// This field can or can not be present sometimes, but if it isn't
// default to `false`.
#[serde(default = "nsfw_false")]
pub nsfw: bool,
}
-fn nsfw_false() -> bool {
- false
-}
+fn nsfw_false() -> bool { false }
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl GuildChannel {
/// Broadcasts to the channel that the current user is typing.
///
@@ -96,9 +93,7 @@ impl GuildChannel {
///
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
- pub fn broadcast_typing(&self) -> Result<()> {
- self.id.broadcast_typing()
- }
+ pub fn broadcast_typing(&self) -> Result<()> { self.id.broadcast_typing() }
/// Creates an invite leading to the given channel.
///
@@ -110,8 +105,9 @@ impl GuildChannel {
/// let invite = channel.create_invite(|i| i.max_uses(5));
/// ```
pub fn create_invite<F>(&self, f: F) -> Result<RichInvite>
- where F: FnOnce(CreateInvite) -> CreateInvite {
- #[cfg(feature="cache")]
+ where
+ F: FnOnce(CreateInvite) -> CreateInvite, {
+ #[cfg(feature = "cache")]
{
let req = permissions::CREATE_INVITE;
@@ -235,7 +231,7 @@ impl GuildChannel {
/// Deletes this channel, returning the channel on a successful deletion.
pub fn delete(&self) -> Result<Channel> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_CHANNELS;
@@ -285,8 +281,14 @@ impl GuildChannel {
/// [`Reaction`]: struct.Reaction.html
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
- pub fn delete_reaction<M, R>(&self, message_id: M, user_id: Option<UserId>, reaction_type: R)
- -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> {
+ pub fn delete_reaction<M, R>(&self,
+ message_id: M,
+ user_id: Option<UserId>,
+ reaction_type: R)
+ -> Result<()>
+ where
+ M: Into<MessageId>,
+ R: Into<ReactionType>, {
self.id.delete_reaction(message_id, user_id, reaction_type)
}
@@ -302,9 +304,10 @@ impl GuildChannel {
/// channel.edit(|c| c.name("test").bitrate(86400));
/// ```
pub fn edit<F>(&mut self, f: F) -> Result<()>
- where F: FnOnce(EditChannel) -> EditChannel {
+ where
+ F: FnOnce(EditChannel) -> EditChannel, {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_CHANNELS;
@@ -315,8 +318,10 @@ impl GuildChannel {
let mut map = Map::new();
map.insert("name".to_owned(), Value::String(self.name.clone()));
- map.insert("position".to_owned(), Value::Number(Number::from(self.position)));
- map.insert("type".to_owned(), Value::String(self.kind.name().to_owned()));
+ map.insert("position".to_owned(),
+ Value::Number(Number::from(self.position)));
+ map.insert("type".to_owned(),
+ Value::String(self.kind.name().to_owned()));
let edited = f(EditChannel(map)).0;
@@ -351,7 +356,9 @@ impl GuildChannel {
/// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
- where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
+ where
+ F: FnOnce(CreateMessage) -> CreateMessage,
+ M: Into<MessageId>, {
self.id.edit_message(message_id, f)
}
@@ -359,19 +366,15 @@ impl GuildChannel {
///
/// **Note**: Right now this performs a clone of the guild. This will be
/// optimized in the future.
- #[cfg(feature="cache")]
- pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> {
- CACHE.read().unwrap().guild(self.guild_id)
- }
+ #[cfg(feature = "cache")]
+ pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { CACHE.read().unwrap().guild(self.guild_id) }
/// Gets all of the channel's invites.
///
/// Requires the [Manage Channels] permission.
/// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html
#[inline]
- pub fn invites(&self) -> Result<Vec<RichInvite>> {
- self.id.invites()
- }
+ pub fn invites(&self) -> Result<Vec<RichInvite>> { self.id.invites() }
/// Determines if the channel is NSFW.
///
@@ -383,7 +386,7 @@ impl GuildChannel {
/// [`ChannelType::Text`]: enum.ChannelType.html#variant.Text
/// [`ChannelType::Voice`]: enum.ChannelType.html#variant.Voice
/// [`utils::is_nsfw`]: ../utils/fn.is_nsfw.html
- #[cfg(feature="utils")]
+ #[cfg(feature = "utils")]
#[inline]
pub fn is_nsfw(&self) -> bool {
self.kind == ChannelType::Text && (self.nsfw || serenity_utils::is_nsfw(&self.name))
@@ -409,14 +412,13 @@ impl GuildChannel {
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
#[inline]
pub fn messages<F>(&self, f: F) -> Result<Vec<Message>>
- where F: FnOnce(GetMessages) -> GetMessages {
+ where
+ F: FnOnce(GetMessages) -> GetMessages, {
self.id.messages(f)
}
/// Returns the name of the guild channel.
- pub fn name(&self) -> &str {
- &self.name
- }
+ pub fn name(&self) -> &str { &self.name }
/// Calculates the permissions of a member.
///
@@ -471,9 +473,11 @@ impl GuildChannel {
/// };
///
/// let current_user_id = CACHE.read().unwrap().user.id;
- /// let permissions = channel.read().unwrap().permissions_for(current_user_id).unwrap();
+ /// let permissions =
+ /// channel.read().unwrap().permissions_for(current_user_id).unwrap();
///
- /// if !permissions.contains(permissions::ATTACH_FILES | permissions::SEND_MESSAGES) {
+ /// if !permissions.contains(permissions::ATTACH_FILES |
+ /// permissions::SEND_MESSAGES) {
/// return;
/// }
///
@@ -486,7 +490,8 @@ impl GuildChannel {
/// },
/// };
///
- /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m| m.content("here's a cat"));
+ /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m|
+ /// m.content("here's a cat"));
/// }
/// }
///
@@ -506,7 +511,7 @@ impl GuildChannel {
/// [`User`]: struct.User.html
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn permissions_for<U: Into<UserId>>(&self, user_id: U) -> Result<Permissions> {
self.guild()
.ok_or_else(|| Error::Model(ModelError::GuildNotFound))
@@ -515,15 +520,11 @@ impl GuildChannel {
/// Pins a [`Message`] to the channel.
#[inline]
- pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- self.id.pin(message_id)
- }
+ pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.id.pin(message_id) }
/// Gets all channel's pins.
#[inline]
- pub fn pins(&self) -> Result<Vec<Message>> {
- self.id.pins()
- }
+ pub fn pins(&self) -> Result<Vec<Message>> { self.id.pins() }
/// Gets the list of [`User`]s who have reacted to a [`Message`] with a
/// certain [`Emoji`].
@@ -542,8 +543,13 @@ impl GuildChannel {
reaction_type: R,
limit: Option<u8>,
after: Option<U>)
- -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
- self.id.reaction_users(message_id, reaction_type, limit, after)
+ -> Result<Vec<User>>
+ where
+ M: Into<MessageId>,
+ R: Into<ReactionType>,
+ U: Into<UserId>, {
+ self.id
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Sends a message with just the given message content in the channel.
@@ -557,9 +563,7 @@ impl GuildChannel {
/// [`ChannelId`]: struct.ChannelId.html
/// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
- pub fn say(&self, content: &str) -> Result<Message> {
- self.id.say(content)
- }
+ pub fn say(&self, content: &str) -> Result<Message> { self.id.say(content) }
/// Sends (a) file(s) along with optional message contents.
///
@@ -581,7 +585,9 @@ impl GuildChannel {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
- where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
+ where
+ F: FnOnce(CreateMessage) -> CreateMessage,
+ T: Into<AttachmentType<'a>>, {
self.id.send_files(files, f)
}
@@ -605,7 +611,7 @@ impl GuildChannel {
/// [`Message`]: struct.Message.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::SEND_MESSAGES;
@@ -634,15 +640,11 @@ impl GuildChannel {
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
#[inline]
- pub fn webhooks(&self) -> Result<Vec<Webhook>> {
- self.id.webhooks()
- }
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> { self.id.webhooks() }
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Display for GuildChannel {
/// Formats the channel, creating a mention of it.
- fn fmt(&self, f: &mut Formatter) -> FmtResult {
- Display::fmt(&self.id.mention(), f)
- }
+ fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.id.mention(), f) }
}