From 4f9eb58c16bd809caf6c94e743dc9c840378e057 Mon Sep 17 00:00:00 2001 From: jellywx Date: Thu, 18 Nov 2021 21:05:49 +0000 Subject: [PATCH] made the missing perms send a message (since the webhook responses bypass perms) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/consts.rs | 2 -- src/hooks.rs | 36 ++++++++++++++++++------------------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fe02d9..ac9fc11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1187,7 +1187,7 @@ dependencies = [ [[package]] name = "reminder_rs" -version = "1.6.0-beta1" +version = "1.6.0-beta2" dependencies = [ "base64", "chrono", diff --git a/Cargo.toml b/Cargo.toml index eaf93ae..16cf289 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder_rs" -version = "1.6.0-beta1" +version = "1.6.0-beta2" authors = ["jellywx "] edition = "2018" diff --git a/src/consts.rs b/src/consts.rs index 8bc6301..cf9aa92 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -23,8 +23,6 @@ lazy_static! { env!("WEBHOOK_AVATAR"), ) .into(); - pub static ref REGEX_CHANNEL: Regex = Regex::new(r#"^\s*<#(\d+)>\s*$"#).unwrap(); - pub static ref REGEX_ROLE: Regex = Regex::new(r#"<@&(\d+)>"#).unwrap(); pub static ref REGEX_CHANNEL_USER: Regex = Regex::new(r#"\s*<(#|@)(?:!)?(\d+)>\s*"#).unwrap(); pub static ref SUBSCRIPTION_ROLES: HashSet = HashSet::from_iter( env::var("SUBSCRIPTION_ROLES") diff --git a/src/hooks.rs b/src/hooks.rs index 212d4e4..fae9bcf 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -1,4 +1,3 @@ -use log::warn; use regex_command_attr::check; use serenity::{client::Context, model::channel::Channel}; @@ -81,7 +80,7 @@ pub async fn check_self_permissions( let manage_webhooks = guild.member_permissions(&ctx, user_id).await.map_or(false, |p| p.manage_webhooks()); - let (send_messages, embed_links) = invoke + let (view_channel, send_messages, embed_links) = invoke .channel_id() .to_channel_cached(&ctx) .map(|c| { @@ -92,29 +91,30 @@ pub async fn check_self_permissions( } }) .flatten() - .map_or((false, false), |p| (p.send_messages(), p.embed_links())); + .map_or((false, false, false), |p| { + (p.read_messages(), p.send_messages(), p.embed_links()) + }); if manage_webhooks && send_messages && embed_links { HookResult::Continue } else { - if send_messages { - let _ = invoke - .respond( - &ctx, - CreateGenericResponse::new().content(format!( - "Please ensure the bot has the correct permissions: + let _ = invoke + .respond( + &ctx, + CreateGenericResponse::new().content(format!( + "Please ensure the bot has the correct permissions: -✅ **Send Message** +{} **View Channel** +{} **Send Message** {} **Embed Links** {} **Manage Webhooks**", - if manage_webhooks { "✅" } else { "❌" }, - if embed_links { "✅" } else { "❌" }, - )), - ) - .await; - } else { - warn!("Missing permissions in guild {}", guild.id); - } + if view_channel { "✅" } else { "❌" }, + if send_messages { "✅" } else { "❌" }, + if manage_webhooks { "✅" } else { "❌" }, + if embed_links { "✅" } else { "❌" }, + )), + ) + .await; HookResult::Halt }