diff options
| author | 2019-01-16 20:55:58 -0500 | |
|---|---|---|
| committer | 2019-01-16 20:55:58 -0500 | |
| commit | 6d3fbf07efa0768ad32ef9319dac73a3b1e840cc (patch) | |
| tree | c01e2486cb7111c2a05c61fae64874e202c1c897 | |
| parent | Merge branch 'master' into moderation-hierarchy-check (diff) | |
Simplify role check logic
| -rw-r--r-- | bot/cogs/moderation.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index d9c217b83..64c76ae8a 100644 --- a/bot/cogs/moderation.py +++ b/bot/cogs/moderation.py @@ -1243,7 +1243,7 @@ class Moderation(Scheduler): async def respect_role_hierarchy(self, ctx: Context, target: Member, infraction_type: str) -> bool: """ - Check if the highest role of the invoking member is less than or equal to the target member + Check if the highest role of the invoking member is greater than that of the target member If this check fails, a warning is sent to the invoking ctx @@ -1251,19 +1251,18 @@ class Moderation(Scheduler): checks & conversions in a dedicated check decorater """ - # Build role hierarchy actor = ctx.author - role_hierarchy = {role: rank for rank, role in enumerate(reversed(ctx.guild.roles))} - hierarchy_check = role_hierarchy[actor.top_role] <= role_hierarchy[target.top_role] - - if not hierarchy_check: + target_is_lower = target.top_role < actor.top_role + if not target_is_lower: log.info( f"{actor} ({actor.id}) attempted to {infraction_type} " - f"{target} ({target.id}), who has a higher top role" + f"{target} ({target.id}), who has an equal or higher top role" + ) + await ctx.send( + f":x: {actor.mention}, you may not {infraction_type} someone with an equal or higher top role" ) - await ctx.send(f":x: {actor.mention}, you may not {infraction_type} someone with a higher top role") - return hierarchy_check + return target_is_lower def setup(bot): |