From d2cf3549ece5640fd7e215a75e12421c8f19fa10 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 20 Jul 2021 08:15:15 -0600 Subject: [PATCH] Update regex to close #59 --- jarvis/__init__.py | 16 ++++++++++++---- jarvis/cogs/modlog.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index dbaa0c3..0838d32 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -25,7 +25,8 @@ intents.members = True restart_ctx = None invites = re.compile( - r"(https?://)?(www.)?(discord.(gg|io|me|li)|discordapp.com/invite)/([^\s/]+?)(?=\b)" + r"(https?://)?(www.)?(discord.(gg|io|me|li)|discord(app)?.com/invite)/([^\s/]+?)(?=\b)", + flags=re.IGNORECASE, ) @@ -92,7 +93,7 @@ async def on_member_join(user: Member): async def on_message(message: Message): if ( not isinstance(message.channel, DMChannel) - and not message.author.id == get_config().client_id + and message.author.id != jarvis.user.id ): autoreact = db.jarvis.autoreact.find_one( {"guild": message.guild.id, "channel": message.channel.id} @@ -192,9 +193,16 @@ async def on_message(message: Message): ) if autopurge: await message.delete(delay=autopurge["delay"]) - matches = invites.match(message.content) + content = re.sub(r"\s+", "", message.content) + content = re.sub(r"[^\w\s]", "", content) + matches = invites.match(content) if matches: - if matches.group(5) not in ["dbrand", "VtgZntXcnZ"]: + guild_invites = await message.guild.invites() + allowed = [x.code for x in guild_invites] + [ + "dbrand", + "VtgZntXcnZ", + ] + if matches.group(6) not in allowed: await message.delete() db.jarvis.warns.insert_one( { diff --git a/jarvis/cogs/modlog.py b/jarvis/cogs/modlog.py index c48153d..853a927 100644 --- a/jarvis/cogs/modlog.py +++ b/jarvis/cogs/modlog.py @@ -357,7 +357,7 @@ class ModlogCog(commands.Cog): async def on_message_edit( self, before: discord.Message, after: discord.Message ): - if before.author != self.bot.client.id: + if before.author != self.bot.user.id: modlog = self.db.jarvis.settings.find_one( {"guild": after.guild.id, "setting": "modlog"} )