diff options
| author | 2021-10-31 16:04:16 +0000 | |
|---|---|---|
| committer | 2021-11-01 21:07:46 +0000 | |
| commit | f315f4c18571b3e5a7d8e322db4dbc0f3f13943b (patch) | |
| tree | 55e95809491b818d1fec36a62eb58c16207e0161 | |
| parent | Merge pull request #1897 from python-discord/modlog/correct-color-names (diff) | |
Add support for `!infractions by <m|me|uid>`
| -rw-r--r-- | bot/exts/moderation/infraction/management.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index b1c8b64dc..8c1ef057c 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -263,6 +263,44 @@ class ModManagement(commands.Cog): await self.send_infraction_list(ctx, embed, infraction_list) # endregion + # region: Search infractions by given user + @infraction_group.command(name="by", aliases=("b",)) + async def search_by_user( + self, + ctx: Context, + user: t.Union[discord.Member, t.Literal["m", "me"]], + oldest_first: bool = False + ) -> None: + """ + Search for infractions made by `user`. + + Use "m" or "me" as the `user` to get infractions by author. + + Use "1" for `oldest_first` to send oldest infractions first. + """ + if isinstance(user, discord.Member): + moderator_id = user.id + moderator_name_discrim = str(user) + else: + moderator_id = ctx.author.id + moderator_name_discrim = str(ctx.author) + + infraction_list = await self.bot.api_client.get( + 'bot/infractions/expanded', + params={ + 'actor__id': str(moderator_id), + 'ordering': f'{["-", ""][oldest_first]}inserted_at' # `'inserted_at'` makes api return oldest first + } + ) + + embed = discord.Embed( + title=f"Infractions by `{moderator_name_discrim}` (`{moderator_id}`)", + colour=discord.Colour.orange() + ) + + await self.send_infraction_list(ctx, embed, infraction_list) + + # endregion # region: Utility functions async def send_infraction_list( |