diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index d5d321e..e2ff9ba 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -18,6 +18,25 @@ use crate::types::{ use crate::types::{GuildBan, Snowflake}; impl Guild { + /// Fetches a guild by its id. + /// + /// # Reference + /// See + pub async fn get(guild_id: Snowflake, user: &mut ChorusUser) -> ChorusResult { + let chorus_request = ChorusRequest { + request: Client::new() + .get(format!( + "{}/guilds/{}", + user.belongs_to.read().unwrap().urls.api, + guild_id + )) + .header("Authorization", user.token()), + limit_type: LimitType::Guild(guild_id), + }; + let response = chorus_request.deserialize_response::(user).await?; + Ok(response) + } + /// Creates a new guild. /// /// # Reference @@ -38,6 +57,35 @@ impl Guild { chorus_request.deserialize_response::(user).await } + /// Modify a guild's settings. + /// + /// Requires the [MANAGE_GUILD](crate::types::PermissionFlags::MANAGE_GUILD) permission. + /// + /// Returns the updated guild. + /// + /// # Reference + /// + pub async fn modify( + guild_id: Snowflake, + schema: GuildModifySchema, + user: &mut ChorusUser, + ) -> ChorusResult { + let chorus_request = ChorusRequest { + request: Client::new() + .patch(format!( + "{}/guilds/{}", + user.belongs_to.read().unwrap().urls.api, + guild_id, + )) + .header("Authorization", user.token()) + .header("Content-Type", "application/json") + .body(to_string(&schema).unwrap()), + limit_type: LimitType::Guild(guild_id), + }; + let response = chorus_request.deserialize_response::(user).await?; + Ok(response) + } + /// Deletes a guild by its id. /// /// User must be the owner. @@ -127,77 +175,11 @@ impl Guild { }; } - /// Fetches a guild by its id. + /// Returns a guild preview object for the given guild ID. + /// + /// If the user is not in the guild, the guild must be discoverable. /// - /// # Reference - /// See - pub async fn get(guild_id: Snowflake, user: &mut ChorusUser) -> ChorusResult { - let chorus_request = ChorusRequest { - request: Client::new() - .get(format!( - "{}/guilds/{}", - user.belongs_to.read().unwrap().urls.api, - guild_id - )) - .header("Authorization", user.token()), - limit_type: LimitType::Guild(guild_id), - }; - let response = chorus_request.deserialize_response::(user).await?; - Ok(response) - } - - pub async fn create_ban( - guild_id: Snowflake, - user_id: Snowflake, - audit_log_reason: Option, - schema: GuildBanCreateSchema, - user: &mut ChorusUser, - ) -> ChorusResult<()> { - // FIXME: Return GuildBan instead of (). Requires to be resolved. - let request = ChorusRequest::new( - http::Method::PUT, - format!( - "{}/guilds/{}/bans/{}", - user.belongs_to.read().unwrap().urls.api, - guild_id, - user_id - ) - .as_str(), - Some(to_string(&schema).unwrap()), - audit_log_reason.as_deref(), - None, - Some(user), - LimitType::Guild(guild_id), - ); - request.handle_request_as_result(user).await - } - - /// # Reference - /// - pub async fn modify( - guild_id: Snowflake, - schema: GuildModifySchema, - user: &mut ChorusUser, - ) -> ChorusResult { - let chorus_request = ChorusRequest { - request: Client::new() - .patch(format!( - "{}/guilds/{}", - user.belongs_to.read().unwrap().urls.api, - guild_id, - )) - .header("Authorization", user.token()) - .header("Content-Type", "application/json") - .body(to_string(&schema).unwrap()), - limit_type: LimitType::Guild(guild_id), - }; - let response = chorus_request.deserialize_response::(user).await?; - Ok(response) - } - - /// Returns a guild preview object for the given guild ID. If the user is not in the guild, the guild must be discoverable. /// # Reference: - /// /// See pub async fn get_preview( guild_id: Snowflake, @@ -274,7 +256,9 @@ impl Guild { request.deserialize_response::>(user).await } - /// Removes a member from a guild. Requires the KICK_MEMBERS permission. Returns a 204 empty response on success. + /// Removes a member from a guild. + /// + /// Requires the [KICK_MEMBERS](crate::types::PermissionFlags::KICK_MEMBERS) permission. /// /// # Reference /// See @@ -387,7 +371,9 @@ impl Guild { .await } - /// Returns a list of ban objects for the guild. Requires the `BAN_MEMBERS` permission. + /// Returns a list of ban objects for the guild. + /// + /// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission. /// /// # Reference: /// See @@ -417,7 +403,9 @@ impl Guild { request.deserialize_response::>(user).await } - /// Returns a ban object for the given user. Requires the `BAN_MEMBERS` permission. + /// Returns a ban object for the given user. + /// + /// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission. /// /// # Reference: /// See @@ -445,7 +433,39 @@ impl Guild { request.deserialize_response::(user).await } - /// Removes the ban for a user. Requires the BAN_MEMBERS permissions. Returns a 204 empty response on success. + /// Creates a ban from the guild. + /// + /// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission. + /// + pub async fn create_ban( + guild_id: Snowflake, + user_id: Snowflake, + audit_log_reason: Option, + schema: GuildBanCreateSchema, + user: &mut ChorusUser, + ) -> ChorusResult<()> { + // FIXME: Return GuildBan instead of (). Requires to be resolved. + let request = ChorusRequest::new( + http::Method::PUT, + format!( + "{}/guilds/{}/bans/{}", + user.belongs_to.read().unwrap().urls.api, + guild_id, + user_id + ) + .as_str(), + Some(to_string(&schema).unwrap()), + audit_log_reason.as_deref(), + None, + Some(user), + LimitType::Guild(guild_id), + ); + request.handle_request_as_result(user).await + } + + /// Removes the ban for a user. + /// + /// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission. /// /// # Reference: /// See diff --git a/src/api/users/channels.rs b/src/api/users/channels.rs index 15d779c..44ed897 100644 --- a/src/api/users/channels.rs +++ b/src/api/users/channels.rs @@ -13,6 +13,26 @@ use crate::{ }; impl ChorusUser { + /// Fetches a list of private channels the user is in. + /// + /// # Reference: + /// See + pub async fn get_private_channels(&mut self) -> ChorusResult> { + let url = format!( + "{}/users/@me/channels", + self.belongs_to.read().unwrap().urls.api + ); + ChorusRequest { + request: Client::new() + .get(url) + .header("Authorization", self.token()) + .header("Content-Type", "application/json"), + limit_type: LimitType::Global, + } + .deserialize_response::>(self) + .await + } + /// Creates a DM channel or group DM channel. /// /// One recipient creates or returns an existing DM channel, diff --git a/src/types/schema/guild.rs b/src/types/schema/guild.rs index 50519b1..2e29ce0 100644 --- a/src/types/schema/guild.rs +++ b/src/types/schema/guild.rs @@ -38,6 +38,8 @@ pub struct GuildBanCreateSchema { #[derive(Debug, Deserialize, Serialize, Default, Clone, Eq, PartialEq)] #[serde(rename_all = "snake_case")] +/// Represents the schema used to modify a guild. +/// See: pub struct GuildModifySchema { pub name: Option, pub icon: Option>, @@ -47,6 +49,7 @@ pub struct GuildModifySchema { pub discovery_splash: Option>, pub owner_id: Option, pub description: Option, + /// Deprecated pub region: Option, pub afk_channel_id: Option, pub afk_timeout: Option, @@ -56,6 +59,9 @@ pub struct GuildModifySchema { pub features: Option>, pub system_channel_id: Option, pub system_channel_flags: Option, + /// If set to Some(1), will create a new #rules channel + /// + /// Reference: pub rules_channel_id: Option, pub public_updates_channel_id: Option, pub safety_alerts_channel_id: Option,