fix(moderation): use correct mute duration (#46)

sorry
This commit is contained in:
Ax333l 2022-12-20 11:38:11 +01:00 committed by GitHub
parent 5b5db3bc7e
commit a8cedfc1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);