Add [p]listcases command and typing indicator to [p]casesfor (#4426)

* [ModLog] Add [p]listcases and typing indicator to casesfor

* weird

* Address review

* Update redbot/cogs/modlog/modlog.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
TrustyJAID 2021-01-23 12:48:31 -07:00 committed by GitHub
parent aa0ee3385d
commit e106dfaece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ import discord
from redbot.core import checks, commands, modlog
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import box
from redbot.core.utils.chat_formatting import box, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
_ = Translator("ModLog", __file__)
@ -129,6 +129,7 @@ class ModLog(commands.Cog):
@commands.guild_only()
async def casesfor(self, ctx: commands.Context, *, member: Union[discord.Member, int]):
"""Display cases for the specified member."""
async with ctx.typing():
try:
if isinstance(member, int):
cases = await modlog.get_cases_for_member(
@ -164,6 +165,42 @@ class ModLog(commands.Cog):
await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
@commands.command()
@commands.guild_only()
async def listcases(self, ctx: commands.Context, *, member: Union[discord.Member, int]):
"""List cases for the specified member."""
async with ctx.typing():
try:
if isinstance(member, int):
cases = await modlog.get_cases_for_member(
bot=ctx.bot, guild=ctx.guild, member_id=member
)
else:
cases = await modlog.get_cases_for_member(
bot=ctx.bot, guild=ctx.guild, member=member
)
except discord.NotFound:
return await ctx.send(_("That user does not exist."))
except discord.HTTPException:
return await ctx.send(
_("Something unexpected went wrong while fetching that user by ID.")
)
if not cases:
return await ctx.send(_("That user does not have any cases."))
rendered_cases = []
message = ""
for case in cases:
message += _("{case}\n**Timestamp:** {timestamp}\n\n").format(
case=await case.message_content(embed=False),
timestamp=datetime.utcfromtimestamp(case.created_at).strftime(
"%Y-%m-%d %H:%M:%S UTC"
),
)
for page in pagify(message, ["\n\n", "\n"], priority=True):
rendered_cases.append(page)
await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
@commands.command()
@commands.guild_only()
async def reason(self, ctx: commands.Context, case: Optional[int], *, reason: str):