Merge pull request #134 from polyphony-chat/bug/reactionsget-returns-generic-successfailure
Make ReactionMeta::get() return a Vec<PublicUser>
This commit is contained in:
commit
dbf4f634b4
|
@ -1,10 +1,10 @@
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::handle_request_as_result,
|
api::{deserialize_response, handle_request_as_result},
|
||||||
errors::ChorusResult,
|
errors::ChorusResult,
|
||||||
instance::UserMeta,
|
instance::UserMeta,
|
||||||
types::{self, Snowflake},
|
types::{self, PublicUser, Snowflake},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,20 +16,15 @@ pub struct ReactionMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
||||||
This endpoint requires the `MANAGE_MESSAGES` permission to be present on the current user.
|
/// # Arguments
|
||||||
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
# Arguments
|
/// # Returns
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// A `Result` [`()`] [`crate::errors::ChorusLibError`] if something went wrong.
|
||||||
|
/// Fires a `Message Reaction Remove All` Gateway event.
|
||||||
# Returns
|
/// # Reference
|
||||||
A `Result` [`()`] [`crate::errors::ChorusLibError`] if something went wrong.
|
/// See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions)
|
||||||
Fires a `Message Reaction Remove All` Gateway event.
|
|
||||||
|
|
||||||
# Reference
|
|
||||||
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions)
|
|
||||||
*/
|
|
||||||
pub async fn delete_all(&self, user: &mut UserMeta) -> ChorusResult<()> {
|
pub async fn delete_all(&self, user: &mut UserMeta) -> ChorusResult<()> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/",
|
"{}/channels/{}/messages/{}/reactions/",
|
||||||
|
@ -41,22 +36,17 @@ impl ReactionMeta {
|
||||||
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Gets a list of users that reacted with a specific emoji to a message.
|
||||||
Gets a list of users that reacted with a specific emoji to a message.
|
/// # Arguments
|
||||||
|
/// * `emoji` - A string slice containing the emoji to search for. The emoji must be URL Encoded or
|
||||||
# Arguments
|
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
* `emoji` - A string slice containing the emoji to search for. The emoji must be URL Encoded or
|
/// format name:id with the emoji name and emoji id.
|
||||||
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
format name:id with the emoji name and emoji id.
|
/// # Returns
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong.
|
||||||
|
/// # Reference
|
||||||
# Returns
|
/// See [https://discord.com/developers/docs/resources/channel#get-reactions](https://discord.com/developers/docs/resources/channel#get-reactions)
|
||||||
A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong.
|
pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<Vec<PublicUser>> {
|
||||||
|
|
||||||
# Reference
|
|
||||||
See [https://discord.com/developers/docs/resources/channel#get-reactions](https://discord.com/developers/docs/resources/channel#get-reactions)
|
|
||||||
*/
|
|
||||||
pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/{}/",
|
"{}/channels/{}/messages/{}/reactions/{}/",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
|
@ -65,26 +55,26 @@ impl ReactionMeta {
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let request = Client::new().get(url).bearer_auth(user.token());
|
let request = Client::new().get(url).bearer_auth(user.token());
|
||||||
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
deserialize_response::<Vec<PublicUser>>(
|
||||||
|
request,
|
||||||
|
user,
|
||||||
|
crate::api::limits::LimitType::Channel,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// 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.
|
||||||
MANAGE_MESSAGES permission to be present on the current user.
|
/// # Arguments
|
||||||
|
/// * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
||||||
# Arguments
|
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
/// format name:id with the emoji name and emoji id.
|
||||||
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
format name:id with the emoji name and emoji id.
|
/// # Returns
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong.
|
||||||
|
/// Fires a `Message Reaction Remove Emoji` Gateway event.
|
||||||
# Returns
|
/// # Reference
|
||||||
A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong.
|
/// 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)
|
||||||
Fires a `Message Reaction Remove Emoji` Gateway event.
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
*/
|
|
||||||
pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/{}/",
|
"{}/channels/{}/messages/{}/reactions/{}/",
|
||||||
|
@ -97,25 +87,21 @@ impl ReactionMeta {
|
||||||
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Create a reaction for the message.
|
||||||
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 endpoint requires the READ_MESSAGE_HISTORY permission
|
/// this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current
|
||||||
to be present on the current user. Additionally, if nobody else has reacted to the message using
|
/// user.
|
||||||
this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current
|
/// # Arguments
|
||||||
user.
|
/// * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
||||||
# Arguments
|
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
/// format name:id with the emoji name and emoji id.
|
||||||
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
format name:id with the emoji name and emoji id.
|
/// # Returns
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
||||||
|
/// # Reference
|
||||||
# Returns
|
/// See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction)
|
||||||
A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
///
|
||||||
|
|
||||||
# Reference
|
|
||||||
See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction)
|
|
||||||
*/
|
|
||||||
pub async fn create(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
pub async fn create(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
||||||
|
@ -128,22 +114,17 @@ impl ReactionMeta {
|
||||||
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Delete a reaction the current user has made for the message.
|
||||||
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
|
||||||
# Arguments
|
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
/// format name:id with the emoji name and emoji id.
|
||||||
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
format name:id with the emoji name and emoji id.
|
/// # Returns
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
||||||
|
/// Fires a `Message Reaction Remove` Gateway event.
|
||||||
# Returns
|
/// # Reference
|
||||||
A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
/// See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
|
||||||
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) -> ChorusResult<()> {
|
pub async fn remove(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
"{}/channels/{}/messages/{}/reactions/{}/@me/",
|
||||||
|
@ -156,25 +137,19 @@ impl ReactionMeta {
|
||||||
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
handle_request_as_result(request, user, crate::api::limits::LimitType::Channel).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Delete a user's reaction to a message.
|
||||||
Delete a user's reaction to a message.
|
/// This endpoint requires the MANAGE_MESSAGES permission to be present on the current user.
|
||||||
|
/// # Arguments
|
||||||
This endpoint requires the MANAGE_MESSAGES permission to be present on the current user.
|
/// * `user_id` - 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
|
||||||
# Arguments
|
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
||||||
* `user_id` - ID of the user whose reaction is to be deleted.
|
/// format name:id with the emoji name and emoji id.
|
||||||
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
|
/// * `user` - A mutable reference to a [`UserMeta`] instance.
|
||||||
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
|
/// # Returns
|
||||||
format name:id with the emoji name and emoji id.
|
/// A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
||||||
* `user` - A mutable reference to a [`UserMeta`] instance.
|
/// Fires a Message Reaction Remove Gateway event.
|
||||||
|
/// # Reference
|
||||||
# Returns
|
/// See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
|
||||||
A `Result` containing [`()`] or a [`crate::errors::ChorusLibError`].
|
|
||||||
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(
|
pub async fn delete_user(
|
||||||
&self,
|
&self,
|
||||||
user_id: Snowflake,
|
user_id: Snowflake,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use chorus::{
|
use chorus::{
|
||||||
errors::ChorusResult,
|
|
||||||
instance::{Instance, UserMeta},
|
instance::{Instance, UserMeta},
|
||||||
types::{
|
types::{
|
||||||
Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema,
|
Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema,
|
||||||
|
|
Loading…
Reference in New Issue