From a8cedfc1c04c458c4eb8626c9476041c85688c7c Mon Sep 17 00:00:00 2001 From: Ax333l Date: Tue, 20 Dec 2022 11:38:11 +0100 Subject: [PATCH] fix(moderation): use correct mute duration (#46) sorry --- src/commands/moderation.rs | 45 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/commands/moderation.rs b/src/commands/moderation.rs index 771308e..098e808 100644 --- a/src/commands/moderation.rs +++ b/src/commands/moderation.rs @@ -230,12 +230,6 @@ pub async fn mute( .unwrap(); } - let unmute_time = if !mute_duration.is_zero() { - Some((now + mute_duration).timestamp() as u64) - } else { - None - }; - let data = &mut *ctx.data().write().await; let configuration = &data.configuration; let mute = &configuration.general.mute; @@ -245,6 +239,27 @@ pub async fn mute( let author = ctx.author(); + if let Some(pending_unmute) = data.pending_unmutes.get(&member.user.id.0) { + trace!("Cancelling pending unmute for {}", member.user.id.0); + pending_unmute.abort(); + } + + let unmute_time = if !mute_duration.is_zero() { + data.pending_unmutes.insert( + member.user.id.0, + queue_unmute_member( + &ctx.discord().http, + &data.database, + &member, + mute_role_id, + mute_duration.num_seconds() as u64, + ), + ); + Some((now + mute_duration).timestamp() as u64) + } else { + None + }; + let result = if let Err(add_role_result) = member.add_role(&ctx.discord().http, mute_role_id).await { Some(Error::from(add_role_result)) @@ -319,24 +334,6 @@ pub async fn mute( } }; - if let Some(pending_unmute) = data.pending_unmutes.get(&member.user.id.0) { - trace!("Cancelling pending unmute for {}", member.user.id.0); - pending_unmute.abort(); - } - - if let Some(mute_duration) = unmute_time { - data.pending_unmutes.insert( - member.user.id.0, - queue_unmute_member( - &ctx.discord().http, - &data.database, - &member, - mute_role_id, - mute_duration, - ), - ); - } - if result.is_none() { if let Err(e) = member.disconnect_from_voice(&ctx.discord().http).await { warn!("Could not disconnect member from voice channel: {}", e);