Better docs

This commit is contained in:
kozabrada123 2023-07-28 18:45:40 +02:00
parent dcfb59fca1
commit d0547cb1f0
5 changed files with 55 additions and 138 deletions

View File

@ -39,7 +39,7 @@ impl Channel {
} }
/// Modifies a channel with the provided data. /// Modifies a channel with the provided data.
/// Replaces self with the new channel object. /// Returns the new Channel.
pub async fn modify( pub async fn modify(
&self, &self,
modify_data: ChannelModifySchema, modify_data: ChannelModifySchema,

View File

@ -10,7 +10,8 @@ use crate::ratelimiter::ChorusRequest;
use crate::types::{Message, MessageSendSchema, Snowflake}; use crate::types::{Message, MessageSendSchema, Snowflake};
impl Message { impl Message {
/// Sends a message to the Spacebar server. /// Sends a message in the channel with the provided channel_id.
/// Returns the sent message.
pub async fn send( pub async fn send(
user: &mut UserMeta, user: &mut UserMeta,
channel_id: Snowflake, channel_id: Snowflake,
@ -68,14 +69,15 @@ impl Message {
} }
impl UserMeta { impl UserMeta {
/// Sends a message to the Spacebar server. /// Sends a message in the channel with the provided channel_id.
/// Returns the sent message.
/// # Notes /// # Notes
/// Shorthand call for Message::send() /// Shorthand call for Message::send()
pub async fn send_message( pub async fn send_message(
&mut self, &mut self,
message: MessageSendSchema, message: MessageSendSchema,
channel_id: Snowflake, channel_id: Snowflake,
) -> ChorusResult<Message, crate::errors::ChorusError> { ) -> ChorusResult<Message> {
Message::send(self, channel_id, message).await Message::send(self, channel_id, message).await
} }
} }

View File

@ -11,16 +11,6 @@ use crate::{
impl types::Channel { impl types::Channel {
/// Edits the permission overwrites for a channel. /// Edits the permission overwrites for a channel.
///
/// # Arguments
///
/// * `user` - A mutable reference to a [`UserMeta`] instance.
/// * `channel_id` - A string slice representing the ID of the channel.
/// * `overwrite` - A [`PermissionOverwrite`] instance representing the new permission overwrites.
///
/// # Returns
///
/// This function returns a result that is either [`Ok(())`] if the request is successful, or an [`Err(ChorusLibError)`].
pub async fn edit_permissions( pub async fn edit_permissions(
user: &mut UserMeta, user: &mut UserMeta,
channel_id: Snowflake, channel_id: Snowflake,
@ -48,16 +38,6 @@ impl types::Channel {
} }
/// Deletes a permission overwrite for a channel. /// Deletes a permission overwrite for a channel.
///
/// # Arguments
///
/// * `user` - A mutable reference to a [`UserMeta`] instance.
/// * `channel_id` - A string slice representing the ID of the channel.
/// * `overwrite_id` - A string slice representing the ID of the permission overwrite to delete.
///
/// # Returns
///
/// This function returns a Result that is either [`Ok(())`] if the request is successfulm or an [`Err(ChorusLibError)`].
pub async fn delete_permission( pub async fn delete_permission(
user: &mut UserMeta, user: &mut UserMeta,
channel_id: Snowflake, channel_id: Snowflake,

View File

@ -16,12 +16,11 @@ 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.
/// # Returns
/// A `Result` [`()`] [`crate::errors::ChorusError`] if something went wrong.
/// Fires a `Message Reaction Remove All` Gateway event. /// Fires a `Message Reaction Remove All` Gateway event.
///
/// # Reference /// # Reference
/// See <https://discord.com/developers/docs/resources/channel#delete-all-reactions> /// See <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<()> {
@ -39,13 +38,10 @@ impl ReactionMeta {
} }
/// 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 /// The emoji must be URL Encoded or the request will fail with 10014: Unknown Emoji.
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the /// To use custom emoji, the format of the emoji string must be name:id.
/// format name:id with the emoji name and emoji id. ///
/// * `user` - A mutable reference to a [`UserMeta`] instance.
/// # Returns
/// A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong.
/// # Reference /// # Reference
/// See <https://discord.com/developers/docs/resources/channel#get-reactions> /// See <https://discord.com/developers/docs/resources/channel#get-reactions>
pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<Vec<PublicUser>> { pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<Vec<PublicUser>> {
@ -65,16 +61,15 @@ impl ReactionMeta {
.await .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.
/// MANAGE_MESSAGES permission to be present on the current user. ///
/// # Arguments /// This endpoint requires the MANAGE_MESSAGES permission.
/// * `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 emoji must be URL Encoded or the request will fail with 10014: Unknown Emoji.
/// format name:id with the emoji name and emoji id. /// To use custom emoji, the format of the emoji string must be name:id.
/// * `user` - A mutable reference to a [`UserMeta`] instance. ///
/// # Returns /// Fires the `Message Reaction Remove Emoji` Gateway event.
/// A Result that is [`Err(crate::errors::ChorusLibError)`] if something went wrong. ///
/// Fires a `Message Reaction Remove Emoji` Gateway event.
/// # Reference /// # Reference
/// See <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>
pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> { pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> {
@ -92,21 +87,18 @@ impl ReactionMeta {
chorus_request.handle_request_as_result(user).await chorus_request.handle_request_as_result(user).await
} }
/// Create a reaction for the message. /// Create a reaction on a 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 ///
/// user. /// Additionally, if nobody else has reacted to the message using this emoji,
/// # Arguments /// this endpoint requires the ADD_REACTIONS permission.
/// * `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 emoji must be URL Encoded or the request will fail with 10014: Unknown Emoji.
/// format name:id with the emoji name and emoji id. /// To use custom emoji, the format of the emoji string must be name:id.
/// * `user` - A mutable reference to a [`UserMeta`] instance. ///
/// # Returns
/// A `Result` containing [`()`] or a [`crate::errors::ChorusError`].
/// # Reference /// # Reference
/// See <https://discord.com/developers/docs/resources/channel#create-reaction> /// See <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/",
@ -122,15 +114,13 @@ impl ReactionMeta {
chorus_request.handle_request_as_result(user).await chorus_request.handle_request_as_result(user).await
} }
/// Delete a reaction the current user has made for the message. /// Deletes a reaction the current user has made to the message.
/// # Arguments ///
/// * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or /// The reaction emoji must be URL Encoded or the request will fail with 10014: Unknown Emoji.
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the /// To use custom emoji, the format of the emoji string must be name:id.
/// format name:id with the emoji name and emoji id. ///
/// * `user` - A mutable reference to a [`UserMeta`] instance.
/// # Returns
/// A `Result` containing [`()`] or a [`crate::errors::ChorusError`].
/// Fires a `Message Reaction Remove` Gateway event. /// Fires a `Message Reaction Remove` Gateway event.
///
/// # Reference /// # Reference
/// See <https://discord.com/developers/docs/resources/channel#delete-own-reaction> /// See <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<()> {
@ -148,17 +138,15 @@ impl ReactionMeta {
chorus_request.handle_request_as_result(user).await chorus_request.handle_request_as_result(user).await
} }
/// Delete a user's reaction to a message. /// Deletes 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.
/// * `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 /// The reaction emoji must be URL Encoded or the request will fail with 10014: Unknown Emoji.
/// the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the /// To use custom emoji, the format of the emoji string must be name:id.
/// format name:id with the emoji name and emoji id. ///
/// * `user` - A mutable reference to a [`UserMeta`] instance.
/// # Returns
/// A [`ChorusResult`] containing [`()`] or a [`crate::errors::ChorusError`].
/// Fires a Message Reaction Remove Gateway event. /// Fires a Message Reaction Remove Gateway event.
///
/// # Reference /// # Reference
/// See <https://discord.com/developers/docs/resources/channel#delete-user-reaction> /// See <https://discord.com/developers/docs/resources/channel#delete-user-reaction>
pub async fn delete_user( pub async fn delete_user(

View File

@ -11,22 +11,7 @@ use crate::types::Snowflake;
use crate::types::{Channel, ChannelCreateSchema, Guild, GuildCreateSchema}; use crate::types::{Channel, ChannelCreateSchema, Guild, GuildCreateSchema};
impl Guild { impl Guild {
/// Creates a new guild with the given parameters. /// Creates a new guild.
///
/// # Arguments
///
/// * `user` - A mutable reference to the user creating the guild.
/// * `instance` - A mutable reference to the instance where the guild will be created.
/// * `guild_create_schema` - A reference to the schema containing the guild creation parameters.
///
/// # Returns
///
/// A `Result<Guild>` containing the object of the newly created guild, or an error if the request fails.
///
/// # Errors
///
/// Returns an `ChorusLibError` if the request fails.
///
pub async fn create( pub async fn create(
user: &mut UserMeta, user: &mut UserMeta,
guild_create_schema: GuildCreateSchema, guild_create_schema: GuildCreateSchema,
@ -42,17 +27,7 @@ impl Guild {
chorus_request.deserialize_response::<Guild>(user).await chorus_request.deserialize_response::<Guild>(user).await
} }
/// Deletes a guild. /// Deletes a guild by its id.
///
/// # Arguments
///
/// * `user` - A mutable reference to a `User` instance.
/// * `instance` - A mutable reference to an `Instance` instance.
/// * `guild_id` - ID of the guild to delete.
///
/// # Returns
///
/// An `Result` containing an `ChorusLibError` if an error occurred during the request, otherwise `()`.
/// ///
/// # Example /// # Example
/// ///
@ -61,9 +36,9 @@ impl Guild {
/// let mut instance = Instance::new(); /// let mut instance = Instance::new();
/// let guild_id = String::from("1234567890"); /// let guild_id = String::from("1234567890");
/// ///
/// match Guild::delete(&mut user, &mut instance, guild_id) { /// match Guild::delete(&mut user, guild_id) {
/// Some(e) => println!("Error deleting guild: {:?}", e), /// Err(e) => println!("Error deleting guild: {:?}", e),
/// None => println!("Guild deleted successfully"), /// Ok(_) => println!("Guild deleted successfully"),
/// } /// }
/// ``` /// ```
pub async fn delete(user: &mut UserMeta, guild_id: Snowflake) -> ChorusResult<()> { pub async fn delete(user: &mut UserMeta, guild_id: Snowflake) -> ChorusResult<()> {
@ -81,19 +56,7 @@ impl Guild {
chorus_request.handle_request_as_result(user).await chorus_request.handle_request_as_result(user).await
} }
/// Sends a request to create a new channel in the guild. /// Creates a new channel in a guild.
///
/// # Arguments
///
/// * `url_api` - The base URL for the Discord API.
/// * `token` - A Discord bot token.
/// * `schema` - A `ChannelCreateSchema` struct containing the properties of the new channel.
/// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits.
/// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits.
///
/// # Returns
///
/// A `Result` containing a `reqwest::Response` if the request was successful, or an `ChorusLibError` if there was an error.
pub async fn create_channel( pub async fn create_channel(
&self, &self,
user: &mut UserMeta, user: &mut UserMeta,
@ -102,15 +65,7 @@ impl Guild {
Channel::create(user, self.id, schema).await Channel::create(user, self.id, schema).await
} }
/// Returns a `Result` containing a vector of `Channel` structs if the request was successful, or an `ChorusLibError` if there was an error. // TODO: Docs: What is this endpoint?
///
/// # Arguments
///
/// * `url_api` - A string slice that holds the URL of the API.
/// * `token` - A string slice that holds the authorization token.
/// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits.
/// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits.
///
pub async fn channels(&self, user: &mut UserMeta) -> ChorusResult<Vec<Channel>> { pub async fn channels(&self, user: &mut UserMeta) -> ChorusResult<Vec<Channel>> {
let chorus_request = ChorusRequest { let chorus_request = ChorusRequest {
request: Client::new() request: Client::new()
@ -141,16 +96,8 @@ impl Guild {
}; };
} }
/// Returns a `Result` containing a `Guild` struct if the request was successful, or an `ChorusLibError` if there was an error. // TODO: Check if these docs are correct, Im not sure what this endpoint is
/// /// Fetches a given guild.
/// # Arguments
///
/// * `url_api` - A string slice that holds the URL of the API.
/// * `guild_id` - ID of the guild.
/// * `token` - A string slice that holds the authorization token.
/// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits.
/// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits.
///
pub async fn get(guild_id: Snowflake, user: &mut UserMeta) -> ChorusResult<Guild> { pub async fn get(guild_id: Snowflake, user: &mut UserMeta) -> ChorusResult<Guild> {
let chorus_request = ChorusRequest { let chorus_request = ChorusRequest {
request: Client::new() request: Client::new()