[Modlog] Make the case number optional in [p]reason (#1979)

* [V3 Modlog] Make the case number optional

If not specified, it will be the latest case.

* Fix some errors

* Black reformat

* More info for usage string

* Use isdigit instead of isnumeric
This commit is contained in:
El Laggron 2018-08-11 03:44:17 +02:00 committed by Toby Harradine
parent 51a54863c5
commit 2a396b4438

View File

@ -97,17 +97,24 @@ class ModLog:
else:
await ctx.send(embed=await case.get_case_msg_content())
@commands.command()
@commands.command(usage="[case] <reason>")
@commands.guild_only()
async def reason(self, ctx: commands.Context, case: int, *, reason: str = ""):
async def reason(self, ctx: commands.Context, *, reason: str):
"""Lets you specify a reason for mod-log's cases
Please note that you can only edit cases you are
the owner of unless you are a mod/admin or the server owner"""
the owner of unless you are a mod/admin or the server owner.
If no number is specified, the latest case will be used."""
author = ctx.author
guild = ctx.guild
if not reason:
await ctx.send_help()
return
potential_case = reason.split()[0]
if potential_case.isdigit():
case = int(potential_case)
reason = reason.replace(potential_case, "")
else:
case = str(int(await modlog.get_next_case_number(guild)) - 1)
# latest case
try:
case_before = await modlog.get_case(case, guild, self.bot)
except RuntimeError: