Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bot/exts/moderation/infraction/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from bot.constants import Categories, Channels, Colours, Icons, MODERATION_ROLES, STAFF_AND_COMMUNITY_ROLES
from bot.converters import DurationOrExpiry, MemberOrUser
from bot.errors import InvalidInfractedUserError
from bot.exts.moderation.infraction._views import BanConfirmationView
from bot.exts.moderation.infraction._views import InfractionConfirmationView
from bot.log import get_logger
from bot.utils import time
from bot.utils.channel import is_in_category, is_mod_channel
Expand Down Expand Up @@ -328,9 +328,9 @@ def cap_timeout_duration(duration: datetime.datetime | relativedelta) -> tuple[b
return capped, duration


async def confirm_elevated_user_ban(ctx: Context, user: MemberOrUser) -> bool:
async def confirm_elevated_user_infraction(ctx: Context, user: MemberOrUser) -> bool:
"""
If user has an elevated role, require confirmation before banning.
If user has an elevated role, require confirmation before issuing infraction.

A member with the staff or community roles are considered elevated.

Expand All @@ -339,24 +339,24 @@ async def confirm_elevated_user_ban(ctx: Context, user: MemberOrUser) -> bool:
if not isinstance(user, Member) or not any(role.id in STAFF_AND_COMMUNITY_ROLES for role in user.roles):
return True

confirmation_view = BanConfirmationView(
confirmation_view = InfractionConfirmationView(
allowed_users=(ctx.author.id,),
allowed_roles=MODERATION_ROLES,
timeout=10,
)
confirmation_view.message = await ctx.send(
f"{user.mention} has an elevated role. Are you sure you want to ban them?",
f"{user.mention} has an elevated role. Are you sure you want to infract them?",
view=confirmation_view,
allowed_mentions=discord.AllowedMentions.none(),
)

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

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

return True
Expand Down
6 changes: 3 additions & 3 deletions bot/exts/moderation/infraction/_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from pydis_core.utils import interactions


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

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

@discord.ui.button(label="Ban", style=ButtonStyle.red)
@discord.ui.button(label="Infract", style=ButtonStyle.red)
async def confirm(self, interaction: Interaction, button: Button) -> None:
"""Callback coroutine that is called when the "Ban" button is pressed."""
"""Callback coroutine that is called when the "Infract" button is pressed."""
self.confirmed = True
await interaction.response.defer()
self.stop()
Expand Down
5 changes: 4 additions & 1 deletion bot/exts/moderation/infraction/infractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ async def apply_kick(self, ctx: Context, user: Member, reason: str | None, **kwa
await ctx.send(":x: I can't kick users above or equal to me in the role hierarchy.")
return

if not await _utils.confirm_elevated_user_infraction(ctx, user):
return

infraction = await _utils.post_infraction(ctx, user, "kick", reason, active=False, **kwargs)
if infraction is None:
return
Expand Down Expand Up @@ -459,7 +462,7 @@ async def apply_ban(
await ctx.send(":x: I can't ban users above or equal to me in the role hierarchy.")
return None

if not await _utils.confirm_elevated_user_ban(ctx, user):
if not await _utils.confirm_elevated_user_infraction(ctx, user):
return None

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