From d2cf3549ece5640fd7e215a75e12421c8f19fa10 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 20 Jul 2021 08:15:15 -0600 Subject: [PATCH 1/4] 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"} ) From 667de50f912b0be9832262355834c29aac13272c Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 20 Jul 2021 08:38:55 -0600 Subject: [PATCH 2/4] Update regex to close #59 --- jarvis/__init__.py | 18 +++++++++++++----- jarvis/cogs/modlog.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index dbaa0c3..cc2f332 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) - if matches: - if matches.group(5) not in ["dbrand", "VtgZntXcnZ"]: + content = re.sub(r"\s+", "", message.content) + content = re.sub(r"[^\w\d./]+", "", content) + match = invites.search(content) + if match: + guild_invites = await message.guild.invites() + allowed = [x.code for x in guild_invites] + [ + "dbrand", + "VtgZntXcnZ", + ] + if match.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"} ) From df44dd6c72c49db3deac046b3d44226cccdd0fb4 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 20 Jul 2021 08:39:56 -0600 Subject: [PATCH 3/4] Merge branch 'bugfix-59' of git.zevaryx.com:stark-industries/j.a.r.v.i.s. into bugfix-59 --- jarvis/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index cc2f332..da05ec4 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -194,15 +194,25 @@ async def on_message(message: Message): if autopurge: await message.delete(delay=autopurge["delay"]) content = re.sub(r"\s+", "", message.content) +<<<<<<< HEAD content = re.sub(r"[^\w\d./]+", "", content) match = invites.search(content) if match: +======= + content = re.sub(r"[^\w\s]", "", content) + matches = invites.match(content) + if matches: +>>>>>>> d2cf3549ece5640fd7e215a75e12421c8f19fa10 guild_invites = await message.guild.invites() allowed = [x.code for x in guild_invites] + [ "dbrand", "VtgZntXcnZ", ] +<<<<<<< HEAD if match.group(6) not in allowed: +======= + if matches.group(6) not in allowed: +>>>>>>> d2cf3549ece5640fd7e215a75e12421c8f19fa10 await message.delete() db.jarvis.warns.insert_one( { From c98130b65415519ef40312d6890ed72d0588e02a Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 20 Jul 2021 18:35:03 -0600 Subject: [PATCH 4/4] Properly fix regex detection of invites --- jarvis/__init__.py | 15 ++------------- jarvis/cogs/modlog.py | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index da05ec4..0b6530d 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -25,7 +25,7 @@ intents.members = True restart_ctx = None invites = re.compile( - r"(https?://)?(www.)?(discord.(gg|io|me|li)|discord(app)?.com/invite)/([^\s/]+?)(?=\b)", + r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", flags=re.IGNORECASE, ) @@ -194,25 +194,14 @@ async def on_message(message: Message): if autopurge: await message.delete(delay=autopurge["delay"]) content = re.sub(r"\s+", "", message.content) -<<<<<<< HEAD - content = re.sub(r"[^\w\d./]+", "", content) match = invites.search(content) if match: -======= - content = re.sub(r"[^\w\s]", "", content) - matches = invites.match(content) - if matches: ->>>>>>> d2cf3549ece5640fd7e215a75e12421c8f19fa10 guild_invites = await message.guild.invites() allowed = [x.code for x in guild_invites] + [ "dbrand", "VtgZntXcnZ", ] -<<<<<<< HEAD - if match.group(6) not in allowed: -======= - if matches.group(6) not in allowed: ->>>>>>> d2cf3549ece5640fd7e215a75e12421c8f19fa10 + if match.group(1) not in allowed: await message.delete() db.jarvis.warns.insert_one( { diff --git a/jarvis/cogs/modlog.py b/jarvis/cogs/modlog.py index 853a927..b89bf1f 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.user.id: + if before.author != get_config().client_id: modlog = self.db.jarvis.settings.find_one( {"guild": after.guild.id, "setting": "modlog"} )