aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-04-05 20:42:51 +0100
committerGravatar GitHub <[email protected]>2022-04-05 15:42:51 -0400
commitf4a3de4cb399aa0c51ed6b8df6fbc45f27f38613 (patch)
treeaac91fe17539f3bf86a44602b23dc7d3d27f3e36
parentMerge pull request #1943 from jonathan-d-zhang/type-hint-tag (diff)
Parse infraction search reason as regex before calling site (#2126)
Previously this would raise an error within site due to the invalid regexp.
-rw-r--r--bot/exts/moderation/infraction/management.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index 62d349519..81f623688 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -1,3 +1,4 @@
+import re
import textwrap
import typing as t
@@ -275,6 +276,11 @@ class ModManagement(commands.Cog):
@infraction_search_group.command(name="reason", aliases=("match", "regex", "re"))
async def search_reason(self, ctx: Context, reason: str) -> None:
"""Search for infractions by their reason. Use Re2 for matching."""
+ try:
+ re.compile(reason)
+ except re.error as e:
+ raise commands.BadArgument(f"Invalid regular expression in `reason`: {e}")
+
infraction_list = await self.bot.api_client.get(
'bot/infractions/expanded',
params={'search': reason}