diff options
author | 2022-02-17 11:01:53 +0000 | |
---|---|---|
committer | 2022-02-17 11:01:53 +0000 | |
commit | abfb0ed9f0b3f1c676dc75707e51b33ded86cdf5 (patch) | |
tree | c5759223f58c7f3ea4785bdf1cdcec5168294f1d | |
parent | Remove unnecessary Infraction conversion in clean ban (#2092) (diff) |
Validate regex when adding to the filter_token filter
-rw-r--r-- | bot/exts/filters/filter_lists.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/bot/exts/filters/filter_lists.py b/bot/exts/filters/filter_lists.py index ee5bd89f3..d3e6393d3 100644 --- a/bot/exts/filters/filter_lists.py +++ b/bot/exts/filters/filter_lists.py @@ -1,3 +1,4 @@ +import re from typing import Optional from discord import Colour, Embed @@ -72,6 +73,18 @@ class FilterLists(Cog): elif list_type == "FILE_FORMAT" and not content.startswith("."): content = f".{content}" + # If it's a filter token, validate the passed regex + elif list_type == "FILTER_TOKEN": + try: + _ = re.compile(content) + except re.error: + await ctx.message.add_reaction("❌") + await ctx.send( + f"{ctx.author.mention} that's not a valid regex! " + "You may have forgotten to escape part of the regex." + ) + return + # Try to add the item to the database log.trace(f"Trying to add the {content} item to the {list_type} {allow_type}") payload = { |