From 8d6475a9195471e17932094d094857ebff950a9e Mon Sep 17 00:00:00 2001 From: Nawaf <30420446+xLive@users.noreply.github.com> Date: Fri, 5 Sep 2025 17:31:09 +0300 Subject: [PATCH 1/2] extendedmodlog: make URLs unclickable --- extendedmodlog/eventmixin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extendedmodlog/eventmixin.py b/extendedmodlog/eventmixin.py index 1dedbfab..575180b3 100644 --- a/extendedmodlog/eventmixin.py +++ b/extendedmodlog/eventmixin.py @@ -1,7 +1,8 @@ import asyncio import datetime import logging -from typing import Sequence, Union, cast, Optional, Tuple +from typing import Sequence, Union, cast, Optional, Tuple, Pattern +import re import discord from discord.ext.commands.converter import Converter @@ -20,6 +21,9 @@ _ = Translator("ExtendedModLog", __file__) logger = logging.getLogger("red.trusty-cogs.ExtendedModLog") +LINK_RE: Pattern = re.compile( + r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)", re.I +) class CommandPrivs(Converter): """ @@ -380,8 +384,9 @@ async def _cached_message_delete( channel=message_channel, ) if embed_links: + filtered_content = LINK_RE.sub(r"\g<0>​", message.content) # make urls unclickable embed = discord.Embed( - description=f"{message.author.mention}: {message.content}", + description=f"{message.author.mention}: {filtered_content}", colour=await self.get_event_colour(guild, "message_delete"), timestamp=time, ) From 398833729bdbc64843df3751af9c023be6eccc99 Mon Sep 17 00:00:00 2001 From: Nawaf <30420446+xLive@users.noreply.github.com> Date: Fri, 5 Sep 2025 17:31:24 +0300 Subject: [PATCH 2/2] spam: make URLs unclickable --- spam/spam.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spam/spam.py b/spam/spam.py index 5fb52b50..84176a0a 100644 --- a/spam/spam.py +++ b/spam/spam.py @@ -12,6 +12,10 @@ r"(?:https?\:\/\/)?discord(?:\.gg|(?:app)?\.com\/invite)\/([a-zA-Z0-9]+)", re.I ) +LINK_RE: Pattern = re.compile( + r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)", re.I +) + class spam(commands.Cog): """ MTA:SA Spam Cog """ @@ -189,7 +193,7 @@ async def on_message(self, ctx): if feed: embed = discord.Embed(colour=discord.Colour(0xf5a623), description="Spam protection deleted an invite (Whitelist) in <#"+str(ctx.channel.id)+">") embed.add_field(name="**Author:**", value="<@"+str(ctx.author.id)+">", inline=False) - embed.add_field(name="**Message:**", value=ctx.content, inline=False) + embed.add_field(name="**Message:**", value=LINK_RE.sub(r"\g<0>​", ctx.content), inline=False) # make urls unclickable await self.bot.get_channel(int(await self.config.guild(ctx.guild).feed())).send(embed=embed) return @@ -201,7 +205,7 @@ async def on_message(self, ctx): if feed: embed = discord.Embed(colour=discord.Colour(0xf5a623), description="Spam protection deleted an invite (Blocked) in <#"+str(ctx.channel.id)+">") embed.add_field(name="**Author:**", value="<@"+str(ctx.author.id)+">", inline=False) - embed.add_field(name="**Message:**", value=ctx.content, inline=False) + embed.add_field(name="**Message:**", value=LINK_RE.sub(r"\g<0>​", ctx.content), inline=False) # make urls unclickable await self.bot.get_channel(int(await self.config.guild(ctx.guild).feed())).send(embed=embed) return await ctx.delete() @@ -212,7 +216,7 @@ async def on_message(self, ctx): if feed: embed = discord.Embed(colour=discord.Colour(0xf5a623), description="Spam protection deleted a message in <#"+str(ctx.channel.id)+">") embed.add_field(name="**Author:**", value="<@"+str(ctx.author.id)+">", inline=False) - embed.add_field(name="**Message:**", value=ctx.content, inline=False) + embed.add_field(name="**Message:**", value=LINK_RE.sub(r"\g<0>​", ctx.content), inline=False) # make urls unclickable await self.bot.get_channel(int(await self.config.guild(ctx.guild).feed())).send(embed=embed) await ctx.delete() return