From 46a7b9785902729da8e7de01935f0af3d53384ca Mon Sep 17 00:00:00 2001 From: vivekashok1221 Date: Fri, 30 Dec 2022 19:29:00 +0400 Subject: [PATCH 1/5] Display message link in infraction log --- bot/exts/moderation/infraction/_utils.py | 9 ++++++++- bot/exts/moderation/infraction/management.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py index 2cf7f8efb0..0343709faa 100644 --- a/bot/exts/moderation/infraction/_utils.py +++ b/bot/exts/moderation/infraction/_utils.py @@ -6,11 +6,12 @@ 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__) @@ -94,6 +95,11 @@ 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." + else: + jump_url_text = f"[Click here]({ctx.message.jump_url})" + payload = { "actor": ctx.author.id, # Don't use ctx.message.author; antispam only patches ctx.author. "hidden": hidden, @@ -102,6 +108,7 @@ async def post_infraction( "user": user.id, "active": active, "dm_sent": dm_sent, + "jump_url_text": jump_url_text, "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 6ef3821196..bcbacf0851 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -390,6 +390,7 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: 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"] # Format the user string. if user_obj := self.bot.get_user(user["id"]): @@ -420,6 +421,10 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: else: dm_sent_text = "Yes" if dm_sent else "No" + if jump_url_text == "": + # Infraction was issued prior to jump urls being stored in the database. + jump_url_text = "N/A" + lines = textwrap.dedent(f""" {"**===============**" if active else "==============="} Status: {"__**Active**__" if active else "Inactive"} @@ -432,6 +437,7 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: Duration: {duration} Actor: <@{infraction["actor"]["id"]}> ID: `{infraction["id"]}` + Jump Url: {jump_url_text} Reason: {infraction["reason"] or "*None*"} {"**===============**" if active else "==============="} """) From c6af8bfdb5d57ed304636b4eb89343e40e928dad Mon Sep 17 00:00:00 2001 From: vivekashok1221 Date: Sat, 31 Dec 2022 11:14:48 +0400 Subject: [PATCH 2/5] Include message link in mod-log embeds --- bot/exts/moderation/infraction/_scheduler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index 9b8e67ec5a..4b8ab18a47 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -147,6 +147,7 @@ async def apply_infraction( icon = _utils.INFRACTION_ICONS[infr_type][0] reason = infraction["reason"] id_ = infraction['id'] + jump_url_text = infraction['jump_url_text'] expiry = time.format_with_duration( infraction["expires_at"], infraction["last_applied"] @@ -273,6 +274,7 @@ async def apply_infraction( Member: {messages.format_user(user)} Actor: {ctx.author.mention}{dm_log_text}{expiry_log_text} Reason: {reason} + Jump url: {jump_url_text} {additional_info} """), content=log_content, From ed59a9fd38f8bcfcb81efaf66f86e7ebc6661665 Mon Sep 17 00:00:00 2001 From: vivekashok1221 Date: Fri, 17 Feb 2023 11:35:00 +0530 Subject: [PATCH 3/5] Format jump url bot-side --- bot/exts/moderation/infraction/_scheduler.py | 8 ++++-- bot/exts/moderation/infraction/_utils.py | 27 +++++++++++--------- bot/exts/moderation/infraction/management.py | 11 +++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index 4b8ab18a47..de1ec398e2 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -147,7 +147,7 @@ async def apply_infraction( 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 @@ async def apply_infraction( 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 @@ async def apply_infraction( 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 0343709faa..12c8f06140 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 bcbacf0851..78778048e7 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -390,7 +390,7 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: 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 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: 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 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: 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 "==============="} """) From 0cc7fa30ca30c756c64c05d081ddb927dcbe19c2 Mon Sep 17 00:00:00 2001 From: vivekashok1221 Date: Fri, 10 Mar 2023 23:28:13 +0530 Subject: [PATCH 4/5] Display "N/A" for infractions in ModMail Previously displayed "Infraction issued in modmail" for infractions in ModMail. --- bot/exts/moderation/infraction/_scheduler.py | 6 ++++-- bot/exts/moderation/infraction/_utils.py | 2 +- bot/exts/moderation/infraction/management.py | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index de1ec398e2..63aac63400 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -262,9 +262,11 @@ async def apply_infraction( 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: + if jump_url is None: + # Infraction issued in ModMail category. + jump_url = "N/A" + else: 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. diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py index 12c8f06140..edd875921e 100644 --- a/bot/exts/moderation/infraction/_utils.py +++ b/bot/exts/moderation/infraction/_utils.py @@ -99,7 +99,7 @@ async def post_infraction( is_in_category(ctx.channel, category) for category in (Categories.modmail, Categories.appeals, Categories.appeals2) ): - jump_url = "Infraction issued in a ModMail channel." + jump_url = None else: jump_url = ctx.message.jump_url diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 78778048e7..aafa6d9b01 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -421,12 +421,12 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str: else: dm_sent_text = "Yes" if dm_sent else "No" - if jump_url == "": - # Infraction was issued prior to jump urls being stored in the database. + 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" - elif "discord.com" in jump_url: + else: jump_url = f"[Click here.]({jump_url})" - # Else, infraction was issued in ModMail category. lines = textwrap.dedent(f""" {"**===============**" if active else "==============="} From 0e116430be8ef2e0bda2ad195250a88b792bd7b8 Mon Sep 17 00:00:00 2001 From: vivekashok1221 Date: Sat, 11 Mar 2023 23:52:31 +0530 Subject: [PATCH 5/5] Update appeals2 to appeals_2 to reflect config change --- bot/exts/moderation/infraction/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py index f86c78707f..5e9fa75cca 100644 --- a/bot/exts/moderation/infraction/_utils.py +++ b/bot/exts/moderation/infraction/_utils.py @@ -98,7 +98,7 @@ async def post_infraction( if any( is_in_category(ctx.channel, category) - for category in (Categories.modmail, Categories.appeals, Categories.appeals2) + for category in (Categories.modmail, Categories.appeals, Categories.appeals_2) ): jump_url = None else: