removed all remaining restriction code
This commit is contained in:
96
src/hooks.rs
96
src/hooks.rs
@ -4,7 +4,7 @@ use serenity::{client::Context, model::channel::Channel};
|
||||
|
||||
use crate::{
|
||||
framework::{CommandInvoke, CommandOptions, CreateGenericResponse, HookResult},
|
||||
moderation_cmds, RecordingMacros, SQLPool,
|
||||
moderation_cmds, RecordingMacros,
|
||||
};
|
||||
|
||||
#[check]
|
||||
@ -103,100 +103,6 @@ pub async fn check_self_permissions(
|
||||
}
|
||||
}
|
||||
|
||||
#[check]
|
||||
pub async fn check_managed_permissions(
|
||||
ctx: &Context,
|
||||
invoke: &mut CommandInvoke,
|
||||
args: &CommandOptions,
|
||||
) -> HookResult {
|
||||
if let Some(guild) = invoke.guild(&ctx) {
|
||||
let permissions = guild.member_permissions(&ctx, invoke.author_id()).await.unwrap();
|
||||
|
||||
if permissions.manage_messages() {
|
||||
return HookResult::Continue;
|
||||
}
|
||||
|
||||
let member = invoke.member().unwrap();
|
||||
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
.await
|
||||
.get::<SQLPool>()
|
||||
.cloned()
|
||||
.expect("Could not get SQLPool from data");
|
||||
|
||||
match sqlx::query!(
|
||||
"
|
||||
SELECT
|
||||
role
|
||||
FROM
|
||||
roles
|
||||
INNER JOIN
|
||||
command_restrictions ON roles.id = command_restrictions.role_id
|
||||
WHERE
|
||||
command_restrictions.command = ? AND
|
||||
roles.guild_id = (
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
guilds
|
||||
WHERE
|
||||
guild = ?)
|
||||
",
|
||||
args.command,
|
||||
guild.id.as_u64()
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
{
|
||||
Ok(rows) => {
|
||||
let role_ids = member.roles.iter().map(|r| *r.as_u64()).collect::<Vec<u64>>();
|
||||
|
||||
for row in rows {
|
||||
if role_ids.contains(&row.role) {
|
||||
return HookResult::Continue;
|
||||
}
|
||||
}
|
||||
|
||||
let _ = invoke
|
||||
.respond(
|
||||
&ctx,
|
||||
CreateGenericResponse::new().content(
|
||||
"You must have \"Manage Messages\" or have a role capable of sending reminders to that channel. \
|
||||
Please talk to your server admin, and ask them to use the `/restrict` command to specify allowed roles.",
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
HookResult::Halt
|
||||
}
|
||||
|
||||
Err(sqlx::Error::RowNotFound) => {
|
||||
let _ = invoke
|
||||
.respond(
|
||||
&ctx,
|
||||
CreateGenericResponse::new().content(
|
||||
"You must have \"Manage Messages\" or have a role capable of sending reminders to that channel. \
|
||||
Please talk to your server admin, and ask them to use the `/restrict` command to specify allowed roles.",
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
HookResult::Halt
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
warn!("Unexpected error occurred querying command_restrictions: {:?}", e);
|
||||
|
||||
HookResult::Halt
|
||||
}
|
||||
}
|
||||
} else {
|
||||
HookResult::Continue
|
||||
}
|
||||
}
|
||||
|
||||
#[check]
|
||||
pub async fn check_guild_permissions(
|
||||
ctx: &Context,
|
||||
|
Reference in New Issue
Block a user