diff options
-rw-r--r-- | bot/exts/moderation/infraction/_utils.py | 23 | ||||
-rw-r--r-- | bot/exts/moderation/infraction/infractions.py | 18 | ||||
-rw-r--r-- | bot/exts/moderation/infraction/management.py | 4 |
3 files changed, 24 insertions, 21 deletions
diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py index d616e4009..f306ede02 100644 --- a/bot/exts/moderation/infraction/_utils.py +++ b/bot/exts/moderation/infraction/_utils.py @@ -5,17 +5,17 @@ import arrow import discord from dateutil.relativedelta import relativedelta from discord import Member -from discord.ext.commands import Context +from discord.ext.commands import Bot, Context from pydis_core.site_api import ResponseCodeError import bot -from bot.constants import Categories, Colours, Icons, MODERATION_ROLES, STAFF_PARTNERS_COMMUNITY_ROLES +from bot.constants import Categories, Channels, Colours, Icons, MODERATION_ROLES, STAFF_PARTNERS_COMMUNITY_ROLES from bot.converters import DurationOrExpiry, MemberOrUser from bot.errors import InvalidInfractedUserError 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 +from bot.utils.channel import is_in_category, is_mod_channel from bot.utils.time import unpack_duration log = get_logger(__name__) @@ -66,6 +66,11 @@ INFRACTION_DESCRIPTION_WARNING_TEMPLATE = ( MAXIMUM_TIMEOUT_DAYS = datetime.timedelta(days=28) +TIMEOUT_CAP_MESSAGE = ( + f"The timeout for {{0}} can't be longer than {MAXIMUM_TIMEOUT_DAYS.days} days." + " I'll pretend that's what you meant." +) + async def post_user(ctx: Context, user: MemberOrUser) -> dict | None: """ @@ -308,7 +313,7 @@ async def send_private_embed(user: MemberOrUser, embed: discord.Embed) -> bool: def cap_timeout_duration(duration: datetime.datetime | relativedelta) -> tuple[bool, datetime.datetime]: - """Caps the duration of a duration to Discord's limit.""" + """Cap the duration of a duration to Discord's limit.""" now = arrow.utcnow() capped = False if isinstance(duration, relativedelta): @@ -355,3 +360,13 @@ async def confirm_elevated_user_ban(ctx: Context, user: MemberOrUser) -> bool: return False return True + + +async def notify_timeout_cap(bot: Bot, ctx: Context, user: discord.Member) -> None: + """Notify moderators about a timeout duration being capped.""" + cap_message_for_user = TIMEOUT_CAP_MESSAGE.format(user.mention) + if is_mod_channel(ctx.channel): + await ctx.reply(f":warning: {cap_message_for_user}") + else: + await bot.get_channel(Channels.mods).send( + f":warning: {ctx.author.mention} {cap_message_for_user}") diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py index f2dbd858d..e435035f2 100644 --- a/bot/exts/moderation/infraction/infractions.py +++ b/bot/exts/moderation/infraction/infractions.py @@ -12,13 +12,12 @@ from pydis_core.utils.members import get_or_fetch_member from bot import constants from bot.bot import Bot -from bot.constants import Channels, Event +from bot.constants import Event from bot.converters import Age, Duration, DurationOrExpiry, MemberOrUser, UnambiguousMemberOrUser from bot.decorators import ensure_future_timestamp, respect_role_hierarchy from bot.exts.moderation.infraction import _utils from bot.exts.moderation.infraction._scheduler import InfractionScheduler from bot.log import get_logger -from bot.utils.channel import is_mod_channel from bot.utils.messages import format_user log = get_logger(__name__) @@ -46,12 +45,6 @@ COMP_BAN_REASON = ( "this message to appeal your ban." ) COMP_BAN_DURATION = timedelta(days=4) -# Timeout -MAXIMUM_TIMEOUT_DAYS = timedelta(days=28) -TIMEOUT_CAP_MESSAGE = ( - f"The timeout for {{0}} can't be longer than {MAXIMUM_TIMEOUT_DAYS.days} days." - " I'll pretend that's what you meant." -) class Infractions(InfractionScheduler, commands.Cog): @@ -232,13 +225,7 @@ class Infractions(InfractionScheduler, commands.Cog): else: capped, duration = _utils.cap_timeout_duration(duration) if capped: - cap_message_for_user = TIMEOUT_CAP_MESSAGE.format(user.mention) - if is_mod_channel(ctx.channel): - await ctx.reply(f":warning: {cap_message_for_user}") - else: - await self.bot.get_channel(Channels.mods).send( - f":warning: {ctx.author.mention} {cap_message_for_user}" - ) + await _utils.notify_timeout_cap(self.bot, ctx, user) await self.apply_timeout(ctx, user, reason, duration_or_expiry=duration) @@ -662,7 +649,6 @@ class Infractions(InfractionScheduler, commands.Cog): @commands.Cog.listener() async def on_member_join(self, member: Member) -> None: """ - Apply active timeout infractions for returning members. This is needed for users who might have had their infraction edited in our database but not in Discord itself. diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index e5216cac9..ac228d8a2 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -233,7 +233,9 @@ class ModManagement(commands.Cog): self.infractions_cog.schedule_expiration(new_infraction) # Timeouts are handled by Discord itself, so we need to edit the expiry in Discord as well if user and infraction["type"] == "timeout": - _, duration = _utils.cap_timeout_duration(expiry) + capped, duration = _utils.cap_timeout_duration(expiry) + if capped: + await _utils.notify_timeout_cap(self.bot, ctx, user) await user.edit(reason=reason, timed_out_until=expiry) log_text += f""" |