From 6ae1096d7908fe90a95b25c61a7a1a7fd8b25a98 Mon Sep 17 00:00:00 2001 From: jude Date: Wed, 12 Jun 2024 17:44:55 +0100 Subject: [PATCH] Bump ver --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/hooks.rs | 59 ++++++++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 935c8b9..528aa6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2431,7 +2431,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "reminder-rs" -version = "1.7.21" +version = "1.7.22" dependencies = [ "base64 0.22.1", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 28f6af0..404e7f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder-rs" -version = "1.7.21" +version = "1.7.22" authors = ["Jude Southworth "] edition = "2021" license = "AGPL-3.0 only" diff --git a/src/hooks.rs b/src/hooks.rs index dc0546c..1f4c47d 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -58,6 +58,10 @@ async fn macro_check(ctx: Context<'_>) -> bool { async fn check_self_permissions(ctx: Context<'_>) -> bool { let user_id = ctx.serenity_context().cache.current_user().id; + let app_permissions = match ctx { + Context::Application(app_ctx) => app_ctx.interaction.app_permissions, + _ => None, + }; match ctx.guild().map(|g| g.to_owned()) { Some(guild) => { @@ -66,42 +70,37 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool { .await .map_or(false, |m| m.permissions(&ctx).map_or(false, |p| p.manage_webhooks())); - let (view_channel, send_messages, embed_links) = ctx - .channel_id() - .to_channel(&ctx) - .await - .ok() - .and_then(|c| { - if let Channel::Guild(channel) = c { - let perms = channel.permissions_for_user(&ctx, user_id).ok()?; - - Some((perms.view_channel(), perms.send_messages(), perms.embed_links())) - } else { - None - } - }) - .unwrap_or((true, true, true)); - - if manage_webhooks && send_messages && embed_links { - true - } else { - let _ = ctx - .send(CreateReply::default().content(format!( - "Please ensure the bot has the correct permissions: + if let Some(permissions) = app_permissions { + return if permissions.send_messages() + && permissions.embed_links() + && permissions.view_channel() + && manage_webhooks + { + true + } else { + let _ = ctx + .send(CreateReply::default().content(format!( + "The bot appears to be missing some permissions: {} **View Channel** {} **Send Message** {} **Embed Links** -{} **Manage Webhooks**", - if view_channel { "✅" } else { "❌" }, - if send_messages { "✅" } else { "❌" }, - if embed_links { "✅" } else { "❌" }, - if manage_webhooks { "✅" } else { "❌" }, - ))) - .await; +{} **Manage Webhooks** - false +Please check the bot's roles, and any channel overrides. Alternatively, giving the bot +\"Administrator\" will bypass permission checks", + if permissions.view_channel() { "✅" } else { "❌" }, + if permissions.send_messages() { "✅" } else { "❌" }, + if permissions.embed_links() { "✅" } else { "❌" }, + if manage_webhooks { "✅" } else { "❌" }, + ))) + .await; + + false + }; } + + manage_webhooks } None => {