Skip to content

Commit e2ef37d

Browse files
committed
Make search_keyword search regex patterns too
1 parent 3e53880 commit e2ef37d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cogs/automod.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ async def transform(self, interaction: discord.Interaction, value: str) -> disco
4040
except discord.NotFound:
4141
raise app_commands.TransformerError("Automod rule not found.", discord.AppCommandOptionType.string, self)
4242

43-
4443
@app_commands.default_permissions(ban_members=True)
4544
class AutoMod(commands.GroupCog):
4645
"""
@@ -75,14 +74,18 @@ async def search_keyword(self, interaction: discord.Interaction, word: str):
7574
for keyword in rule.trigger.keyword_filter:
7675
if word in keyword:
7776
count += 1
78-
matches[rule.name].append(f"{keyword} contains {word}")
79-
text = ""
77+
matches[rule.name].append(keyword)
78+
for keyword in rule.trigger.regex_patterns:
79+
if word in keyword:
80+
count += 1
81+
matches[rule.name].append(f"{keyword} (Regex)")
82+
text = f"Matches for {word}\n"
8083
if not count:
8184
return await interaction.response.send_message("No match found.")
8285
for rule_name in matches:
8386
if not matches[rule_name]:
8487
continue
85-
text = f'Rule {rule_name}:\n ' + ' \n'.join(matches[rule_name])
88+
text = f' Rule {rule_name}:\n' + ' \n'.join(matches[rule_name])
8689
file = text_to_discord_file(text, name='matches.txt')
8790
await interaction.response.send_message(f"{count} matches found.", file=file)
8891

0 commit comments

Comments
 (0)