adds function to modlg API to get cases by member (#2453)

adds command using this to view all of a member's cases demonstrating this

closes #2266
This commit is contained in:
DiscordLiz
2019-02-21 21:31:37 -05:00
committed by Kowlin
parent 77a0a67029
commit 9966668307
2 changed files with 121 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Union
import discord
@@ -6,6 +6,8 @@ from redbot.core import checks, modlog, commands
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.menus import menu, DEFAULT_CONTROLS
_ = Translator("ModLog", __file__)
@@ -105,6 +107,37 @@ class ModLog(commands.Cog):
else:
await ctx.send(await case.message_content(embed=False))
@commands.command()
@commands.guild_only()
async def casesfor(self, ctx: commands.Context, member: Union[discord.Member, int]):
"""
Displays the cases for the specified member
"""
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."))
embed_requested = await ctx.embed_requested()
rendered_cases = [await case.message_content(embed=embed_requested) for case in cases]
await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
@commands.command()
@commands.guild_only()
async def reason(self, ctx: commands.Context, case: Optional[int], *, reason: str):