diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/moderation/infraction/_scheduler.py | 22 | ||||
| -rw-r--r-- | bot/exts/moderation/infraction/infractions.py | 12 | 
2 files changed, 24 insertions, 10 deletions
| diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index c7f03b2e9..d733c3936 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -271,6 +271,7 @@ class InfractionScheduler:              ctx: Context,              infr_type: str,              user: MemberOrUser, +            pardon_reason: t.Optional[str] = None,              *,              send_msg: bool = True,              notify: bool = True @@ -278,6 +279,9 @@ class InfractionScheduler:          """          Prematurely end an infraction for a user and log the action in the mod log. +        If `pardon_reason` is None, then the infraction object will not receive +        appended text explaining why the infraction was pardoned. +          If `send_msg` is True, then a pardoning confirmation message will be sent to          the context channel. Otherwise, no such message will be sent. @@ -302,7 +306,7 @@ class InfractionScheduler:              return          # Deactivate the infraction and cancel its scheduled expiration task. -        log_text = await self.deactivate_infraction(response[0], send_log=False, notify=notify) +        log_text = await self.deactivate_infraction(response[0], pardon_reason, send_log=False, notify=notify)          log_text["Member"] = messages.format_user(user)          log_text["Actor"] = ctx.author.mention @@ -355,6 +359,7 @@ class InfractionScheduler:      async def deactivate_infraction(          self,          infraction: _utils.Infraction, +        pardon_reason: t.Optional[str] = None,          *,          send_log: bool = True,          notify: bool = True @@ -362,6 +367,9 @@ class InfractionScheduler:          """          Deactivate an active infraction and return a dictionary of lines to send in a mod log. +        If `pardon_reason` is None, then the infraction object will not receive +        appended text explaining why the infraction was pardoned. +          The infraction is removed from Discord, marked as inactive in the database, and has its          expiration task cancelled. If `send_log` is True, a mod log is sent for the          deactivation of the infraction. @@ -386,7 +394,7 @@ class InfractionScheduler:              "Reason": infraction["reason"],              "Created": time.format_with_duration(infraction["inserted_at"], infraction["expires_at"]),          } - +                  try:              log.trace("Awaiting the pardon action coroutine.")              returned_log = await self._pardon_action(infraction, notify) @@ -430,13 +438,19 @@ class InfractionScheduler:          except ResponseCodeError:              log.exception(f"Failed to fetch watch status for user {user_id}")              log_text["Watching"] = "Unknown - failed to fetch watch status." - +                  try:              # Mark infraction as inactive in the database.              log.trace(f"Marking infraction #{id_} as inactive in the database.") + +            data = {"active": False} + +            if pardon_reason is not None: +                data["reason"] = infraction["reason"] + f" | Pardoned: {pardon_reason}" +              await self.bot.api_client.patch(                  f"bot/infractions/{id_}", -                json={"active": False} +                json=data              )          except ResponseCodeError as e:              log.exception(f"Failed to deactivate infraction #{id_} ({type_})") diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py index 46fd3381c..a94da0d7c 100644 --- a/bot/exts/moderation/infraction/infractions.py +++ b/bot/exts/moderation/infraction/infractions.py @@ -330,14 +330,14 @@ class Infractions(InfractionScheduler, commands.Cog):      # region: Remove infractions (un- commands)      @command() -    async def unmute(self, ctx: Context, user: UnambiguousMemberOrUser) -> None: +    async def unmute(self, ctx: Context, user: UnambiguousMemberOrUser, *, pardon_reason: t.Optional[str] = None) -> None:          """Prematurely end the active mute infraction for the user.""" -        await self.pardon_infraction(ctx, "mute", user) +        await self.pardon_infraction(ctx, "mute", user, pardon_reason)      @command() -    async def unban(self, ctx: Context, user: UnambiguousMemberOrUser) -> None: +    async def unban(self, ctx: Context, user: UnambiguousMemberOrUser, *, pardon_reason: t.Optional[str] = None) -> None:          """Prematurely end the active ban infraction for the user.""" -        await self.pardon_infraction(ctx, "ban", user) +        await self.pardon_infraction(ctx, "ban", user, pardon_reason)      @command(aliases=("uvban",))      async def unvoiceban(self, ctx: Context) -> None: @@ -349,9 +349,9 @@ class Infractions(InfractionScheduler, commands.Cog):          await ctx.send(":x: This command is not yet implemented. Maybe you meant to use `unvoicemute`?")      @command(aliases=("uvmute",)) -    async def unvoicemute(self, ctx: Context, user: UnambiguousMemberOrUser) -> None: +    async def unvoicemute(self, ctx: Context, user: UnambiguousMemberOrUser, *, pardon_reason: t.Optional[str] = None) -> None:          """Prematurely end the active voice mute infraction for the user.""" -        await self.pardon_infraction(ctx, "voice_mute", user) +        await self.pardon_infraction(ctx, "voice_mute", user, pardon_reason)      # endregion      # region: Base apply functions | 
