Skip to content

Commit

Permalink
fix(moderation): only mute on rejoin if previously muted
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 7, 2022
1 parent 7ea6f90 commit 6e9f20d
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/utils/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use mongodb::options::FindOptions;
use poise::serenity_prelude::{ChannelId, Http, User};
use tokio::task::JoinHandle;
use tracing::{debug, error, trace};
use tracing::{debug, error};

use super::bot::get_data_lock;
use super::*;
Expand Down Expand Up @@ -43,23 +43,28 @@ pub async fn mute_on_join(ctx: &serenity::Context, new_member: &mut serenity::Me
)
.await
{
if cursor.advance().await.is_ok() {
trace!("Muted member {} rejoined the server", new_member.user.tag());
if new_member
.add_role(&ctx.http, RoleId(data.configuration.general.mute.role))
.await
.is_ok()
{
debug!(
"Muted member {} was successfully muted",
new_member.user.tag()
);
} else {
error!(
"Failed to mute member {} after rejoining the server",
new_member.user.tag()
);

if let Ok(found) = cursor.advance().await {
if found {
debug!("Muted member {} rejoined the server", new_member.user.tag());
if new_member
.add_role(&ctx.http, RoleId(data.configuration.general.mute.role))
.await
.is_ok()
{
debug!(
"Muted member {} was successfully muted",
new_member.user.tag()
);
} else {
error!(
"Failed to mute member {} after rejoining the server",
new_member.user.tag()
);
}
}
} else {
error!("Failed to advance the cursor");
}
} else {
error!("Failed to query database for muted users");
Expand Down

0 comments on commit 6e9f20d

Please sign in to comment.