aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Luna Ilune Makyus <[email protected]>2022-08-17 17:14:04 -0400
committerGravatar GitHub <[email protected]>2022-08-17 17:14:04 -0400
commit2e01be758e64f6e4cf4110f735966bca6d0b408d (patch)
tree62c45be999ea624ff51f9724f44dea097a3da733
parentMerge pull request #2252 from python-discord/Resolve-silence-test-failures (diff)
parentfix: lint (diff)
Merge pull request #1 from VirdanTheBurden/feat-add-reason-argument-to-pardons
feat: add reason argument to pardon commands
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py18
-rw-r--r--bot/exts/moderation/infraction/infractions.py30
2 files changed, 40 insertions, 8 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index c7f03b2e9..a6846e239 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.
@@ -434,9 +442,15 @@ class InfractionScheduler:
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..8e5ee8200 100644
--- a/bot/exts/moderation/infraction/infractions.py
+++ b/bot/exts/moderation/infraction/infractions.py
@@ -330,14 +330,26 @@ 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 +361,15 @@ 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