Skip to content

Commit

Permalink
fix: check member role for excluded roles
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 7, 2022
1 parent 6e9f20d commit 6279a79
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/utils/autorespond.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use regex::Regex;
use tracing::log::error;

use super::*;
use crate::utils::bot::get_data_lock;
Expand All @@ -15,6 +16,7 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa

let data_lock = get_data_lock(ctx).await;
let responses = &data_lock.read().await.configuration.message_responses;
let message = &new_message.content;

for response in responses {
// check if the message was sent in a channel that is included in the responder
Expand All @@ -27,18 +29,17 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
continue;
}

let excludes = &response.excludes;
// check if the message was sent by a user that is not excluded from the responder
if excludes
.roles
.iter()
.any(|&role_id| role_id == new_message.author.id.0)
{
let excludes = &response.excludes;
let member_roles = &new_message.member.as_ref().unwrap().roles;
if excludes.roles.iter().any(|&role_id| {
member_roles
.iter()
.any(|&member_role| role_id == member_role.0)
}) {
continue;
}

let message = &new_message.content;

// check if the message does not match any of the excludes
if contains_match(&excludes.match_field, message) {
continue;
Expand Down Expand Up @@ -69,7 +70,7 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
return;
}

new_message
if let Err(err) = new_message
.channel_id
.send_message(&ctx.http, |m| {
m.reference_message(new_message);
Expand All @@ -95,7 +96,13 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
}
})
.await
.expect("Could not reply to message author.");
{
error!(
"Failed to reply to the message from {}. Error: {:?}",
new_message.author.tag(),
err
);
}
}
}
}

0 comments on commit 6279a79

Please sign in to comment.