Skip to content

Commit e6db94c

Browse files
committed
Require confirmation before kicking elevated user
This was already the case when attempting to ban an elevated user, but kicks have almost the same consequences (e.g. loss of roles), so we should prevent it in that case, too.
1 parent f5fb111 commit e6db94c

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

bot/exts/moderation/infraction/_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from bot.constants import Categories, Channels, Colours, Icons, MODERATION_ROLES, STAFF_AND_COMMUNITY_ROLES
1313
from bot.converters import DurationOrExpiry, MemberOrUser
1414
from bot.errors import InvalidInfractedUserError
15-
from bot.exts.moderation.infraction._views import BanConfirmationView
15+
from bot.exts.moderation.infraction._views import InfractionConfirmationView
1616
from bot.log import get_logger
1717
from bot.utils import time
1818
from bot.utils.channel import is_in_category, is_mod_channel
@@ -328,9 +328,9 @@ def cap_timeout_duration(duration: datetime.datetime | relativedelta) -> tuple[b
328328
return capped, duration
329329

330330

331-
async def confirm_elevated_user_ban(ctx: Context, user: MemberOrUser) -> bool:
331+
async def confirm_elevated_user_infraction(ctx: Context, user: MemberOrUser) -> bool:
332332
"""
333-
If user has an elevated role, require confirmation before banning.
333+
If user has an elevated role, require confirmation before issuing infraction.
334334
335335
A member with the staff or community roles are considered elevated.
336336
@@ -339,24 +339,24 @@ async def confirm_elevated_user_ban(ctx: Context, user: MemberOrUser) -> bool:
339339
if not isinstance(user, Member) or not any(role.id in STAFF_AND_COMMUNITY_ROLES for role in user.roles):
340340
return True
341341

342-
confirmation_view = BanConfirmationView(
342+
confirmation_view = InfractionConfirmationView(
343343
allowed_users=(ctx.author.id,),
344344
allowed_roles=MODERATION_ROLES,
345345
timeout=10,
346346
)
347347
confirmation_view.message = await ctx.send(
348-
f"{user.mention} has an elevated role. Are you sure you want to ban them?",
348+
f"{user.mention} has an elevated role. Are you sure you want to infract them?",
349349
view=confirmation_view,
350350
allowed_mentions=discord.AllowedMentions.none(),
351351
)
352352

353353
timed_out = await confirmation_view.wait()
354354
if timed_out:
355-
log.trace(f"Attempted ban of user {user} by moderator {ctx.author} cancelled due to timeout.")
355+
log.trace(f"Attempted infraction of user {user} by moderator {ctx.author} cancelled due to timeout.")
356356
return False
357357

358358
if confirmation_view.confirmed is False:
359-
log.trace(f"Attempted ban of user {user} by moderator {ctx.author} cancelled due to manual cancel.")
359+
log.trace(f"Attempted infraction of user {user} by moderator {ctx.author} cancelled due to manual cancel.")
360360
return False
361361

362362
return True

bot/exts/moderation/infraction/_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
from pydis_core.utils import interactions
77

88

9-
class BanConfirmationView(interactions.ViewWithUserAndRoleCheck):
9+
class InfractionConfirmationView(interactions.ViewWithUserAndRoleCheck):
1010
"""A confirmation view to be sent before issuing potentially suspect infractions."""
1111

1212
def __init__(self, *args: Any, **kwargs: Any) -> None:
1313
super().__init__(*args, **kwargs)
1414
self.confirmed = False
1515

16-
@discord.ui.button(label="Ban", style=ButtonStyle.red)
16+
@discord.ui.button(label="Infract", style=ButtonStyle.red)
1717
async def confirm(self, interaction: Interaction, button: Button) -> None:
18-
"""Callback coroutine that is called when the "Ban" button is pressed."""
18+
"""Callback coroutine that is called when the "Infract" button is pressed."""
1919
self.confirmed = True
2020
await interaction.response.defer()
2121
self.stop()

bot/exts/moderation/infraction/infractions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ async def apply_kick(self, ctx: Context, user: Member, reason: str | None, **kwa
427427
await ctx.send(":x: I can't kick users above or equal to me in the role hierarchy.")
428428
return
429429

430+
if not await _utils.confirm_elevated_user_infraction(ctx, user):
431+
return
432+
430433
infraction = await _utils.post_infraction(ctx, user, "kick", reason, active=False, **kwargs)
431434
if infraction is None:
432435
return
@@ -459,7 +462,7 @@ async def apply_ban(
459462
await ctx.send(":x: I can't ban users above or equal to me in the role hierarchy.")
460463
return None
461464

462-
if not await _utils.confirm_elevated_user_ban(ctx, user):
465+
if not await _utils.confirm_elevated_user_infraction(ctx, user):
463466
return None
464467

465468
# In the case of a permanent ban, we don't need get_active_infractions to tell us if one is active

0 commit comments

Comments
 (0)