aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar momothereal <[email protected]>2018-07-24 02:46:18 -0400
committerGravatar momothereal <[email protected]>2018-07-24 02:46:18 -0400
commit869e7e3e7bbedf2d6aa3ae6e6ab49adaf1c264a3 (patch)
treed78f3cc8084ca0aa3a8f7af7db1d21ef90707bd5
parentShow active status in infraction list, fix Discord pagination rendering issue (diff)
Add support for searching infractions by reason
-rw-r--r--bot/cogs/moderation.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py
index 69cdfb10c..59357e4cb 100644
--- a/bot/cogs/moderation.py
+++ b/bot/cogs/moderation.py
@@ -339,7 +339,7 @@ class Moderation:
async def search(self, ctx, arg: InfractionSearchQuery):
"""
Searches for infractions in the database.
- :param arg: Either a user or a reason string.
+ :param arg: Either a user or a reason string. If a string, you can use the Re2 matching syntax.
"""
if isinstance(arg, User):
user: User = arg
@@ -366,20 +366,41 @@ class Moderation:
colour=Colour.orange()
)
- await LinePaginator.paginate(
- lines=(self.infraction_to_string(infraction_object) for infraction_object in infraction_list),
- ctx=ctx,
- embed=embed,
- empty=True,
- max_lines=3,
- max_size=1000
- )
-
elif isinstance(arg, str):
# search by reason
- return
+ try:
+ response = await self.bot.http_session.get(
+ URLs.site_infractions,
+ headers=self.headers,
+ params={"search": arg}
+ )
+ infraction_list = await response.json()
+ except Exception:
+ log.exception("There was an error fetching infractions.")
+ await ctx.send(":x: There was an error fetching infraction.")
+ return
+
+ if not infraction_list:
+ await ctx.send(f":warning: No infractions matching \"{arg}\".")
+ return
+
+ embed = Embed(
+ title=f"Infractions matching \"{arg}\" ({len(infraction_list)} total)",
+ colour=Colour.orange()
+ )
+
else:
await ctx.send(":x: Invalid infraction search query.")
+ return
+
+ await LinePaginator.paginate(
+ lines=(self.infraction_to_string(infraction_object) for infraction_object in infraction_list),
+ ctx=ctx,
+ embed=embed,
+ empty=True,
+ max_lines=3,
+ max_size=1000
+ )
# Utility functions