aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Izan <[email protected]>2021-09-01 11:50:36 +0100
committerGravatar Izan <[email protected]>2021-09-01 12:02:35 +0100
commit8e25ed16caf0a510b386d371800b6f93e8855684 (patch)
tree3e553339b8d357ea02069c08c22c3d68029629b2
parentAdd support for searching infractions by infraction id (#1787) (diff)
Prevent infractions raising error due to role hierarchy
Now explicitly states that the bot is unable to starify/kick/ban someone who's higher in the role hierarchy
-rw-r--r--bot/exts/moderation/infraction/infractions.py8
-rw-r--r--bot/exts/moderation/infraction/superstarify.py4
2 files changed, 12 insertions, 0 deletions
diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py
index eaba97703..4afa66460 100644
--- a/bot/exts/moderation/infraction/infractions.py
+++ b/bot/exts/moderation/infraction/infractions.py
@@ -314,6 +314,10 @@ class Infractions(InfractionScheduler, commands.Cog):
@respect_role_hierarchy(member_arg=2)
async def apply_kick(self, ctx: Context, user: Member, reason: t.Optional[str], **kwargs) -> None:
"""Apply a kick infraction with kwargs passed to `post_infraction`."""
+ if user.top_role > ctx.me.top_role:
+ await ctx.send(":x: I can't kick users above me in the role hierarchy.")
+ return
+
infraction = await _utils.post_infraction(ctx, user, "kick", reason, active=False, **kwargs)
if infraction is None:
return
@@ -340,6 +344,10 @@ class Infractions(InfractionScheduler, commands.Cog):
Will also remove the banned user from the Big Brother watch list if applicable.
"""
+ if hasattr(user, 'top_role') and user.top_role > ctx.me.top_role:
+ await ctx.send(":x: I can't ban users above me in the role hierarchy.")
+ return
+
# In the case of a permanent ban, we don't need get_active_infractions to tell us if one is active
is_temporary = kwargs.get("expires_at") is not None
active_infraction = await _utils.get_active_infraction(ctx, user, "ban", is_temporary)
diff --git a/bot/exts/moderation/infraction/superstarify.py b/bot/exts/moderation/infraction/superstarify.py
index 05a2bbe10..2b111fed7 100644
--- a/bot/exts/moderation/infraction/superstarify.py
+++ b/bot/exts/moderation/infraction/superstarify.py
@@ -132,6 +132,10 @@ class Superstarify(InfractionScheduler, Cog):
An optional reason can be provided, which would be added to a message stating their old nickname
and linking to the nickname policy.
"""
+ if member.top_role > ctx.me.top_role:
+ await ctx.send(":x: I can't starify users above me in the role hierarchy.")
+ return
+
if await _utils.get_active_infraction(ctx, member, "superstar"):
return