Adjust permission check
Correct response code for oauth redirect
This commit is contained in:
parent
90f05758d0
commit
60b90a61d4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2389,7 +2389,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reminder_web"
|
name = "reminder_web"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
75
src/hooks.rs
75
src/hooks.rs
@ -59,51 +59,54 @@ async fn macro_check(ctx: Context<'_>) -> bool {
|
|||||||
async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
||||||
let user_id = ctx.serenity_context().cache.current_user().id;
|
let user_id = ctx.serenity_context().cache.current_user().id;
|
||||||
|
|
||||||
// DM permissions are always fine
|
match ctx.guild().map(|g| g.to_owned()) {
|
||||||
if ctx.guild_id().is_none() {
|
Some(guild) => {
|
||||||
return true;
|
let manage_webhooks = guild
|
||||||
}
|
.member(&ctx, user_id)
|
||||||
|
.await
|
||||||
|
.map_or(false, |m| m.permissions(&ctx).map_or(false, |p| p.manage_webhooks()));
|
||||||
|
|
||||||
let (view_channel, send_messages, embed_links, manage_webhooks) = ctx
|
let (view_channel, send_messages, embed_links) = ctx
|
||||||
.channel_id()
|
.channel_id()
|
||||||
.to_channel(&ctx)
|
.to_channel(&ctx)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|c| {
|
.and_then(|c| {
|
||||||
if let Channel::Guild(channel) = c {
|
if let Channel::Guild(channel) = c {
|
||||||
let perms = channel.permissions_for_user(&ctx, user_id).ok()?;
|
let perms = channel.permissions_for_user(&ctx, user_id).ok()?;
|
||||||
|
|
||||||
Some((
|
Some((perms.view_channel(), perms.send_messages(), perms.embed_links()))
|
||||||
perms.view_channel(),
|
} else {
|
||||||
perms.send_messages(),
|
None
|
||||||
perms.embed_links(),
|
}
|
||||||
perms.manage_webhooks(),
|
})
|
||||||
))
|
.unwrap_or((false, false, false));
|
||||||
|
|
||||||
|
if manage_webhooks && send_messages && embed_links {
|
||||||
|
true
|
||||||
} else {
|
} else {
|
||||||
None
|
let _ = ctx
|
||||||
}
|
.send(CreateReply::default().content(format!(
|
||||||
})
|
"Please ensure the bot has the correct permissions:
|
||||||
.unwrap_or((false, false, false, false));
|
|
||||||
|
|
||||||
if view_channel && manage_webhooks && send_messages && embed_links {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
let _ = ctx
|
|
||||||
.send(CreateReply::default().content(format!(
|
|
||||||
"Please ensure the bot has the correct permissions:
|
|
||||||
|
|
||||||
{} **View Channel**
|
{} **View Channel**
|
||||||
{} **Send Message**
|
{} **Send Message**
|
||||||
{} **Embed Links**
|
{} **Embed Links**
|
||||||
{} **Manage Webhooks**",
|
{} **Manage Webhooks**",
|
||||||
if view_channel { "✅" } else { "❌" },
|
if view_channel { "✅" } else { "❌" },
|
||||||
if send_messages { "✅" } else { "❌" },
|
if send_messages { "✅" } else { "❌" },
|
||||||
if embed_links { "✅" } else { "❌" },
|
if embed_links { "✅" } else { "❌" },
|
||||||
if manage_webhooks { "✅" } else { "❌" },
|
if manage_webhooks { "✅" } else { "❌" },
|
||||||
)))
|
)))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
false
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None => {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "reminder_web"
|
name = "reminder_web"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ async fn create_database_channel(
|
|||||||
pub enum DashboardPage {
|
pub enum DashboardPage {
|
||||||
#[response(status = 200)]
|
#[response(status = 200)]
|
||||||
Ok(NamedFile),
|
Ok(NamedFile),
|
||||||
#[response(status = 200)]
|
#[response(status = 302)]
|
||||||
Unauthorised(Redirect),
|
Unauthorised(Redirect),
|
||||||
#[response(status = 500)]
|
#[response(status = 500)]
|
||||||
NotConfigured(Template),
|
NotConfigured(Template),
|
||||||
|
Loading…
Reference in New Issue
Block a user