mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
aa0ee3385d
commit
e106dfaece
@ -7,7 +7,7 @@ import discord
|
|||||||
from redbot.core import checks, commands, modlog
|
from redbot.core import checks, commands, modlog
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
from redbot.core.i18n import Translator, cog_i18n
|
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
|
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
|
||||||
|
|
||||||
_ = Translator("ModLog", __file__)
|
_ = Translator("ModLog", __file__)
|
||||||
@ -129,6 +129,7 @@ class ModLog(commands.Cog):
|
|||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def casesfor(self, ctx: commands.Context, *, member: Union[discord.Member, int]):
|
async def casesfor(self, ctx: commands.Context, *, member: Union[discord.Member, int]):
|
||||||
"""Display cases for the specified member."""
|
"""Display cases for the specified member."""
|
||||||
|
async with ctx.typing():
|
||||||
try:
|
try:
|
||||||
if isinstance(member, int):
|
if isinstance(member, int):
|
||||||
cases = await modlog.get_cases_for_member(
|
cases = await modlog.get_cases_for_member(
|
||||||
@ -164,6 +165,42 @@ class ModLog(commands.Cog):
|
|||||||
|
|
||||||
await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
|
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.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def reason(self, ctx: commands.Context, case: Optional[int], *, reason: str):
|
async def reason(self, ctx: commands.Context, case: Optional[int], *, reason: str):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user