diff options
| author | Maiddog <[email protected]> | 2017-08-26 17:55:43 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-08-27 00:55:43 +0200 |
| commit | 3e0b1032d80a1847558a752e8316d97f9ae58f04 (patch) | |
| tree | ca65390091cb3c0ab98b6497a1447ba69df3d20d /src/model/channel | |
| parent | Use `$crate` for `Args` (diff) | |
| download | serenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.tar.xz serenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.zip | |
Add ability to play DCA and Opus files. (#148)
Diffstat (limited to 'src/model/channel')
| -rw-r--r-- | src/model/channel/channel_id.rs | 19 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 17 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 15 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 29 | ||||
| -rw-r--r-- | src/model/channel/mod.rs | 50 | ||||
| -rw-r--r-- | src/model/channel/private_channel.rs | 10 |
6 files changed, 90 insertions, 50 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index cf9e41c..122b5bc 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -100,7 +100,7 @@ impl ChannelId { /// [`Message::delete`]: struct.Message.html#method.delete /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html #[inline] -pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ + pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { http::delete_message(self.0, message_id.into().0) } @@ -187,7 +187,7 @@ pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ /// [`Channel`]: enum.Channel.html /// [Manage Channel]: permissions/constant.MANAGE_CHANNELS.html #[inline] -pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildChannel>{ + pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildChannel> { http::edit_channel(self.0, &f(EditChannel::default()).0) } @@ -256,12 +256,13 @@ pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildC /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - http::get_message(self.0, message_id.into().0) - .map(|mut msg| { + http::get_message(self.0, message_id.into().0).map( + |mut msg| { msg.transform_content(); msg - }) + }, + ) } /// Gets messages from the channel. @@ -306,9 +307,11 @@ pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildC 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, + Group(channel) => { + match channel.read().unwrap().name() { + Cow::Borrowed(name) => name.to_string(), + Cow::Owned(name) => name, + } }, Private(channel) => channel.read().unwrap().name(), }) diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index 94483ec..ad20fcd 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -124,8 +124,11 @@ impl Group { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self.channel_id - .delete_reaction(message_id, user_id, reaction_type) + self.channel_id.delete_reaction( + message_id, + user_id, + reaction_type, + ) } /// Edits a [`Message`] in the channel given its Id. @@ -243,8 +246,12 @@ impl Group { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.channel_id - .reaction_users(message_id, reaction_type, limit, after) + self.channel_id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Removes a recipient from the group. If the recipient is already not in @@ -309,7 +316,7 @@ impl Group { /// [`CreateMessage`]: ../builder/struct.CreateMessage.html /// [Send Messages]: permissions/constant.SEND_MESSAGES.html #[inline] -pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message>{ + pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> { self.channel_id.send_message(f) } diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 620ba93..d4e93f0 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -310,7 +310,10 @@ impl GuildChannel { } let mut map = Map::new(); - map.insert("name".to_owned(), Value::String(self.name.clone())); + map.insert( + "name".to_owned(), + Value::String(self.name.clone()), + ); map.insert( "position".to_owned(), Value::Number(Number::from(self.position)), @@ -539,8 +542,12 @@ impl GuildChannel { 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) + self.id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Sends a message with just the given message content in the channel. @@ -599,7 +606,7 @@ impl GuildChannel { /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong /// [`Message`]: struct.Message.html /// [Send Messages]: permissions/constant.SEND_MESSAGES.html -pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message>{ + pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> { #[cfg(feature = "cache")] { let req = permissions::SEND_MESSAGES; diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 399d351..27f4e31 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -291,9 +291,10 @@ impl Message { } // And finally replace everyone and here mentions. - result - .replace("@everyone", "@\u{200B}everyone") - .replace("@here", "@\u{200B}here") + result.replace("@everyone", "@\u{200B}everyone").replace( + "@here", + "@\u{200B}here", + ) } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a @@ -319,8 +320,12 @@ impl Message { after: Option<U>) -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { - self.channel_id - .reaction_users(self.id, reaction_type, limit, after) + self.channel_id.reaction_users( + self.id, + reaction_type, + limit, + after, + ) } /// Returns the associated `Guild` for the message if one is in the cache. @@ -333,8 +338,9 @@ impl Message { /// [`guild_id`]: #method.guild_id #[cfg(feature = "cache")] pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { - self.guild_id() - .and_then(|guild_id| CACHE.read().unwrap().guild(guild_id)) + self.guild_id().and_then(|guild_id| { + CACHE.read().unwrap().guild(guild_id) + }) } /// Retrieves the Id of the guild that the message was sent in, if sent in @@ -354,7 +360,8 @@ impl Message { #[cfg(feature = "cache")] pub fn is_private(&self) -> bool { match CACHE.read().unwrap().channel(self.channel_id) { - Some(Channel::Group(_)) | Some(Channel::Private(_)) => true, + Some(Channel::Group(_)) | + Some(Channel::Private(_)) => true, _ => false, } } @@ -371,11 +378,7 @@ impl Message { let count = content.chars().count() as i64; let diff = count - (constants::MESSAGE_CODE_LIMIT as i64); - if diff > 0 { - Some(diff as u64) - } else { - None - } + if diff > 0 { Some(diff as u64) } else { None } } /// Pins this message to its channel. diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 0911139..ddaa183 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -100,7 +100,7 @@ impl Channel { /// [`Message::delete`]: struct.Message.html#method.delete /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html #[inline] -pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ + pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.id().delete_message(message_id) } @@ -118,8 +118,11 @@ pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self.id() - .delete_reaction(message_id, user_id, reaction_type) + self.id().delete_reaction( + message_id, + user_id, + reaction_type, + ) } /// Edits a [`Message`] in the channel given its Id. @@ -157,7 +160,8 @@ pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ pub fn is_nsfw(&self) -> bool { match *self { Channel::Guild(ref channel) => channel.with(|c| c.is_nsfw()), - Channel::Group(_) | Channel::Private(_) => false, + Channel::Group(_) | + Channel::Private(_) => false, } } @@ -217,8 +221,12 @@ pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ 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) + self.id().reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or @@ -319,15 +327,21 @@ impl<'de> Deserialize<'de> for Channel { }; match kind { - 0 | 2 => serde_json::from_value::<GuildChannel>(Value::Object(v)) - .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), - 1 => serde_json::from_value::<PrivateChannel>(Value::Object(v)) - .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), - 3 => serde_json::from_value::<Group>(Value::Object(v)) - .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), + 0 | 2 => { + serde_json::from_value::<GuildChannel>(Value::Object(v)) + .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, + 1 => { + serde_json::from_value::<PrivateChannel>(Value::Object(v)) + .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, + 3 => { + serde_json::from_value::<Group>(Value::Object(v)) + .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, _ => Err(DeError::custom("Unknown channel type")), } } @@ -399,8 +413,10 @@ impl ChannelType { struct PermissionOverwriteData { allow: Permissions, deny: Permissions, - #[serde(deserialize_with = "deserialize_u64")] id: u64, - #[serde(rename = "type")] kind: String, + #[serde(deserialize_with = "deserialize_u64")] + id: u64, + #[serde(rename = "type")] + kind: String, } /// A channel-specific permission overwrite for a member or role. diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index e5e14d9..d9abbb2 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -192,8 +192,12 @@ impl PrivateChannel { 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) + self.id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Pins a [`Message`] to the channel. @@ -259,7 +263,7 @@ impl PrivateChannel { /// [`CreateMessage`]: ../builder/struct.CreateMessage.html /// [`Message`]: struct.Message.html #[inline] -pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message>{ + pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> { self.id.send_message(f) } |