Skip to content

Commit

Permalink
Add additional methods for deleting reactions to ChannelId and `Mes…
Browse files Browse the repository at this point in the history
…sage` (#2533)
  • Loading branch information
Collin-Swish authored Sep 9, 2023
1 parent ab08c9f commit 1503d53
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,25 @@ impl ChannelId {
)
.await
}
/// Deletes all of the [`Reaction`]s associated with the provided message id.
///
/// **Note**: Requires the [Manage Messages] permission.
///
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission
///
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
#[inline]
pub async fn delete_reactions(
&self,
http: impl AsRef<Http>,
message_id: impl Into<MessageId>,
) -> Result<()> {
http.as_ref().delete_message_reactions(self.0, message_id.into().0).await
}

/// Deletes all [`Reaction`]s of the given emoji to a message within the channel.
///
Expand Down
20 changes: 20 additions & 0 deletions src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,26 @@ impl GuildChannel {
self.id.delete_reaction(&http, message_id, user_id, reaction_type).await
}

/// Deletes all of the [`Reaction`]s associated with the provided message id.
///
/// **Note**: Requires the [Manage Messages] permission.
///
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission
///
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
#[inline]
pub async fn delete_reactions(
&self,
http: impl AsRef<Http>,
message_id: impl Into<MessageId>,
) -> Result<()> {
self.id.delete_reactions(http, message_id).await
}

/// Modifies a channel's settings, such as its position or name.
///
/// Refer to [`EditChannel`]s documentation for a full list of methods.
Expand Down
23 changes: 22 additions & 1 deletion src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,28 @@ impl Message {
}
}

cache_http.http().as_ref().delete_message_reactions(self.channel_id.0, self.id.0).await
self.channel_id.delete_reactions(cache_http.http(), self.id).await
}

/// Deletes the given [`Reaction`] from the message.
///
/// **Note**: Requires the [Manage Messages] permission, _if_ the current user did not perform
/// the reaction.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user did not perform the reaction, or lacks
/// permission.
///
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
#[inline]
pub async fn delete_reaction(
self,
http: impl AsRef<Http>,
user_id: Option<UserId>,
reaction_type: impl Into<ReactionType>,
) -> Result<()> {
self.channel_id.delete_reaction(http, self.id, user_id, reaction_type).await
}

/// Deletes all of the [`Reaction`]s of a given emoji associated with the message.
Expand Down

0 comments on commit 1503d53

Please sign in to comment.