made the missing perms send a message (since the webhook responses bypass perms)
This commit is contained in:
parent
c953bc0cd3
commit
4f9eb58c16
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1187,7 +1187,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reminder_rs"
|
||||
version = "1.6.0-beta1"
|
||||
version = "1.6.0-beta2"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reminder_rs"
|
||||
version = "1.6.0-beta1"
|
||||
version = "1.6.0-beta2"
|
||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
|
@ -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<u64> = HashSet::from_iter(
|
||||
env::var("SUBSCRIPTION_ROLES")
|
||||
|
36
src/hooks.rs
36
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user