diff options
author | 2022-02-19 20:38:02 +0000 | |
---|---|---|
committer | 2022-02-19 20:38:02 +0000 | |
commit | ddb5d8082a8a0d04f8bc459989ca620c5e927279 (patch) | |
tree | 43d5504ceb7b5dfaf8c117a2361d573ea87822f9 | |
parent | Merge pull request #2098 from minalike/enhancement/uid-mod-alerts2 (diff) | |
parent | Merge branch 'main' into fix-bot-2093 (diff) |
Merge pull request #2094 from python-discord/fix-bot-2093
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..a883ddf54 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 as e: + await ctx.message.add_reaction("❌") + await ctx.send( + f"{ctx.author.mention} that's not a valid regex! " + f"Regex error message: {e.msg}." + ) + 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 = { |