diff --git a/src/api/channels/reactions.rs b/src/api/channels/reactions.rs index 3186991..5716697 100644 --- a/src/api/channels/reactions.rs +++ b/src/api/channels/reactions.rs @@ -1,6 +1,10 @@ use reqwest::Client; -use crate::{instance::UserMeta, limit::LimitedRequester, types}; +use crate::{ + instance::UserMeta, + limit::LimitedRequester, + types::{self, Snowflake}, +}; /** Extends the [`types::Reaction`] struct with useful metadata. @@ -118,4 +122,50 @@ impl ReactionMeta { ) .await } + + /* + Create a reaction for the message. + + This endpoint requires the READ_MESSAGE_HISTORY permission + to be present on the current user. Additionally, if nobody else has reacted to the message using + this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current + user. Returns a 204 empty response on success. Fires a Message Reaction Add Gateway event. + + # 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`]. + + # Reference + See https://discord.com/developers/docs/resources/channel#create-reaction + */ + pub async fn create( + channel_id: &Snowflake, + message_id: &Snowflake, + 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(), + channel_id, + message_id, + emoji + ); + let request = Client::new().put(url).bearer_auth(user.token()); + LimitedRequester::new() + .await + .send_request( + request, + crate::api::limits::LimitType::Channel, + &mut belongs_to.limits, + &mut user.limits, + ) + .await + } }