aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Amrou Bellalouna <[email protected]>2023-03-12 09:51:03 +0100
committerGravatar GitHub <[email protected]>2023-03-12 09:51:03 +0100
commitb9f08cf8e4d11e4998024dd5cba49fedb8ea3f10 (patch)
treea88285c35b72b103524bb2742788f50bf9870378
parentMerge pull request #2326 from python-discord/snekbox-files (diff)
parentUpdate appeals2 to appeals_2 to reflect config change (diff)
Merge pull request #2372 from python-discord/vivek/jump-url-infr-log
Display jump url to message invoking an infraction in infraction log
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py8
-rw-r--r--bot/exts/moderation/infraction/_utils.py28
-rw-r--r--bot/exts/moderation/infraction/management.py9
3 files changed, 36 insertions, 9 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 9b8e67ec5..63aac6340 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -147,6 +147,7 @@ class InfractionScheduler:
icon = _utils.INFRACTION_ICONS[infr_type][0]
reason = infraction["reason"]
id_ = infraction['id']
+ jump_url = infraction['jump_url']
expiry = time.format_with_duration(
infraction["expires_at"],
infraction["last_applied"]
@@ -261,6 +262,12 @@ class InfractionScheduler:
mentions = discord.AllowedMentions(users=[user], roles=False)
await ctx.send(f"{dm_result}{confirm_msg}{infr_message}.", allowed_mentions=mentions)
+ if jump_url is None:
+ # Infraction issued in ModMail category.
+ jump_url = "N/A"
+ else:
+ jump_url = f"[Click here.]({jump_url})"
+
# Send a log message to the mod log.
# Don't use ctx.message.author for the actor; antispam only patches ctx.author.
log.trace(f"Sending apply mod log for infraction #{id_}.")
@@ -273,6 +280,7 @@ class InfractionScheduler:
Member: {messages.format_user(user)}
Actor: {ctx.author.mention}{dm_log_text}{expiry_log_text}
Reason: {reason}
+ Jump URL: {jump_url}
{additional_info}
"""),
content=log_content,
diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py
index c2ef80461..5e9fa75cc 100644
--- a/bot/exts/moderation/infraction/_utils.py
+++ b/bot/exts/moderation/infraction/_utils.py
@@ -6,11 +6,12 @@ from discord.ext.commands import Context
from pydis_core.site_api import ResponseCodeError
import bot
-from bot.constants import Colours, Icons
+from bot.constants import Categories, Colours, Icons
from bot.converters import DurationOrExpiry, MemberOrUser
from bot.errors import InvalidInfractedUserError
from bot.log import get_logger
from bot.utils import time
+from bot.utils.channel import is_in_category
from bot.utils.time import unpack_duration
log = get_logger(__name__)
@@ -77,14 +78,14 @@ async def post_user(ctx: Context, user: MemberOrUser) -> t.Optional[dict]:
async def post_infraction(
- ctx: Context,
- user: MemberOrUser,
- infr_type: str,
- reason: str,
- duration_or_expiry: t.Optional[DurationOrExpiry] = None,
- hidden: bool = False,
- active: bool = True,
- dm_sent: bool = False,
+ ctx: Context,
+ user: MemberOrUser,
+ infr_type: str,
+ reason: str,
+ duration_or_expiry: t.Optional[DurationOrExpiry] = None,
+ hidden: bool = False,
+ active: bool = True,
+ dm_sent: bool = False,
) -> t.Optional[dict]:
"""Posts an infraction to the API."""
if isinstance(user, (discord.Member, discord.User)) and user.bot:
@@ -95,6 +96,14 @@ async def post_infraction(
current_time = arrow.utcnow()
+ if any(
+ is_in_category(ctx.channel, category)
+ for category in (Categories.modmail, Categories.appeals, Categories.appeals_2)
+ ):
+ jump_url = None
+ else:
+ jump_url = ctx.message.jump_url
+
payload = {
"actor": ctx.author.id, # Don't use ctx.message.author; antispam only patches ctx.author.
"hidden": hidden,
@@ -103,6 +112,7 @@ async def post_infraction(
"user": user.id,
"active": active,
"dm_sent": dm_sent,
+ "jump_url": jump_url,
"inserted_at": current_time.isoformat(),
"last_applied": current_time.isoformat(),
}
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index 6ef382119..aafa6d9b0 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -390,6 +390,7 @@ class ModManagement(commands.Cog):
applied = time.discord_timestamp(last_applied)
duration_edited = arrow.get(last_applied) > arrow.get(inserted_at)
dm_sent = infraction["dm_sent"]
+ jump_url = infraction["jump_url"]
# Format the user string.
if user_obj := self.bot.get_user(user["id"]):
@@ -420,6 +421,13 @@ class ModManagement(commands.Cog):
else:
dm_sent_text = "Yes" if dm_sent else "No"
+ if jump_url is None:
+ # Infraction was issued prior to jump urls being stored in the database
+ # or infraction was issued in ModMail category.
+ jump_url = "N/A"
+ else:
+ jump_url = f"[Click here.]({jump_url})"
+
lines = textwrap.dedent(f"""
{"**===============**" if active else "==============="}
Status: {"__**Active**__" if active else "Inactive"}
@@ -432,6 +440,7 @@ class ModManagement(commands.Cog):
Duration: {duration}
Actor: <@{infraction["actor"]["id"]}>
ID: `{infraction["id"]}`
+ Jump URL: {jump_url}
Reason: {infraction["reason"] or "*None*"}
{"**===============**" if active else "==============="}
""")