aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar vivekashok1221 <[email protected]>2023-02-17 11:35:00 +0530
committerGravatar vivekashok1221 <[email protected]>2023-02-17 11:35:00 +0530
commited59a9fd38f8bcfcb81efaf66f86e7ebc6661665 (patch)
tree0ac3c6c090c39df7857adbb61e6370cb3cc8863f
parentInclude message link in mod-log embeds (diff)
Format jump url bot-side
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py8
-rw-r--r--bot/exts/moderation/infraction/_utils.py27
-rw-r--r--bot/exts/moderation/infraction/management.py11
3 files changed, 28 insertions, 18 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 4b8ab18a4..de1ec398e 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -147,7 +147,7 @@ class InfractionScheduler:
icon = _utils.INFRACTION_ICONS[infr_type][0]
reason = infraction["reason"]
id_ = infraction['id']
- jump_url_text = infraction['jump_url_text']
+ jump_url = infraction['jump_url']
expiry = time.format_with_duration(
infraction["expires_at"],
infraction["last_applied"]
@@ -262,6 +262,10 @@ class InfractionScheduler:
mentions = discord.AllowedMentions(users=[user], roles=False)
await ctx.send(f"{dm_result}{confirm_msg}{infr_message}.", allowed_mentions=mentions)
+ if "discord.com" in jump_url:
+ jump_url = f"[Click here.]({jump_url})"
+ # Else, infraction was issued in ModMail category.
+
# 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_}.")
@@ -274,7 +278,7 @@ class InfractionScheduler:
Member: {messages.format_user(user)}
Actor: {ctx.author.mention}{dm_log_text}{expiry_log_text}
Reason: {reason}
- Jump url: {jump_url_text}
+ 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 0343709fa..12c8f0614 100644
--- a/bot/exts/moderation/infraction/_utils.py
+++ b/bot/exts/moderation/infraction/_utils.py
@@ -77,14 +77,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,10 +95,13 @@ async def post_infraction(
current_time = arrow.utcnow()
- if is_in_category(ctx.channel, Categories.modmail):
- jump_url_text = "Infraction issued in a ModMail channel."
+ if any(
+ is_in_category(ctx.channel, category)
+ for category in (Categories.modmail, Categories.appeals, Categories.appeals2)
+ ):
+ jump_url = "Infraction issued in a ModMail channel."
else:
- jump_url_text = f"[Click here]({ctx.message.jump_url})"
+ jump_url = ctx.message.jump_url
payload = {
"actor": ctx.author.id, # Don't use ctx.message.author; antispam only patches ctx.author.
@@ -108,7 +111,7 @@ async def post_infraction(
"user": user.id,
"active": active,
"dm_sent": dm_sent,
- "jump_url_text": jump_url_text,
+ "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 bcbacf085..78778048e 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -390,7 +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_text = infraction["jump_url_text"]
+ jump_url = infraction["jump_url"]
# Format the user string.
if user_obj := self.bot.get_user(user["id"]):
@@ -421,9 +421,12 @@ class ModManagement(commands.Cog):
else:
dm_sent_text = "Yes" if dm_sent else "No"
- if jump_url_text == "":
+ if jump_url == "":
# Infraction was issued prior to jump urls being stored in the database.
- jump_url_text = "N/A"
+ jump_url = "N/A"
+ elif "discord.com" in jump_url:
+ jump_url = f"[Click here.]({jump_url})"
+ # Else, infraction was issued in ModMail category.
lines = textwrap.dedent(f"""
{"**===============**" if active else "==============="}
@@ -437,7 +440,7 @@ class ModManagement(commands.Cog):
Duration: {duration}
Actor: <@{infraction["actor"]["id"]}>
ID: `{infraction["id"]}`
- Jump Url: {jump_url_text}
+ Jump URL: {jump_url}
Reason: {infraction["reason"] or "*None*"}
{"**===============**" if active else "==============="}
""")