aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar sco1 <[email protected]>2019-01-07 19:15:22 -0500
committerGravatar sco1 <[email protected]>2019-01-07 19:15:22 -0500
commit86a2b550b980361a99314632c3e6e0a112a0d43d (patch)
tree1720de3810b9f56e89c0d2793ba037ec3fcd6277
parentMerge pull request #258 from python-discord/hemlock/Reminder_Deletion_Methods (diff)
Add role hierarchy comparison check method
-rw-r--r--bot/cogs/moderation.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py
index ac08d3dd4..a15a1b71c 100644
--- a/bot/cogs/moderation.py
+++ b/bot/cogs/moderation.py
@@ -1207,6 +1207,19 @@ class Moderation(Scheduler):
if User in error.converters:
await ctx.send(str(error.errors[0]))
+ async def respect_role_hierarchy(self, guild: Guild, actor: Member, target: Member) -> bool:
+ """
+ Check if the highest role of the invoking member is less than or equal to the target member
+
+ Implement as a method rather than a check in order to avoid having to reimplement parameter
+ checks & conversions in a dedicated check decorater
+ """
+
+ # Build role hierarchy
+ role_hierarchy = {role: rank for rank, role in enumerate(reversed(guild.roles))}
+
+ return role_hierarchy[actor.top_role] <= role_hierarchy[target.top_role]
+
def setup(bot):
bot.add_cog(Moderation(bot))