diff options
| author | acdenisSK <[email protected]> | 2017-10-02 22:29:10 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-10-02 22:29:10 +0200 |
| commit | 6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249 (patch) | |
| tree | ae9ad7d7cb73d4ece6a199796af5975545071493 /src/model/channel | |
| parent | `to_owned` -> `to_string` (diff) | |
| download | serenity-6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249.tar.xz serenity-6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249.zip | |
Use the de-generification trick.
Fixes #168
Diffstat (limited to 'src/model/channel')
| -rw-r--r-- | src/model/channel/channel_id.rs | 61 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 8 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 6 | ||||
| -rw-r--r-- | src/model/channel/reaction.rs | 12 |
4 files changed, 72 insertions, 15 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 4cc997d..04ed266 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -81,7 +81,11 @@ impl ChannelId { #[inline] pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - http::create_reaction(self.0, message_id.into().0, &reaction_type.into()) + self._create_reaction(message_id.into(), reaction_type.into()) + } + + fn _create_reaction(&self, MessageId(id): MessageId, reaction_type: ReactionType) -> Result<()> { + http::create_reaction(self.0, id, &reaction_type) } /// Deletes this channel, returning the channel on a successful deletion. @@ -100,7 +104,11 @@ impl ChannelId { /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html #[inline] pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - http::delete_message(self.0, message_id.into().0) + self._delete_message(message_id.into()) + } + + fn _delete_message(&self, MessageId(id): MessageId) -> Result<()> { + http::delete_message(self.0, id) } /// Deletes all messages by Ids from the given vector in the given channel. @@ -156,11 +164,18 @@ impl ChannelId { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { + self._delete_reaction(message_id.into(), user_id, reaction_type.into()) + } + + fn _delete_reaction(&self, + MessageId(id): MessageId, + user_id: Option<UserId>, + reaction_type: ReactionType) -> Result<()> { http::delete_reaction( self.0, - message_id.into().0, + id, user_id.map(|uid| uid.0), - &reaction_type.into(), + &reaction_type, ) } @@ -209,6 +224,11 @@ impl ChannelId { /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { + self._edit_message(message_id.into(), f) + } + + fn _edit_message<F>(&self, MessageId(id): MessageId, f: F) -> Result<Message> + where F: FnOnce(CreateMessage) -> CreateMessage { let map = f(CreateMessage::default()).0; if let Some(content) = map.get("content") { @@ -219,7 +239,7 @@ impl ChannelId { } } - http::edit_message(self.0, message_id.into().0, &Value::Object(map)) + http::edit_message(self.0, id, &Value::Object(map)) } /// Search the cache for the channel with the Id. @@ -253,7 +273,11 @@ impl ChannelId { /// [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) + self._message(message_id.into()) + } + + fn _message(&self, MessageId(id): MessageId) -> Result<Message> { + http::get_message(self.0, id) .map(|mut msg| { msg.transform_content(); @@ -326,7 +350,11 @@ impl ChannelId { /// [`Message`]: struct.Message.html #[inline] pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - http::pin_message(self.0, message_id.into().0) + self._pin(message_id.into()) + } + + fn _pin(&self, MessageId(id): MessageId) -> Result<()> { + http::pin_message(self.0, id) } /// Gets the list of [`Message`]s which are pinned to the channel. @@ -354,14 +382,23 @@ impl ChannelId { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self._reaction_users(message_id.into(), reaction_type.into(), limit, after.map(|u| u.into())) + } + + fn _reaction_users(&self, + MessageId(id): MessageId, + reaction_type: ReactionType, + limit: Option<u8>, + after: Option<UserId>) + -> Result<Vec<User>> { let limit = limit.map_or(50, |x| if x > 100 { 100 } else { x }); http::get_reaction_users( self.0, - message_id.into().0, - &reaction_type.into(), + id, + &reaction_type, limit, - after.map(|u| u.into().0), + after.map(|u| u.0), ) } @@ -504,6 +541,10 @@ impl ChannelId { http::unpin_message(self.0, message_id.into().0) } + fn _unpin(&self, MessageId(id): MessageId) -> Result<()> { + http::unpin_message(self.0, id) + } + /// Retrieves the channel's webhooks. /// /// **Note**: Requires the [Manage Webhooks] permission. diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index 418ce3a..dfccca3 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -49,8 +49,10 @@ impl Group { /// /// [`http::add_group_recipient`]: ../http/fn.add_group_recipient.html pub fn add_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> { - let user = user.into(); + self._add_recipient(user.into()) + } + fn _add_recipient(&self, user: UserId) -> Result<()> { // If the group already contains the recipient, do nothing. if self.recipients.contains_key(&user) { return Ok(()); @@ -253,8 +255,10 @@ impl Group { /// /// **Note**: This is only available to the group owner. pub fn remove_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> { - let user = user.into(); + self._remove_recipient(user.into()) + } + fn _remove_recipient(&self, user: UserId) -> Result<()> { // If the group does not contain the recipient already, do nothing. if !self.recipients.contains_key(&user) { return Ok(()); diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 55f61ba..52f5be5 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -419,6 +419,10 @@ impl Message { /// [Add Reactions]: permissions/constant.ADD_REACTIONS.html /// [permissions]: permissions pub fn react<R: Into<ReactionType>>(&self, reaction_type: R) -> Result<()> { + self._react(reaction_type.into()) + } + + fn _react(&self, reaction_type: ReactionType) -> Result<()> { #[cfg(feature = "cache")] { let req = Permissions::ADD_REACTIONS; @@ -428,7 +432,7 @@ impl Message { } } - http::create_reaction(self.channel_id.0, self.id.0, &reaction_type.into()) + http::create_reaction(self.channel_id.0, self.id.0, &reaction_type) } /// Replies to the user, mentioning them prior to the content in the form diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index 8edc2e9..976ea3d 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -106,12 +106,20 @@ impl Reaction { after: Option<U>) -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { + self._users(reaction_type.into(), limit, after.map(|u| u.into())) + } + + fn _users(&self, + reaction_type: ReactionType, + limit: Option<u8>, + after: Option<UserId>) + -> Result<Vec<User>> { http::get_reaction_users( self.channel_id.0, self.message_id.0, - &reaction_type.into(), + &reaction_type, limit.unwrap_or(50), - after.map(|u| u.into().0), + after.map(|u| u.0), ) } } |