[Mod] Default [p]reason to last case assigned if case # is not specified

This commit is contained in:
Twentysix 2016-10-17 05:14:17 +02:00
parent a7200b0e44
commit dbc7f04d25

View File

@ -48,6 +48,7 @@ class Mod:
self.cache = defaultdict(lambda: deque(maxlen=3)) self.cache = defaultdict(lambda: deque(maxlen=3))
self.cases = dataIO.load_json("data/mod/modlog.json") self.cases = dataIO.load_json("data/mod/modlog.json")
self._tmp_banned_cache = [] self._tmp_banned_cache = []
self.last_case = defaultdict(lambda: dict())
@commands.group(pass_context=True, no_pm=True) @commands.group(pass_context=True, no_pm=True)
@checks.serverowner_or_permissions(administrator=True) @checks.serverowner_or_permissions(administrator=True)
@ -434,11 +435,26 @@ class Mod:
@commands.command(pass_context=True) @commands.command(pass_context=True)
@checks.mod_or_permissions(manage_messages=True) @checks.mod_or_permissions(manage_messages=True)
async def reason(self, ctx, case : int, *, reason : str): async def reason(self, ctx, case, *, reason : str=""):
"""Lets you specify a reason for mod-log's cases""" """Lets you specify a reason for mod-log's cases
Defaults to last case assigned to yourself, if available."""
author = ctx.message.author author = ctx.message.author
server = author.server server = author.server
case = str(case) try:
case = int(case)
if not reason:
await send_cmd_help(ctx)
return
except:
if reason:
reason = "{} {}".format(case, reason)
else:
reason = case
case = self.last_case[server.id].get(author.id, None)
if case is None:
await send_cmd_help(ctx)
return
try: try:
await self.update_case(server, case=case, mod=author, await self.update_case(server, case=case, mod=author,
reason=reason) reason=reason)
@ -451,7 +467,7 @@ class Mod:
except CaseMessageNotFound: except CaseMessageNotFound:
await self.bot.say("Couldn't find the case's message.") await self.bot.say("Couldn't find the case's message.")
else: else:
await self.bot.say("Case updated.") await self.bot.say("Case #{} updated.".format(case))
@commands.group(pass_context=True) @commands.group(pass_context=True)
@ -837,6 +853,9 @@ class Mod:
self.cases[server.id][str(case_n)] = case self.cases[server.id][str(case_n)] = case
if mod:
self.last_case[server.id][mod.id] = case_n
dataIO.save_json("data/mod/modlog.json", self.cases) dataIO.save_json("data/mod/modlog.json", self.cases)
async def update_case(self, server, *, case, mod, reason): async def update_case(self, server, *, case, mod, reason):