From d3d09cdd954ed1d1f4f272dc41a768073c3ef66e Mon Sep 17 00:00:00 2001 From: Gnome! Date: Fri, 29 Mar 2024 20:13:19 +0000 Subject: [PATCH] Add audit log reasons to remaining model methods (#2821) --- examples/e14_message_components/src/main.rs | 2 +- examples/testing/src/main.rs | 4 +- src/builder/edit_role.rs | 4 +- src/model/channel/channel_id.rs | 53 ++++--- src/model/channel/guild_channel.rs | 51 +++++-- src/model/channel/message.rs | 12 +- src/model/channel/mod.rs | 4 +- src/model/channel/private_channel.rs | 11 +- src/model/error.rs | 2 +- src/model/guild/guild_id.rs | 152 +++++++++++--------- src/model/guild/member.rs | 87 ++++------- src/model/guild/mod.rs | 117 +++++++++------ src/model/guild/partial_guild.rs | 116 +++++++++------ src/model/guild/role.rs | 4 +- src/model/invite.rs | 8 +- src/model/sticker.rs | 4 +- src/model/webhook.rs | 6 +- 17 files changed, 360 insertions(+), 277 deletions(-) diff --git a/examples/e14_message_components/src/main.rs b/examples/e14_message_components/src/main.rs index 2698d5ff96f..8e4c065145d 100644 --- a/examples/e14_message_components/src/main.rs +++ b/examples/e14_message_components/src/main.rs @@ -131,7 +131,7 @@ impl EventHandler for Handler { // Delete the orig message or there will be dangling components (components that still // exist, but no collector is running so any user who presses them sees an error) - m.delete(&ctx).await.unwrap() + m.delete(&ctx, None).await.unwrap() } } diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 0de79e52f8f..29b2d28eeca 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -148,7 +148,7 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> { } else if let Some(user_id) = msg.content.strip_prefix("ban ") { // Test if banning without a reason actually works let user_id: UserId = user_id.trim().parse().unwrap(); - guild_id.ban(&ctx.http, user_id, 0).await?; + guild_id.ban(&ctx.http, user_id, 0, None).await?; } else if msg.content == "createtags" { channel_id .edit( @@ -224,7 +224,7 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> { serenity::utils::parse_message_url(forum_post_url).unwrap(); msg.channel_id.say(ctx, format!("Deleting <#{}> in 10 seconds...", channel_id)).await?; tokio::time::sleep(std::time::Duration::from_secs(10)).await; - channel_id.delete(&ctx.http).await?; + channel_id.delete(&ctx.http, None).await?; } else { return Ok(()); } diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index dc08d753442..d1f000e485b 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -177,9 +177,7 @@ impl<'a> EditRole<'a> { }; if let Some(position) = self.position { - guild_id - .edit_role_position_with_reason(http, role.id, position, self.audit_log_reason) - .await?; + guild_id.edit_role_position(http, role.id, position, self.audit_log_reason).await?; } Ok(role) } diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index e005ca93d3d..d17c7132016 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -95,9 +95,14 @@ impl ChannelId { /// set. /// /// [Manage Channels]: Permissions::MANAGE_CHANNELS - pub async fn create_permission(self, http: &Http, target: PermissionOverwrite) -> Result<()> { + pub async fn create_permission( + self, + http: &Http, + target: PermissionOverwrite, + reason: Option<&str>, + ) -> Result<()> { let data: PermissionOverwriteData = target.into(); - http.create_permission(self, data.id, &data, None).await + http.create_permission(self, data.id, &data, reason).await } /// React to a [`Message`] with a custom [`Emoji`] or unicode character. @@ -130,8 +135,8 @@ impl ChannelId { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Channels]: Permissions::MANAGE_CHANNELS - pub async fn delete(self, http: &Http) -> Result { - http.delete_channel(self, None).await + pub async fn delete(self, http: &Http, reason: Option<&str>) -> Result { + http.delete_channel(self, reason).await } /// Deletes a [`Message`] given its Id. @@ -146,8 +151,13 @@ impl ChannelId { /// Returns [`Error::Http`] if the current user lacks permission to delete the message. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn delete_message(self, http: &Http, message_id: MessageId) -> Result<()> { - http.delete_message(self, message_id, None).await + pub async fn delete_message( + self, + http: &Http, + message_id: MessageId, + reason: Option<&str>, + ) -> Result<()> { + http.delete_message(self, message_id, reason).await } /// Deletes messages by Ids from the given vector in the given channel. @@ -167,7 +177,12 @@ impl ChannelId { /// Also will return [`Error::Http`] if the current user lacks permission to delete messages. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn delete_messages(self, http: &Http, message_ids: &[MessageId]) -> Result<()> { + pub async fn delete_messages( + self, + http: &Http, + message_ids: &[MessageId], + reason: Option<&str>, + ) -> Result<()> { use crate::model::error::{Maximum, Minimum}; #[derive(serde::Serialize)] @@ -179,13 +194,13 @@ impl ChannelId { Maximum::BulkDeleteAmount.check_overflow(message_ids.len())?; if message_ids.len() == 1 { - self.delete_message(http, message_ids[0]).await + self.delete_message(http, message_ids[0], reason).await } else { let req = DeleteMessages { messages: message_ids, }; - http.delete_messages(self, &req, None).await + http.delete_messages(self, &req, reason).await } } @@ -202,12 +217,13 @@ impl ChannelId { self, http: &Http, permission_type: PermissionOverwriteType, + reason: Option<&str>, ) -> Result<()> { let id = match permission_type { PermissionOverwriteType::Member(id) => id.into(), PermissionOverwriteType::Role(id) => id.get().into(), }; - http.delete_permission(self, id, None).await + http.delete_permission(self, id, reason).await } /// Deletes the given [`Reaction`] from the channel. @@ -504,8 +520,8 @@ impl ChannelId { /// many pinned messages. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn pin(self, http: &Http, message_id: MessageId) -> Result<()> { - http.pin_message(self, message_id, None).await + pub async fn pin(self, http: &Http, message_id: MessageId, reason: Option<&str>) -> Result<()> { + http.pin_message(self, message_id, reason).await } /// Crossposts a [`Message`]. @@ -743,8 +759,13 @@ impl ChannelId { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn unpin(self, http: &Http, message_id: MessageId) -> Result<()> { - http.unpin_message(self, message_id, None).await + pub async fn unpin( + self, + http: &Http, + message_id: MessageId, + reason: Option<&str>, + ) -> Result<()> { + http.unpin_message(self, message_id, reason).await } /// Retrieves the channel's webhooks. @@ -849,8 +870,8 @@ impl ChannelId { /// /// Returns [`Error::Http`] if the channel is not a stage channel, or if there is no stage /// instance currently. - pub async fn delete_stage_instance(self, http: &Http) -> Result<()> { - http.delete_stage_instance(self, None).await + pub async fn delete_stage_instance(self, http: &Http, reason: Option<&str>) -> Result<()> { + http.delete_stage_instance(self, reason).await } /// Creates a public thread that is connected to a message. diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 1ef3fe86de8..1943475e4d4 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -254,8 +254,13 @@ impl GuildChannel { /// # Errors /// /// Returns [`Error::Http`] if the current user lacks permission. - pub async fn create_permission(&self, http: &Http, target: PermissionOverwrite) -> Result<()> { - self.id.create_permission(http, target).await + pub async fn create_permission( + &self, + http: &Http, + target: PermissionOverwrite, + reason: Option<&str>, + ) -> Result<()> { + self.id.create_permission(http, target, reason).await } /// Deletes this channel, returning the channel on a successful deletion. @@ -270,7 +275,11 @@ impl GuildChannel { /// Otherwise returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Channels]: Permissions::MANAGE_CHANNELS - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result { + pub async fn delete( + &self, + cache_http: impl CacheHttp, + reason: Option<&str>, + ) -> Result { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { @@ -283,7 +292,7 @@ impl GuildChannel { } } - let channel = self.id.delete(cache_http.http()).await?; + let channel = self.id.delete(cache_http.http(), reason).await?; channel.guild().ok_or(Error::Model(ModelError::InvalidChannelType)) } @@ -301,8 +310,13 @@ impl GuildChannel { /// delete either 0 or more than 100 messages. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn delete_messages(&self, http: &Http, message_ids: &[MessageId]) -> Result<()> { - self.id.delete_messages(http, message_ids).await + pub async fn delete_messages( + &self, + http: &Http, + message_ids: &[MessageId], + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_messages(http, message_ids, reason).await } /// Deletes all permission overrides in the channel from a member or role. @@ -318,8 +332,9 @@ impl GuildChannel { &self, http: &Http, permission_type: PermissionOverwriteType, + reason: Option<&str>, ) -> Result<()> { - self.id.delete_permission(http, permission_type).await + self.id.delete_permission(http, permission_type, reason).await } /// Deletes the given [`Reaction`] from the channel. @@ -657,8 +672,13 @@ impl GuildChannel { /// too many pinned messages. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn pin(&self, http: &Http, message_id: MessageId) -> Result<()> { - self.id.pin(http, message_id).await + pub async fn pin( + &self, + http: &Http, + message_id: MessageId, + reason: Option<&str>, + ) -> Result<()> { + self.id.pin(http, message_id, reason).await } /// Gets all channel's pins. @@ -806,8 +826,13 @@ impl GuildChannel { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn unpin(&self, http: &Http, message_id: MessageId) -> Result<()> { - self.id.unpin(http, message_id).await + pub async fn unpin( + &self, + http: &Http, + message_id: MessageId, + reason: Option<&str>, + ) -> Result<()> { + self.id.unpin(http, message_id, reason).await } /// Retrieves the channel's webhooks. @@ -972,12 +997,12 @@ impl GuildChannel { /// Returns [`ModelError::InvalidChannelType`] if the channel is not a stage channel. /// /// Returns [`Error::Http`] if there is no stage instance currently. - pub async fn delete_stage_instance(&self, http: &Http) -> Result<()> { + pub async fn delete_stage_instance(&self, http: &Http, reason: Option<&str>) -> Result<()> { if self.kind != ChannelType::Stage { return Err(Error::Model(ModelError::InvalidChannelType)); } - self.id.delete_stage_instance(http).await + self.id.delete_stage_instance(http, reason).await } /// Creates a public thread that is connected to a message. diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index fcb28ea69a2..69ad8cd2d29 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -234,7 +234,7 @@ impl Message { /// current user does not have the required permissions. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()> { + pub async fn delete(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result<()> { #[cfg(feature = "cache")] { if let (Some(cache), Some(guild_id)) = (cache_http.cache(), self.guild_id) { @@ -249,7 +249,7 @@ impl Message { } } - self.channel_id.delete_message(cache_http.http(), self.id).await + self.channel_id.delete_message(cache_http.http(), self.id, reason).await } /// Deletes all of the [`Reaction`]s associated with the message. @@ -490,7 +490,7 @@ impl Message { /// does not have the required permissions. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn pin(&self, cache_http: impl CacheHttp) -> Result<()> { + pub async fn pin(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result<()> { #[cfg(feature = "cache")] { if let (Some(cache), Some(guild_id)) = (cache_http.cache(), self.guild_id) { @@ -503,7 +503,7 @@ impl Message { } } - self.channel_id.pin(cache_http.http(), self.id).await + self.channel_id.pin(cache_http.http(), self.id, reason).await } /// React to the message with a custom [`Emoji`] or unicode character. @@ -750,7 +750,7 @@ impl Message { /// does not have the required permissions. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn unpin(&self, cache_http: impl CacheHttp) -> Result<()> { + pub async fn unpin(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result<()> { #[cfg(feature = "cache")] { if let (Some(cache), Some(guild_id)) = (cache_http.cache(), self.guild_id) { @@ -763,7 +763,7 @@ impl Message { } } - cache_http.http().unpin_message(self.channel_id, self.id, None).await + cache_http.http().unpin_message(self.channel_id, self.id, reason).await } /// Ends the [`Poll`] on this message, if there is one. diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 8082f40e761..79f6fccd4a4 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -121,10 +121,10 @@ impl Channel { /// lacks permission. /// /// Otherwise will return [`Error::Http`] if the current user does not have permission. - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()> { + pub async fn delete(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result<()> { match self { Self::Guild(public_channel) => { - public_channel.delete(cache_http).await?; + public_channel.delete(cache_http, reason).await?; }, Self::Private(private_channel) => { private_channel.delete(cache_http.http()).await?; diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 3a87dac488c..1044832f658 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -69,7 +69,8 @@ impl PrivateChannel { /// closing a private channel on the client, which can be re-opened. #[allow(clippy::missing_errors_doc)] pub async fn delete(&self, http: &Http) -> Result { - self.id.delete(http).await?.private().ok_or(Error::Model(ModelError::InvalidChannelType)) + let resp = self.id.delete(http, None).await?; + resp.private().ok_or(Error::Model(ModelError::InvalidChannelType)) } /// Deletes all messages by Ids from the given vector in the channel. @@ -87,7 +88,7 @@ impl PrivateChannel { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES pub async fn delete_messages(&self, http: &Http, message_ids: &[MessageId]) -> Result<()> { - self.id.delete_messages(http, message_ids).await + self.id.delete_messages(http, message_ids, None).await } /// Deletes all permission overrides in the channel from a member or role. @@ -101,7 +102,7 @@ impl PrivateChannel { http: &Http, permission_type: PermissionOverwriteType, ) -> Result<()> { - self.id.delete_permission(http, permission_type).await + self.id.delete_permission(http, permission_type, None).await } /// Deletes the given [`Reaction`] from the channel. @@ -202,7 +203,7 @@ impl PrivateChannel { /// /// Returns [`Error::Http`] if the number of pinned messages would exceed the 50 message limit. pub async fn pin(&self, http: &Http, message_id: MessageId) -> Result<()> { - self.id.pin(http, message_id).await + self.id.pin(http, message_id, None).await } /// Retrieves the list of messages that have been pinned in the private channel. @@ -318,7 +319,7 @@ impl PrivateChannel { /// Returns [`Error::Http`] if the current user lacks permission, if the message was deleted, /// or if the channel already has the limit of 50 pinned messages. pub async fn unpin(&self, http: &Http, message_id: MessageId) -> Result<()> { - self.id.unpin(http, message_id).await + self.id.unpin(http, message_id, None).await } } diff --git a/src/model/error.rs b/src/model/error.rs index 72a57ff1e41..f1e3c4b5bca 100644 --- a/src/model/error.rs +++ b/src/model/error.rs @@ -117,7 +117,7 @@ impl fmt::Display for Minimum { /// #[cfg(feature = "client")] /// impl EventHandler for Handler { /// async fn guild_ban_removal(&self, ctx: &Context, guild_id: &GuildId, user: &User) { -/// match guild_id.ban(&ctx.http, user.id, 8).await { +/// match guild_id.ban(&ctx.http, user.id, 8, Some("No unbanning people!")).await { /// Ok(()) => { /// // Ban successful. /// }, diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index a8307f5b412..e7407a66a0d 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -31,6 +31,7 @@ use crate::gateway::ShardMessenger; use crate::http::{CacheHttp, Http, UserPagination}; #[cfg(feature = "model")] use crate::internal::prelude::*; +use crate::model::error::Maximum; use crate::model::guild::SerializeIter; use crate::model::prelude::*; @@ -138,8 +139,13 @@ impl GuildId { /// does not exist. /// /// [Manage Guild]: Permissions::MANAGE_GUILD - pub async fn delete_automod_rule(self, http: &Http, rule_id: RuleId) -> Result<()> { - http.delete_automod_rule(self, rule_id, None).await + pub async fn delete_automod_rule( + self, + http: &Http, + rule_id: RuleId, + reason: Option<&str>, + ) -> Result<()> { + http.delete_automod_rule(self, rule_id, reason).await } /// Adds a [`User`] to this guild with a valid OAuth2 access token. @@ -178,7 +184,7 @@ impl GuildId { /// # let http: Http = unimplemented!(); /// # let user = UserId::new(1); /// // assuming a `user` has already been bound - /// let _ = GuildId::new(81384788765712384).ban(&http, user, 4).await; + /// let _ = GuildId::new(81384788765712384).ban(&http, user, 4, None).await; /// # Ok(()) /// # } /// ``` @@ -191,30 +197,7 @@ impl GuildId { /// Also can return [`Error::Http`] if the current user lacks permission. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn ban(self, http: &Http, user: UserId, dmd: u8) -> Result<()> { - self.ban_(http, user, dmd, None).await - } - - /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further - /// documentation. - /// - /// # Errors - /// - /// In addition to the reasons [`Self::ban`] may return an error, may also return - /// [`ModelError::TooLarge`] if `reason` is too long. - pub async fn ban_with_reason( - self, - http: &Http, - user: UserId, - dmd: u8, - reason: &str, - ) -> Result<()> { - self.ban_(http, user, dmd, Some(reason)).await - } - - async fn ban_(self, http: &Http, user: UserId, dmd: u8, reason: Option<&str>) -> Result<()> { - use crate::model::error::Maximum; - + pub async fn ban(self, http: &Http, user: UserId, dmd: u8, reason: Option<&str>) -> Result<()> { Maximum::DeleteMessageDays.check_overflow(dmd.into())?; if let Some(reason) = reason { Maximum::AuditLogReason.check_overflow(reason.len())?; @@ -360,7 +343,13 @@ impl GuildId { /// /// [`EditProfile::avatar`]: crate::builder::EditProfile::avatar /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS - pub async fn create_emoji(self, http: &Http, name: &str, image: &str) -> Result { + pub async fn create_emoji( + self, + http: &Http, + name: &str, + image: &str, + reason: Option<&str>, + ) -> Result { #[derive(serde::Serialize)] struct CreateEmoji<'a> { name: &'a str, @@ -372,7 +361,7 @@ impl GuildId { image, }; - http.create_emoji(self, &body, None).await + http.create_emoji(self, &body, reason).await } /// Creates an integration for the guild. @@ -389,6 +378,7 @@ impl GuildId { http: &Http, integration_id: IntegrationId, kind: &str, + reason: Option<&str>, ) -> Result<()> { #[derive(serde::Serialize)] struct CreateIntegration<'a> { @@ -402,7 +392,7 @@ impl GuildId { kind, }; - http.create_guild_integration(self, integration_id, &body, None).await + http.create_guild_integration(self, integration_id, &body, reason).await } /// Creates a new role in the guild with the data set, if any. @@ -484,8 +474,13 @@ impl GuildId { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_emoji(self, http: &Http, emoji_id: EmojiId) -> Result<()> { - http.delete_emoji(self, emoji_id, None).await + pub async fn delete_emoji( + self, + http: &Http, + emoji_id: EmojiId, + reason: Option<&str>, + ) -> Result<()> { + http.delete_emoji(self, emoji_id, reason).await } /// Deletes an integration by Id from the guild. @@ -502,8 +497,9 @@ impl GuildId { self, http: &Http, integration_id: IntegrationId, + reason: Option<&str>, ) -> Result<()> { - http.delete_guild_integration(self, integration_id, None).await + http.delete_guild_integration(self, integration_id, reason).await } /// Deletes a [`Role`] by Id from the guild. @@ -518,8 +514,13 @@ impl GuildId { /// does not exist. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn delete_role(self, http: &Http, role_id: RoleId) -> Result<()> { - http.delete_role(self, role_id, None).await + pub async fn delete_role( + self, + http: &Http, + role_id: RoleId, + reason: Option<&str>, + ) -> Result<()> { + http.delete_role(self, role_id, reason).await } /// Deletes a specified scheduled event in the guild. @@ -554,8 +555,13 @@ impl GuildId { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_sticker(self, http: &Http, sticker_id: StickerId) -> Result<()> { - http.delete_sticker(self, sticker_id, None).await + pub async fn delete_sticker( + self, + http: &Http, + sticker_id: StickerId, + reason: Option<&str>, + ) -> Result<()> { + http.delete_sticker(self, sticker_id, reason).await } /// Edits the current guild with new data where specified. @@ -589,7 +595,13 @@ impl GuildId { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn edit_emoji(self, http: &Http, emoji_id: EmojiId, name: &str) -> Result { + pub async fn edit_emoji( + self, + http: &Http, + emoji_id: EmojiId, + name: &str, + reason: Option<&str>, + ) -> Result { #[derive(serde::Serialize)] struct EditEmoji<'a> { name: &'a str, @@ -599,7 +611,7 @@ impl GuildId { name, }; - http.edit_emoji(self, emoji_id, &map, None).await + http.edit_emoji(self, emoji_id, &map, reason).await } /// Edits the properties a guild member, such as muting or nicknaming them. Returns the new @@ -650,18 +662,22 @@ impl GuildId { self, http: &Http, mfa_level: MfaLevel, - audit_log_reason: Option<&str>, + reason: Option<&str>, ) -> Result { #[derive(serde::Serialize)] struct EditMfaModel { level: MfaLevel, } + if let Some(reason) = reason { + Maximum::AuditLogReason.check_overflow(reason.len())?; + } + let map = EditMfaModel { level: mfa_level, }; - http.edit_guild_mfa_level(self, &map, audit_log_reason).await + http.edit_guild_mfa_level(self, &map, reason).await } /// Edits the current user's nickname for the guild. @@ -675,7 +691,12 @@ impl GuildId { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Change Nickname]: Permissions::CHANGE_NICKNAME - pub async fn edit_nickname(self, http: &Http, new_nickname: Option<&str>) -> Result<()> { + pub async fn edit_nickname( + self, + http: &Http, + new_nickname: Option<&str>, + reason: Option<&str>, + ) -> Result<()> { #[derive(serde::Serialize)] struct EditNickname<'a> { nick: Option<&'a str>, @@ -685,7 +706,7 @@ impl GuildId { nick: new_nickname, }; - http.edit_nickname(self, &map, None).await + http.edit_nickname(self, &map, reason).await } /// Edits a [`Role`], optionally setting its new fields. @@ -809,20 +830,6 @@ impl GuildId { http: &Http, role_id: RoleId, position: i16, - ) -> Result> { - self.edit_role_position_with_reason(http, role_id, position, None).await - } - - /// Edit the position of a [`Role`] relative to all others in the [`Guild`]. - /// - /// # Errors - /// - /// See [`GuildId::edit_role_position`] for more details. - pub async fn edit_role_position_with_reason( - self, - http: &Http, - role_id: RoleId, - position: i16, reason: Option<&str>, ) -> Result> { #[derive(serde::Serialize)] @@ -831,6 +838,10 @@ impl GuildId { position: i16, } + if let Some(reason) = reason { + Maximum::AuditLogReason.check_overflow(reason.len())?; + } + let map = EditRole { id: role_id, position, @@ -1011,16 +1022,12 @@ impl GuildId { /// Returns [`Error::Http`] if the member cannot be kicked by the current user. /// /// [Kick Members]: Permissions::KICK_MEMBERS - pub async fn kick(self, http: &Http, user_id: UserId) -> Result<()> { - http.kick_member(self, user_id, None).await - } + pub async fn kick(self, http: &Http, user_id: UserId, reason: Option<&str>) -> Result<()> { + if let Some(reason) = reason { + Maximum::AuditLogReason.check_overflow(reason.len())?; + } - /// # Errors - /// - /// In addition to the reasons [`Self::kick`] may return an error, may also return an error if - /// the reason is too long. - pub async fn kick_with_reason(self, http: &Http, user_id: UserId, reason: &str) -> Result<()> { - http.kick_member(self, user_id, Some(reason)).await + http.kick_member(self, user_id, reason).await } /// Returns a guild [`Member`] object for the current user. @@ -1349,8 +1356,13 @@ impl GuildId { /// /// [Kick Members]: Permissions::KICK_MEMBERS /// [Manage Guild]: Permissions::MANAGE_GUILD - pub async fn start_prune(self, http: &Http, days: u8) -> Result { - http.start_guild_prune(self, days, None).await + pub async fn start_prune( + self, + http: &Http, + days: u8, + reason: Option<&str>, + ) -> Result { + http.start_guild_prune(self, days, reason).await } /// Unbans a [`User`] from the guild. @@ -1362,8 +1374,8 @@ impl GuildId { /// Returns [`Error::Http`] if the current user does not have permission. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn unban(self, http: &Http, user_id: UserId) -> Result<()> { - http.remove_ban(self, user_id, None).await + pub async fn unban(self, http: &Http, user_id: UserId, reason: Option<&str>) -> Result<()> { + http.remove_ban(self, user_id, reason).await } /// Retrieve's the guild's vanity URL. diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index be37e09644f..56df27e6708 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -107,8 +107,8 @@ impl Member { /// Id does not exist. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn add_role(&self, http: &Http, role_id: RoleId) -> Result<()> { - http.add_member_role(self.guild_id, self.user.id, role_id, None).await + pub async fn add_role(&self, http: &Http, role_id: RoleId, reason: Option<&str>) -> Result<()> { + http.add_member_role(self.guild_id, self.user.id, role_id, reason).await } /// Adds one or multiple [`Role`]s to the member. @@ -121,9 +121,14 @@ impl Member { /// does not exist. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn add_roles(&self, http: &Http, role_ids: &[RoleId]) -> Result<()> { + pub async fn add_roles( + &self, + http: &Http, + role_ids: &[RoleId], + reason: Option<&str>, + ) -> Result<()> { for &role_id in role_ids { - self.add_role(http, role_id).await?; + self.add_role(http, role_id, reason).await?; } Ok(()) @@ -140,19 +145,8 @@ impl Member { /// return [`Error::Http`] if the current user lacks permission to ban this member. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn ban(&self, http: &Http, dmd: u8) -> Result<()> { - self.ban_with_reason(http, dmd, "").await - } - - /// Ban the member from the guild with a reason. Refer to [`Self::ban`] to further - /// documentation. - /// - /// # Errors - /// - /// In addition to the errors [`Self::ban`] may return, can also return - /// [`ModelError::TooLarge`] if the length of the reason is greater than 512. - pub async fn ban_with_reason(&self, http: &Http, dmd: u8, reason: &str) -> Result<()> { - self.guild_id.ban_with_reason(http, self.user.id, dmd, reason).await + pub async fn ban(&self, http: &Http, dmd: u8, audit_log_reason: Option<&str>) -> Result<()> { + self.guild_id.ban(http, self.user.id, dmd, audit_log_reason).await } /// Determines the member's colour. @@ -281,7 +275,7 @@ impl Member { /// /// ```rust,ignore /// // assuming a `member` has already been bound - /// match member.kick().await { + /// match member.kick(None).await { /// Ok(()) => println!("Successfully kicked member"), /// Err(Error::Model(ModelError::GuildNotFound)) => { /// println!("Couldn't determine guild of member"); @@ -304,38 +298,7 @@ impl Member { /// Otherwise will return [`Error::Http`] if the current user lacks permission. /// /// [Kick Members]: Permissions::KICK_MEMBERS - pub async fn kick(&self, cache_http: impl CacheHttp) -> Result<()> { - self.kick_with_reason(cache_http, "").await - } - - /// Kicks the member from the guild, with a reason. - /// - /// **Note**: Requires the [Kick Members] permission. - /// - /// # Examples - /// - /// Kicks a member from it's guild, with an optional reason: - /// - /// ```rust,ignore - /// match member.kick(&ctx.http, "A Reason").await { - /// Ok(()) => println!("Successfully kicked member"), - /// Err(Error::Model(ModelError::GuildNotFound)) => { - /// println!("Couldn't determine guild of member"); - /// }, - /// Err(Error::Model(ModelError::InvalidPermissions(missing_perms))) => { - /// println!("Didn't have permissions; missing: {:?}", missing_perms); - /// }, - /// _ => {}, - /// } - /// ``` - /// - /// # Errors - /// - /// In addition to the reasons [`Self::kick`] may return an error, can also return an error if - /// the given reason is too long. - /// - /// [Kick Members]: Permissions::KICK_MEMBERS - pub async fn kick_with_reason(&self, cache_http: impl CacheHttp, reason: &str) -> Result<()> { + pub async fn kick(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result<()> { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { @@ -348,7 +311,7 @@ impl Member { } } - self.guild_id.kick_with_reason(cache_http.http(), self.user.id, reason).await + self.guild_id.kick(cache_http.http(), self.user.id, reason).await } /// Moves the member to a voice channel. @@ -412,8 +375,13 @@ impl Member { /// lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn remove_role(&self, http: &Http, role_id: RoleId) -> Result<()> { - http.remove_member_role(self.guild_id, self.user.id, role_id, None).await + pub async fn remove_role( + &self, + http: &Http, + role_id: RoleId, + reason: Option<&str>, + ) -> Result<()> { + http.remove_member_role(self.guild_id, self.user.id, role_id, reason).await } /// Removes one or multiple [`Role`]s from the member. @@ -426,9 +394,14 @@ impl Member { /// lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn remove_roles(&self, http: &Http, role_ids: &[RoleId]) -> Result<()> { + pub async fn remove_roles( + &self, + http: &Http, + role_ids: &[RoleId], + reason: Option<&str>, + ) -> Result<()> { for &role_id in role_ids { - self.remove_role(http, role_id).await?; + self.remove_role(http, role_id, reason).await?; } Ok(()) @@ -462,8 +435,8 @@ impl Member { /// does not have permission to perform bans. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn unban(&self, http: &Http) -> Result<()> { - http.remove_ban(self.guild_id, self.user.id, None).await + pub async fn unban(&self, http: &Http, reason: Option<&str>) -> Result<()> { + http.remove_ban(self.guild_id, self.user.id, reason).await } /// Returns the formatted URL of the member's per guild avatar, if one exists. diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index a9b4b8a31e1..d7ee7fbd776 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -354,8 +354,13 @@ impl Guild { /// does not exist. /// /// [Manage Guild]: Permissions::MANAGE_GUILD - pub async fn delete_automod_rule(&self, http: &Http, rule_id: RuleId) -> Result<()> { - self.id.delete_automod_rule(http, rule_id).await + pub async fn delete_automod_rule( + &self, + http: &Http, + rule_id: RuleId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_automod_rule(http, rule_id, reason).await } #[cfg(feature = "cache")] @@ -430,7 +435,7 @@ impl Guild { /// /// ```rust,ignore /// // assumes a `user` and `guild` have already been bound - /// let _ = guild.ban(user, 4); + /// let _ = guild.ban(user, 4, None); /// ``` /// /// # Errors @@ -445,23 +450,12 @@ impl Guild { /// Otherwise returns [`Error::Http`] if the member cannot be banned. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn ban(&self, cache_http: impl CacheHttp, user: UserId, dmd: u8) -> Result<()> { - self.ban_with_reason(cache_http, user, dmd, "").await - } - - /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further - /// documentation. - /// - /// # Errors - /// - /// In addition to the possible reasons [`Self::ban`] may return an error, an - /// [`ModelError::TooLarge`] may also be returned if the reason is too long. - pub async fn ban_with_reason( + pub async fn ban( &self, cache_http: impl CacheHttp, user: UserId, dmd: u8, - reason: &str, + reason: Option<&str>, ) -> Result<()> { #[cfg(feature = "cache")] { @@ -472,7 +466,7 @@ impl Guild { } } - self.id.ban_with_reason(cache_http.http(), user, dmd, reason).await + self.id.ban(cache_http.http(), user, dmd, reason).await } /// Bans multiple users from the guild, returning the users that were and weren't banned. @@ -677,8 +671,14 @@ impl Guild { /// [`EditProfile::avatar`]: crate::builder::EditProfile::avatar /// [`CreateAttachment`]: crate::builder::CreateAttachment /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS - pub async fn create_emoji(&self, http: &Http, name: &str, image: &str) -> Result { - self.id.create_emoji(http, name, image).await + pub async fn create_emoji( + &self, + http: &Http, + name: &str, + image: &str, + reason: Option<&str>, + ) -> Result { + self.id.create_emoji(http, name, image, reason).await } /// Creates an integration for the guild. @@ -695,8 +695,9 @@ impl Guild { http: &Http, integration_id: IntegrationId, kind: &str, + reason: Option<&str>, ) -> Result<()> { - self.id.create_integration(http, integration_id, kind).await + self.id.create_integration(http, integration_id, kind, reason).await } /// Create a guild specific application [`Command`]. @@ -908,8 +909,13 @@ impl Guild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_emoji(&self, http: &Http, emoji_id: EmojiId) -> Result<()> { - self.id.delete_emoji(http, emoji_id).await + pub async fn delete_emoji( + &self, + http: &Http, + emoji_id: EmojiId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_emoji(http, emoji_id, reason).await } /// Deletes an integration by Id from the guild. @@ -926,8 +932,9 @@ impl Guild { &self, http: &Http, integration_id: IntegrationId, + reason: Option<&str>, ) -> Result<()> { - self.id.delete_integration(http, integration_id).await + self.id.delete_integration(http, integration_id, reason).await } /// Deletes a [`Role`] by Id from the guild. @@ -941,8 +948,13 @@ impl Guild { /// Returns [`Error::Http`] if the current user lacks permission to delete the role. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn delete_role(&self, http: &Http, role_id: RoleId) -> Result<()> { - self.id.delete_role(http, role_id).await + pub async fn delete_role( + &self, + http: &Http, + role_id: RoleId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_role(http, role_id, reason).await } /// Deletes a [`ScheduledEvent`] by id from the guild. @@ -977,8 +989,13 @@ impl Guild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_sticker(&self, http: &Http, sticker_id: StickerId) -> Result<()> { - self.id.delete_sticker(http, sticker_id).await + pub async fn delete_sticker( + &self, + http: &Http, + sticker_id: StickerId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_sticker(http, sticker_id, reason).await } /// Edits the current guild with new data where specified. @@ -1042,8 +1059,14 @@ impl Guild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn edit_emoji(&self, http: &Http, emoji_id: EmojiId, name: &str) -> Result { - self.id.edit_emoji(http, emoji_id, name).await + pub async fn edit_emoji( + &self, + http: &Http, + emoji_id: EmojiId, + name: &str, + reason: Option<&str>, + ) -> Result { + self.id.edit_emoji(http, emoji_id, name, reason).await } /// Edits the properties a guild member, such as muting or nicknaming them. Returns the new @@ -1102,6 +1125,7 @@ impl Guild { &self, cache_http: impl CacheHttp, new_nickname: Option<&str>, + reason: Option<&str>, ) -> Result<()> { #[cfg(feature = "cache")] { @@ -1110,7 +1134,7 @@ impl Guild { } } - self.id.edit_nickname(cache_http.http(), new_nickname).await + self.id.edit_nickname(cache_http.http(), new_nickname, reason).await } /// Edits a role, optionally setting its fields. @@ -1157,8 +1181,9 @@ impl Guild { http: &Http, role_id: RoleId, position: i16, + audit_log_reason: Option<&str>, ) -> Result> { - self.id.edit_role_position(http, role_id, position).await + self.id.edit_role_position(http, role_id, position, audit_log_reason).await } /// Modifies a scheduled event in the guild with the data set, if any. @@ -1441,16 +1466,8 @@ impl Guild { /// Returns [`Error::Http`] if the member cannot be kicked by the current user. /// /// [Kick Members]: Permissions::KICK_MEMBERS - pub async fn kick(&self, http: &Http, user_id: UserId) -> Result<()> { - self.id.kick(http, user_id).await - } - - /// # Errors - /// - /// In addition to the reasons [`Self::kick`] may return an error, may also return an error if - /// the reason is too long. - pub async fn kick_with_reason(&self, http: &Http, user_id: UserId, reason: &str) -> Result<()> { - self.id.kick_with_reason(http, user_id, reason).await + pub async fn kick(&self, http: &Http, user_id: UserId, reason: Option<&str>) -> Result<()> { + self.id.kick(http, user_id, reason).await } /// Returns a guild [`Member`] object for the current user. @@ -2098,7 +2115,12 @@ impl Guild { /// [Manage Guild]: Permissions::MANAGE_GUILD /// [`Error::Http`]: crate::error::Error::Http /// [`Error::Json`]: crate::error::Error::Json - pub async fn start_prune(&self, cache_http: impl CacheHttp, days: u8) -> Result { + pub async fn start_prune( + &self, + cache_http: impl CacheHttp, + days: u8, + reason: Option<&str>, + ) -> Result { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { @@ -2106,7 +2128,7 @@ impl Guild { } } - self.id.start_prune(cache_http.http(), days).await + self.id.start_prune(cache_http.http(), days, reason).await } /// Unbans the given [`User`] from the guild. @@ -2121,7 +2143,12 @@ impl Guild { /// Otherwise will return an [`Error::Http`] if the current user does not have permission. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn unban(&self, cache_http: impl CacheHttp, user_id: UserId) -> Result<()> { + pub async fn unban( + &self, + cache_http: impl CacheHttp, + user_id: UserId, + reason: Option<&str>, + ) -> Result<()> { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { @@ -2129,7 +2156,7 @@ impl Guild { } } - self.id.unban(cache_http.http(), user_id).await + self.id.unban(cache_http.http(), user_id, reason).await } /// Retrieve's the guild's vanity URL. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index 3a30680c3ea..96eb7c47bc7 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -251,8 +251,13 @@ impl PartialGuild { /// does not exist. /// /// [Manage Guild]: Permissions::MANAGE_GUILD - pub async fn delete_automod_rule(&self, http: &Http, rule_id: RuleId) -> Result<()> { - self.id.delete_automod_rule(http, rule_id).await + pub async fn delete_automod_rule( + &self, + http: &Http, + rule_id: RuleId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_automod_rule(http, rule_id, reason).await } /// Ban a [`User`] from the guild, deleting a number of days' worth of messages (`dmd`) between @@ -277,25 +282,14 @@ impl PartialGuild { /// Also may return [`Error::Http`] if the current user lacks permission. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn ban(&self, http: &Http, user: UserId, dmd: u8) -> Result<()> { - self.ban_with_reason(http, user, dmd, "").await - } - - /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further - /// documentation. - /// - /// # Errors - /// - /// In addition to the reasons [`Self::ban`] may return an error, can also return an error if - /// the reason is too long. - pub async fn ban_with_reason( + pub async fn ban( &self, http: &Http, user: UserId, dmd: u8, - reason: &str, + reason: Option<&str>, ) -> Result<()> { - self.id.ban_with_reason(http, user, dmd, reason).await + self.id.ban(http, user, dmd, reason).await } /// Gets a list of the guild's bans, with additional options and filtering. See @@ -410,8 +404,14 @@ impl PartialGuild { /// [`EditProfile::avatar`]: crate::builder::EditProfile::avatar /// [`utils::read_image`]: crate::utils::read_image /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS - pub async fn create_emoji(&self, http: &Http, name: &str, image: &str) -> Result { - self.id.create_emoji(http, name, image).await + pub async fn create_emoji( + &self, + http: &Http, + name: &str, + image: &str, + reason: Option<&str>, + ) -> Result { + self.id.create_emoji(http, name, image, reason).await } /// Creates an integration for the guild. @@ -428,8 +428,9 @@ impl PartialGuild { http: &Http, integration_id: IntegrationId, kind: &str, + reason: Option<&str>, ) -> Result<()> { - self.id.create_integration(http, integration_id, kind).await + self.id.create_integration(http, integration_id, kind, reason).await } /// Create a guild specific application [`Command`]. @@ -610,8 +611,13 @@ impl PartialGuild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_emoji(&self, http: &Http, emoji_id: EmojiId) -> Result<()> { - self.id.delete_emoji(http, emoji_id).await + pub async fn delete_emoji( + &self, + http: &Http, + emoji_id: EmojiId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_emoji(http, emoji_id, reason).await } /// Deletes an integration by Id from the guild. @@ -628,8 +634,9 @@ impl PartialGuild { &self, http: &Http, integration_id: IntegrationId, + reason: Option<&str>, ) -> Result<()> { - self.id.delete_integration(http, integration_id).await + self.id.delete_integration(http, integration_id, reason).await } /// Deletes a [`Role`] by Id from the guild. @@ -644,8 +651,13 @@ impl PartialGuild { /// does not exist in the Guild. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn delete_role(&self, http: &Http, role_id: RoleId) -> Result<()> { - self.id.delete_role(http, role_id).await + pub async fn delete_role( + &self, + http: &Http, + role_id: RoleId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_role(http, role_id, reason).await } /// Deletes a [`Sticker`] by Id from the guild. @@ -661,8 +673,13 @@ impl PartialGuild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete_sticker(&self, http: &Http, sticker_id: StickerId) -> Result<()> { - self.id.delete_sticker(http, sticker_id).await + pub async fn delete_sticker( + &self, + http: &Http, + sticker_id: StickerId, + reason: Option<&str>, + ) -> Result<()> { + self.id.delete_sticker(http, sticker_id, reason).await } /// Edits the current guild with new data where specified. @@ -706,8 +723,14 @@ impl PartialGuild { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn edit_emoji(&self, http: &Http, emoji_id: EmojiId, name: &str) -> Result { - self.id.edit_emoji(http, emoji_id, name).await + pub async fn edit_emoji( + &self, + http: &Http, + emoji_id: EmojiId, + name: &str, + reason: Option<&str>, + ) -> Result { + self.id.edit_emoji(http, emoji_id, name, reason).await } /// Edits the properties a guild member, such as muting or nicknaming them. Returns the new @@ -759,8 +782,13 @@ impl PartialGuild { /// Returns [`Error::Http`] if the current user lacks permission to change their nickname. /// /// [Change Nickname]: Permissions::CHANGE_NICKNAME - pub async fn edit_nickname(&self, http: &Http, new_nickname: Option<&str>) -> Result<()> { - self.id.edit_nickname(http, new_nickname).await + pub async fn edit_nickname( + &self, + http: &Http, + new_nickname: Option<&str>, + reason: Option<&str>, + ) -> Result<()> { + self.id.edit_nickname(http, new_nickname, reason).await } /// Edits a role, optionally setting its fields. @@ -807,8 +835,9 @@ impl PartialGuild { http: &Http, role_id: RoleId, position: i16, + audit_log_reason: Option<&str>, ) -> Result> { - self.id.edit_role_position(http, role_id, position).await + self.id.edit_role_position(http, role_id, position, audit_log_reason).await } /// Edits a sticker. @@ -994,8 +1023,13 @@ impl PartialGuild { /// [Manage Guild]: Permissions::MANAGE_GUILD /// [`Error::Http`]: crate::error::Error::Http /// [`Error::Json`]: crate::error::Error::Json - pub async fn start_prune(&self, cache_http: impl CacheHttp, days: u8) -> Result { - self.id.start_prune(cache_http.http(), days).await + pub async fn start_prune( + &self, + cache_http: impl CacheHttp, + days: u8, + reason: Option<&str>, + ) -> Result { + self.id.start_prune(cache_http.http(), days, reason).await } /// Kicks a [`Member`] from the guild. @@ -1007,16 +1041,8 @@ impl PartialGuild { /// Returns [`Error::Http`] if the member cannot be kicked by the current user. /// /// [Kick Members]: Permissions::KICK_MEMBERS - pub async fn kick(&self, http: &Http, user_id: UserId) -> Result<()> { - self.id.kick(http, user_id).await - } - - /// # Errors - /// - /// In addition to the reasons [`Self::kick`] may return an error, can also return an error if - /// the reason is too long. - pub async fn kick_with_reason(&self, http: &Http, user_id: UserId, reason: &str) -> Result<()> { - self.id.kick_with_reason(http, user_id, reason).await + pub async fn kick(&self, http: &Http, user_id: UserId, reason: Option<&str>) -> Result<()> { + self.id.kick(http, user_id, reason).await } /// Returns a formatted URL of the guild's icon, if the guild has an icon. @@ -1220,8 +1246,8 @@ impl PartialGuild { /// /// [Ban Members]: Permissions::BAN_MEMBERS /// [`Guild::unban`]: crate::model::guild::Guild::unban - pub async fn unban(&self, http: &Http, user_id: UserId) -> Result<()> { - self.id.unban(http, user_id).await + pub async fn unban(&self, http: &Http, user_id: UserId, reason: Option<&str>) -> Result<()> { + self.id.unban(http, user_id, reason).await } /// Retrieve's the guild's vanity URL. diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs index 5e64b1cb4c1..2397c8e20a7 100644 --- a/src/model/guild/role.rs +++ b/src/model/guild/role.rs @@ -80,8 +80,8 @@ impl Role { /// Returns [`Error::Http`] if the current user lacks permission to delete this role. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn delete(&mut self, http: &Http) -> Result<()> { - http.delete_role(self.guild_id, self.id, None).await + pub async fn delete(&mut self, http: &Http, reason: Option<&str>) -> Result<()> { + self.guild_id.delete_role(http, self.id, reason).await } /// Edits a [`Role`], optionally setting its new fields. diff --git a/src/model/invite.rs b/src/model/invite.rs index 5dc958a8dfb..bbdb2786634 100644 --- a/src/model/invite.rs +++ b/src/model/invite.rs @@ -94,7 +94,7 @@ impl Invite { /// /// [Manage Guild]: Permissions::MANAGE_GUILD /// [permission]: super::permissions - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result { + pub async fn delete(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result { #[cfg(feature = "cache")] { if let (Some(cache), Some(guild)) = (cache_http.cache(), &self.guild) { @@ -107,7 +107,7 @@ impl Invite { } } - cache_http.http().delete_invite(&self.code, None).await + cache_http.http().delete_invite(&self.code, reason).await } /// Gets information about an invite. @@ -288,7 +288,7 @@ impl RichInvite { /// /// [Manage Guild]: Permissions::MANAGE_GUILD /// [permission]: super::permissions - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result { + pub async fn delete(&self, cache_http: impl CacheHttp, reason: Option<&str>) -> Result { #[cfg(feature = "cache")] { if let (Some(cache), Some(guild)) = (cache_http.cache(), &self.guild) { @@ -301,7 +301,7 @@ impl RichInvite { } } - cache_http.http().delete_invite(&self.code, None).await + cache_http.http().delete_invite(&self.code, reason).await } /// Returns a URL to use for the invite. diff --git a/src/model/sticker.rs b/src/model/sticker.rs index 90bb16055f7..5d40e42e3ff 100644 --- a/src/model/sticker.rs +++ b/src/model/sticker.rs @@ -164,9 +164,9 @@ impl Sticker { /// /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS - pub async fn delete(&self, http: &Http) -> Result<()> { + pub async fn delete(&self, http: &Http, reason: Option<&str>) -> Result<()> { if let Some(guild_id) = self.guild_id { - guild_id.delete_sticker(http, self.id).await + guild_id.delete_sticker(http, self.id, reason).await } else { Err(Error::Model(ModelError::DeleteNitroSticker)) } diff --git a/src/model/webhook.rs b/src/model/webhook.rs index 1e8e115df33..515f8c18194 100644 --- a/src/model/webhook.rs +++ b/src/model/webhook.rs @@ -292,12 +292,12 @@ impl Webhook { /// /// Returns [`Error::Http`] if the webhook does not exist, the token is invalid, or if the /// webhook could not otherwise be deleted. - pub async fn delete(&self, http: &Http) -> Result<()> { + pub async fn delete(&self, http: &Http, reason: Option<&str>) -> Result<()> { match &self.token { Some(token) => { - http.delete_webhook_with_token(self.id, token.expose_secret(), None).await + http.delete_webhook_with_token(self.id, token.expose_secret(), reason).await }, - None => http.delete_webhook(self.id, None).await, + None => http.delete_webhook(self.id, reason).await, } }