Merge pull request #87 from polyphony-chat/feature/reactions
Feature/reactions
This commit is contained in:
commit
e49ff7b325
|
@ -7,22 +7,24 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Extends the [`types::Reaction`] struct with useful metadata.
|
Useful metadata for working with [`types::Reaction`], bundled together nicely.
|
||||||
*/
|
*/
|
||||||
pub struct ReactionMeta {
|
pub struct ReactionMeta {
|
||||||
pub message_id: types::Snowflake,
|
pub message_id: types::Snowflake,
|
||||||
pub channel_id: types::Snowflake,
|
pub channel_id: types::Snowflake,
|
||||||
pub reaction: types::Reaction,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReactionMeta {
|
impl ReactionMeta {
|
||||||
/**
|
/**
|
||||||
Deletes all reactions for a message.
|
Deletes all reactions for a message.
|
||||||
|
This endpoint requires the `MANAGE_MESSAGES` permission to be present on the current user.
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
* `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
|
|
||||||
# Returns
|
# Returns
|
||||||
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
||||||
|
Fires a `Message Reaction Remove All` Gateway event.
|
||||||
|
|
||||||
# Reference
|
# Reference
|
||||||
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions)
|
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions)
|
||||||
|
@ -92,8 +94,7 @@ impl ReactionMeta {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Deletes all the reactions for a given `emoji` on a message. This endpoint requires the
|
Deletes all the reactions for a given `emoji` on a message. This endpoint requires the
|
||||||
MANAGE_MESSAGES permission to be present on the current user. Fires a `Message Reaction
|
MANAGE_MESSAGES permission to be present on the current user.
|
||||||
Remove Emoji` Gateway event.
|
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
||||||
|
@ -103,6 +104,7 @@ impl ReactionMeta {
|
||||||
|
|
||||||
# Returns
|
# Returns
|
||||||
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
||||||
|
Fires a `Message Reaction Remove Emoji` Gateway event.
|
||||||
|
|
||||||
# Reference
|
# Reference
|
||||||
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji](https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji)
|
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji](https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji)
|
||||||
|
@ -131,17 +133,14 @@ impl ReactionMeta {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl types::Reaction {
|
|
||||||
/**
|
/**
|
||||||
Create a reaction for the message.
|
Create a reaction for the message.
|
||||||
|
|
||||||
This endpoint requires the READ_MESSAGE_HISTORY permission
|
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
|
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
|
this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current
|
||||||
user. Fires a Message Reaction Add Gateway event.
|
user.
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
* `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
|
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
|
@ -151,13 +150,13 @@ impl types::Reaction {
|
||||||
# Returns
|
# Returns
|
||||||
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
|
||||||
Returns a 204 empty response on success.
|
Returns a 204 empty response on success.
|
||||||
|
Fires a Message Reaction Add Gateway event.
|
||||||
|
|
||||||
# Reference
|
# Reference
|
||||||
See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction)
|
See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction)
|
||||||
*/
|
*/
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
channel_id: &Snowflake,
|
&self,
|
||||||
message_id: &Snowflake,
|
|
||||||
emoji: &str,
|
emoji: &str,
|
||||||
user: &mut UserMeta,
|
user: &mut UserMeta,
|
||||||
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
|
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
|
||||||
|
@ -165,8 +164,8 @@ impl types::Reaction {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
||||||
belongs_to.urls.get_api(),
|
belongs_to.urls.get_api(),
|
||||||
channel_id,
|
self.channel_id,
|
||||||
message_id,
|
self.message_id,
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let request = Client::new().put(url).bearer_auth(user.token());
|
let request = Client::new().put(url).bearer_auth(user.token());
|
||||||
|
@ -180,4 +179,93 @@ impl types::Reaction {
|
||||||
)
|
)
|
||||||
.await
|
.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.
|
||||||
|
|
||||||
|
# Reference
|
||||||
|
See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
|
||||||
|
*/
|
||||||
|
pub async fn remove(
|
||||||
|
&self,
|
||||||
|
emoji: &str,
|
||||||
|
user: &mut UserMeta,
|
||||||
|
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
|
||||||
|
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.
|
||||||
|
|
||||||
|
This endpoint requires the MANAGE_MESSAGES permission to be present on the current user.
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
* `user_id` - A string slice containing the ID of the user whose reaction is to be deleted.
|
||||||
|
* `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.
|
||||||
|
|
||||||
|
# Reference
|
||||||
|
See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
|
||||||
|
*/
|
||||||
|
pub async fn delete_user(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
emoji: &str,
|
||||||
|
user: &mut UserMeta,
|
||||||
|
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
|
||||||
|
let mut belongs_to = user.belongs_to.borrow_mut();
|
||||||
|
let url = format!(
|
||||||
|
"{}/channels/{}/messages/{}/reactions/{}/{}",
|
||||||
|
belongs_to.urls.get_api(),
|
||||||
|
self.channel_id,
|
||||||
|
self.message_id,
|
||||||
|
emoji,
|
||||||
|
user_id
|
||||||
|
);
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue