Skip to content

Commit

Permalink
fix(moderation): use correct mute duration (ReVanced#46)
Browse files Browse the repository at this point in the history
sorry
  • Loading branch information
Axelen123 authored Dec 20, 2022
1 parent 5b5db3b commit a8cedfc
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/commands/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a8cedfc

Please sign in to comment.