From 0a106d2e1d453190878b095d5a9386cc5342a13c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 4 Jun 2023 14:39:22 +0200 Subject: [PATCH] Add method to remove own reaction --- src/api/channels/reactions.rs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/api/channels/reactions.rs b/src/api/channels/reactions.rs index 52a0134..f95db3a 100644 --- a/src/api/channels/reactions.rs +++ b/src/api/channels/reactions.rs @@ -180,6 +180,45 @@ impl ReactionMeta { .await } + /** + Delete a reaction the current user has made for the message. + + # Arguments + * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or + the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the + format name:id with the emoji name and emoji id. + * `user` - A mutable reference to a [`UserMeta`] instance. + + # Returns + A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`]. + Returns a 204 empty response on success. + Fires a `Message Reaction Remove` Gateway event. + */ + pub async fn remove( + &self, + emoji: &str, + user: &mut UserMeta, + ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); + let url = format!( + "{}/channels/{}/messages/{}/reactions/{}/@me/", + belongs_to.urls.get_api(), + self.channel_id, + self.message_id, + emoji + ); + let request = Client::new().delete(url).bearer_auth(user.token()); + LimitedRequester::new() + .await + .send_request( + request, + crate::api::limits::LimitType::Channel, + &mut belongs_to.limits, + &mut user.limits, + ) + .await + } + /** Delete a user's reaction to a message.