From 5a621e375df50e1ec04fc3ac0cf0f2ad89bb876a Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:55:01 +0530 Subject: Added message link to replied or parent message Now we can check the replies to a deleted message to provide a better context as well as, if the deleted message is a reply to some parent message, it will show the respective parents message it was replying to in #mod-log channel --- bot/exts/moderation/modlog.py | 56 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 74bdc9db9..dcb2fa257 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -490,6 +490,7 @@ class ModLog(Cog, name="ModLog"): return channel.id in GuildConstant.modlog_blacklist + async def log_cached_deleted_message(self, message: discord.Message) -> None: """ Log the message's details to message change log. @@ -513,7 +514,7 @@ class ModLog(Cog, name="ModLog"): f"**Message ID:** `{message.id}`\n" f"**Sent at:** {format_dt(message.created_at)}\n" f"[Jump to message]({message.jump_url})\n" - "\n" + #"\n" ) else: response = ( @@ -522,14 +523,57 @@ class ModLog(Cog, name="ModLog"): f"**Message ID:** `{message.id}`\n" f"**Sent at:** {format_dt(message.created_at)}\n" f"[Jump to message]({message.jump_url})\n" - "\n" + #"\n" ) + # If the message is a reply, add the reference to the response + if message.reference is not None and message.reference.resolved is not None: + resolved_message = message.reference.resolved + + if isinstance(resolved_message, discord.Message): + jump_url = resolved_message.jump_url + if resolved_message.channel.category: + resolved_message_text = ( + f"{resolved_message.author} in " + f"{resolved_message.channel.category}/#{resolved_message.channel.name}:" + ) + else: + resolved_message_text = ( + f"{resolved_message.author} in " + f"#{resolved_message.channel.name}:" + ) + + #Shorten the message content if necessary + if len(resolved_message.clean_content) > 10: + resolved_clean_content = resolved_message.clean_content[:10] + "..." + else: + resolved_clean_content = resolved_message.clean_content + + reference_line = ( + f"**In reply to:** [{resolved_message_text}]({jump_url}) {resolved_clean_content}\n" + ) + response = reference_line + response + + # If the message is a parent messages and has replies to it, add the replies to the response + replies = await self.gather_replies(message) + if replies: + reply_lines: str = "" + for reply in replies: + if len(reply.clean_content) > 10: + short_content = reply.clean_content[:10] + "..." + reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {short_content}" + else: + full_content = reply.clean_content + reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {full_content}" + + response += "**Replies:**" + f"{reply_lines}\n" + if message.attachments: # Prepend the message metadata with the number of attachments response = f"**Attachments:** {len(message.attachments)}\n" + response # Shorten the message content if necessary + response += "\n**Deleted Message:**:\n" content = message.clean_content remaining_chars = 4090 - len(response) @@ -550,6 +594,14 @@ class ModLog(Cog, name="ModLog"): channel_id=Channels.message_log ) + async def gather_replies(self, message: discord.Message) -> list: + """Gather replies to the given message.""" + replies = [] + async for msg in message.channel.history(after=message.created_at, limit=100): + if msg.reference and msg.reference.message_id == message.id: + replies.append(msg) + return replies + async def log_uncached_deleted_message(self, event: discord.RawMessageDeleteEvent) -> None: """ Log the message's details to message change log. -- cgit v1.2.3 From ef57d539ff69b9c3357a6d685934135e94af5d9c Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:09:08 +0530 Subject: Update modlog.py --- bot/exts/moderation/modlog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index dcb2fa257..9ba30b8e8 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -597,7 +597,7 @@ class ModLog(Cog, name="ModLog"): async def gather_replies(self, message: discord.Message) -> list: """Gather replies to the given message.""" replies = [] - async for msg in message.channel.history(after=message.created_at, limit=100): + async for msg in message.channel.history(after=message.created_at, limit=10): if msg.reference and msg.reference.message_id == message.id: replies.append(msg) return replies -- cgit v1.2.3 From 7e0fa0ef1abeafa1346cf91ddcd3173715d2e17f Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:40:11 +0530 Subject: Update bot/exts/moderation/modlog.py Co-authored-by: Vivek Ashokkumar --- bot/exts/moderation/modlog.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 9ba30b8e8..17f8a1eae 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -559,12 +559,10 @@ class ModLog(Cog, name="ModLog"): if replies: reply_lines: str = "" for reply in replies: - if len(reply.clean_content) > 10: - short_content = reply.clean_content[:10] + "..." - reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {short_content}" - else: - full_content = reply.clean_content - reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {full_content}" + content = reply.clean_content + if len(content) > 10: + content = content[:10] + "..." + reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {content}" response += "**Replies:**" + f"{reply_lines}\n" -- cgit v1.2.3 From 6ea894bf3fe688641b09d8c661b2b8bb4611b6de Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:41:31 +0530 Subject: Update bot/exts/moderation/modlog.py Co-authored-by: Vivek Ashokkumar --- bot/exts/moderation/modlog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 17f8a1eae..2d614a04f 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -564,7 +564,7 @@ class ModLog(Cog, name="ModLog"): content = content[:10] + "..." reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {content}" - response += "**Replies:**" + f"{reply_lines}\n" + response += f"**Replies:** {reply_lines}\n" if message.attachments: # Prepend the message metadata with the number of attachments -- cgit v1.2.3 From 98d806cceb00932ddced378608c5cb5d960811ef Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Wed, 26 Jun 2024 22:12:52 +0530 Subject: Update bot/exts/moderation/modlog.py Co-authored-by: Vivek Ashokkumar --- bot/exts/moderation/modlog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 2d614a04f..2ce516afb 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -592,7 +592,7 @@ class ModLog(Cog, name="ModLog"): channel_id=Channels.message_log ) - async def gather_replies(self, message: discord.Message) -> list: + async def gather_replies(self, message: discord.Message) -> list[Message]: """Gather replies to the given message.""" replies = [] async for msg in message.channel.history(after=message.created_at, limit=10): -- cgit v1.2.3 From 9d58aa15d25cb72513e26a220b02499a9b007725 Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Fri, 28 Jun 2024 22:46:44 +0530 Subject: removed gather_reply() - gather_reply() can be resource intensive for big servers as it will iterate through all the message every time a user deletes any message which has replies to it. - removed content and channel in `In reply to:` section as some messages containing `[` or `]` can create interference with the `[](url)` --- bot/exts/moderation/modlog.py | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 2ce516afb..014cb6c34 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -532,40 +532,13 @@ class ModLog(Cog, name="ModLog"): if isinstance(resolved_message, discord.Message): jump_url = resolved_message.jump_url - if resolved_message.channel.category: - resolved_message_text = ( - f"{resolved_message.author} in " - f"{resolved_message.channel.category}/#{resolved_message.channel.name}:" - ) - else: - resolved_message_text = ( - f"{resolved_message.author} in " - f"#{resolved_message.channel.name}:" - ) - - #Shorten the message content if necessary - if len(resolved_message.clean_content) > 10: - resolved_clean_content = resolved_message.clean_content[:10] + "..." - else: - resolved_clean_content = resolved_message.clean_content + author = resolved_message.author.mention reference_line = ( - f"**In reply to:** [{resolved_message_text}]({jump_url}) {resolved_clean_content}\n" + f"**In reply to:** {author} [Jump to message]({jump_url})\n" ) response = reference_line + response - # If the message is a parent messages and has replies to it, add the replies to the response - replies = await self.gather_replies(message) - if replies: - reply_lines: str = "" - for reply in replies: - content = reply.clean_content - if len(content) > 10: - content = content[:10] + "..." - reply_lines += f"\n- {format_user(reply.author)}[Jump to message]({reply.jump_url}) {content}" - - response += f"**Replies:** {reply_lines}\n" - if message.attachments: # Prepend the message metadata with the number of attachments response = f"**Attachments:** {len(message.attachments)}\n" + response @@ -592,14 +565,6 @@ class ModLog(Cog, name="ModLog"): channel_id=Channels.message_log ) - async def gather_replies(self, message: discord.Message) -> list[Message]: - """Gather replies to the given message.""" - replies = [] - async for msg in message.channel.history(after=message.created_at, limit=10): - if msg.reference and msg.reference.message_id == message.id: - replies.append(msg) - return replies - async def log_uncached_deleted_message(self, event: discord.RawMessageDeleteEvent) -> None: """ Log the message's details to message change log. -- cgit v1.2.3 From b3c7ef12c365b24e266f7743dca3a2bf16f1fab3 Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:43:54 +0530 Subject: removed commented newlines --- bot/exts/moderation/modlog.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 014cb6c34..21b24a4ef 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -514,7 +514,6 @@ class ModLog(Cog, name="ModLog"): f"**Message ID:** `{message.id}`\n" f"**Sent at:** {format_dt(message.created_at)}\n" f"[Jump to message]({message.jump_url})\n" - #"\n" ) else: response = ( @@ -523,7 +522,6 @@ class ModLog(Cog, name="ModLog"): f"**Message ID:** `{message.id}`\n" f"**Sent at:** {format_dt(message.created_at)}\n" f"[Jump to message]({message.jump_url})\n" - #"\n" ) # If the message is a reply, add the reference to the response -- cgit v1.2.3 From e37222f6000547e722ed5a5934ad7e2db3ec574c Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:30:11 +0530 Subject: Update bot/exts/moderation/modlog.py Co-authored-by: Boris Muratov <8bee278@gmail.com> --- bot/exts/moderation/modlog.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 21b24a4ef..601da50f4 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -489,8 +489,6 @@ class ModLog(Cog, name="ModLog"): return True return channel.id in GuildConstant.modlog_blacklist - - async def log_cached_deleted_message(self, message: discord.Message) -> None: """ Log the message's details to message change log. -- cgit v1.2.3 From 9946b0a70553235de5b082fa4568ef99aecc6a21 Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:46:24 +0530 Subject: "Jump to message" changed and added handling for Reference deleted messages - [x] Changed "Jump to message" to "Jump to referenced message" as it already exists in the embed, thus can create confusion - [x] if the Reference message is deleted messages it will now give reference line as **In reply to:** Deleted Message --- bot/exts/moderation/modlog.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 601da50f4..15b8f6a3a 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -489,6 +489,7 @@ class ModLog(Cog, name="ModLog"): return True return channel.id in GuildConstant.modlog_blacklist + async def log_cached_deleted_message(self, message: discord.Message) -> None: """ Log the message's details to message change log. @@ -526,12 +527,17 @@ class ModLog(Cog, name="ModLog"): if message.reference is not None and message.reference.resolved is not None: resolved_message = message.reference.resolved - if isinstance(resolved_message, discord.Message): + if isinstance(resolved_message, discord.DeletedReferencedMessage): + # Reference is a deleted message + reference_line = "**In reply to:** Deleted Message" + response = reference_line + response + + elif isinstance(resolved_message, discord.Message): jump_url = resolved_message.jump_url author = resolved_message.author.mention reference_line = ( - f"**In reply to:** {author} [Jump to message]({jump_url})\n" + f"**In reply to:** {author} [Jump to referenced message]({jump_url})\n" ) response = reference_line + response -- cgit v1.2.3 From 5d3962374400939e3e3e7a6bbe4f6a751e4bcb1e Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:16:47 +0530 Subject: Update bot/exts/moderation/modlog.py - It was working fine without it, but i think its better to add one. Thanks Co-authored-by: Vivek Ashokkumar --- bot/exts/moderation/modlog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 15b8f6a3a..3f4cd68c4 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -529,7 +529,7 @@ class ModLog(Cog, name="ModLog"): if isinstance(resolved_message, discord.DeletedReferencedMessage): # Reference is a deleted message - reference_line = "**In reply to:** Deleted Message" + reference_line = "**In reply to:** Deleted Message\n" response = reference_line + response elif isinstance(resolved_message, discord.Message): -- cgit v1.2.3 From 3363c85f6be4c2fd5d73a7161fddc9bc853e0239 Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:48:59 +0530 Subject: added handler for message.reference.resolved if its None --- bot/exts/moderation/modlog.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 3f4cd68c4..880631097 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -529,7 +529,7 @@ class ModLog(Cog, name="ModLog"): if isinstance(resolved_message, discord.DeletedReferencedMessage): # Reference is a deleted message - reference_line = "**In reply to:** Deleted Message\n" + reference_line = f"**In reply to:** `{resolved_message.id}`(Deleted Message)\n" response = reference_line + response elif isinstance(resolved_message, discord.Message): @@ -541,6 +541,12 @@ class ModLog(Cog, name="ModLog"): ) response = reference_line + response + elif message.reference is not None and message.reference.resolved is None: + reference_line = ( + "**In reply to:** (Message could not be resolved)\n" + ) + response = reference_line + response + if message.attachments: # Prepend the message metadata with the number of attachments response = f"**Attachments:** {len(message.attachments)}\n" + response -- cgit v1.2.3 From 76047aa96a7f65b7877a3cd6f1745ccb8f4014aa Mon Sep 17 00:00:00 2001 From: Shambo Chowdhury <54593764+typhonshambo@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:32:02 +0530 Subject: Removed over-indented block --- bot/exts/moderation/modlog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 880631097..ebd156d4b 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -542,10 +542,10 @@ class ModLog(Cog, name="ModLog"): response = reference_line + response elif message.reference is not None and message.reference.resolved is None: - reference_line = ( - "**In reply to:** (Message could not be resolved)\n" - ) - response = reference_line + response + reference_line = ( + "**In reply to:** (Message could not be resolved)\n" + ) + response = reference_line + response if message.attachments: # Prepend the message metadata with the number of attachments -- cgit v1.2.3