From 2fb12e2b3782fff211a41cb27cd316afc4320a7b Mon Sep 17 00:00:00 2001 From: Lakelezz <12222135+Lakelezz@users.noreply.github.com> Date: Sun, 10 Sep 2017 05:19:05 +0200 Subject: [PATCH] Fixed admin bypass perm to framework allowed_roles This makes those with the "Administrator" permission able to bypass the `allowed_roles` check. Additionally change a usage of `len() > 0` to `is_empty()`. --- src/framework/standard/help_commands.rs | 2 +- src/framework/standard/mod.rs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs index c7004d58273..72e0468151b 100644 --- a/src/framework/standard/help_commands.rs +++ b/src/framework/standard/help_commands.rs @@ -51,7 +51,7 @@ fn remove_aliases(cmds: &HashMap) -> HashMap<&String, &I } fn right_roles(cmd: &Command, guild: &Guild, member: &Member) -> bool { - if cmd.allowed_roles.len() > 0 { + if !cmd.allowed_roles.is_empty() { cmd.allowed_roles .iter() .flat_map(|r| guild.role_by_name(&r)) diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index 4fc728db7a6..bd1300da74a 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -523,17 +523,21 @@ impl StandardFramework { } else if self.configuration.disabled_commands.contains(built) { Some(DispatchError::CommandDisabled(built.to_owned())) } else { - if command.allowed_roles.len() > 0 { + if !command.allowed_roles.is_empty() { if let Some(guild) = message.guild() { let guild = guild.read().unwrap(); if let Some(member) = guild.members.get(&message.author.id) { - let right_role = command - .allowed_roles - .iter() - .flat_map(|r| guild.role_by_name(&r)) - .any(|g| member.roles.contains(&g.id)); - if !right_role { - return Some(DispatchError::LackingRole); + if let Ok(permissions) = member.permissions() { + if !permissions.administrator() { + let right_role = command + .allowed_roles + .iter() + .flat_map(|r| guild.role_by_name(&r)) + .any(|g| member.roles.contains(&g.id)); + if !right_role { + return Some(DispatchError::LackingRole); + } + } } } }