Update regex to close #59

This commit is contained in:
Zeva Rose 2021-07-20 08:38:55 -06:00
parent 4b32493cc8
commit 667de50f91
2 changed files with 14 additions and 6 deletions

View file

@ -25,7 +25,8 @@ intents.members = True
restart_ctx = None restart_ctx = None
invites = re.compile( 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): async def on_message(message: Message):
if ( if (
not isinstance(message.channel, DMChannel) 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( autoreact = db.jarvis.autoreact.find_one(
{"guild": message.guild.id, "channel": message.channel.id} {"guild": message.guild.id, "channel": message.channel.id}
@ -192,9 +193,16 @@ async def on_message(message: Message):
) )
if autopurge: if autopurge:
await message.delete(delay=autopurge["delay"]) await message.delete(delay=autopurge["delay"])
matches = invites.match(message.content) content = re.sub(r"\s+", "", message.content)
if matches: content = re.sub(r"[^\w\d./]+", "", content)
if matches.group(5) not in ["dbrand", "VtgZntXcnZ"]: 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() await message.delete()
db.jarvis.warns.insert_one( db.jarvis.warns.insert_one(
{ {

View file

@ -357,7 +357,7 @@ class ModlogCog(commands.Cog):
async def on_message_edit( async def on_message_edit(
self, before: discord.Message, after: discord.Message 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( modlog = self.db.jarvis.settings.find_one(
{"guild": after.guild.id, "setting": "modlog"} {"guild": after.guild.id, "setting": "modlog"}
) )