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]]
|
[[package]]
|
||||||
name = "reminder_rs"
|
name = "reminder_rs"
|
||||||
version = "1.6.0-beta1"
|
version = "1.6.0-beta2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "reminder_rs"
|
name = "reminder_rs"
|
||||||
version = "1.6.0-beta1"
|
version = "1.6.0-beta2"
|
||||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ lazy_static! {
|
|||||||
env!("WEBHOOK_AVATAR"),
|
env!("WEBHOOK_AVATAR"),
|
||||||
)
|
)
|
||||||
.into();
|
.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 REGEX_CHANNEL_USER: Regex = Regex::new(r#"\s*<(#|@)(?:!)?(\d+)>\s*"#).unwrap();
|
||||||
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
||||||
env::var("SUBSCRIPTION_ROLES")
|
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 regex_command_attr::check;
|
||||||
use serenity::{client::Context, model::channel::Channel};
|
use serenity::{client::Context, model::channel::Channel};
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ pub async fn check_self_permissions(
|
|||||||
|
|
||||||
let manage_webhooks =
|
let manage_webhooks =
|
||||||
guild.member_permissions(&ctx, user_id).await.map_or(false, |p| p.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()
|
.channel_id()
|
||||||
.to_channel_cached(&ctx)
|
.to_channel_cached(&ctx)
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
@ -92,29 +91,30 @@ pub async fn check_self_permissions(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.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 {
|
if manage_webhooks && send_messages && embed_links {
|
||||||
HookResult::Continue
|
HookResult::Continue
|
||||||
} else {
|
} else {
|
||||||
if send_messages {
|
let _ = invoke
|
||||||
let _ = invoke
|
.respond(
|
||||||
.respond(
|
&ctx,
|
||||||
&ctx,
|
CreateGenericResponse::new().content(format!(
|
||||||
CreateGenericResponse::new().content(format!(
|
"Please ensure the bot has the correct permissions:
|
||||||
"Please ensure the bot has the correct permissions:
|
|
||||||
|
|
||||||
✅ **Send Message**
|
{} **View Channel**
|
||||||
|
{} **Send Message**
|
||||||
{} **Embed Links**
|
{} **Embed Links**
|
||||||
{} **Manage Webhooks**",
|
{} **Manage Webhooks**",
|
||||||
if manage_webhooks { "✅" } else { "❌" },
|
if view_channel { "✅" } else { "❌" },
|
||||||
if embed_links { "✅" } else { "❌" },
|
if send_messages { "✅" } else { "❌" },
|
||||||
)),
|
if manage_webhooks { "✅" } else { "❌" },
|
||||||
)
|
if embed_links { "✅" } else { "❌" },
|
||||||
.await;
|
)),
|
||||||
} else {
|
)
|
||||||
warn!("Missing permissions in guild {}", guild.id);
|
.await;
|
||||||
}
|
|
||||||
|
|
||||||
HookResult::Halt
|
HookResult::Halt
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user