[Mod] [p]reason: Better error handling for case messages

Fixes #665
This commit is contained in:
Twentysix 2017-03-24 03:03:14 +01:00
parent bc68ad21c5
commit 25dfefce4d

View File

@ -59,6 +59,10 @@ class NoModLogChannel(ModError):
pass pass
class NoModLogAccess(ModError):
pass
class TempCache: class TempCache:
""" """
This is how we avoid events such as ban and unban This is how we avoid events such as ban and unban
@ -994,7 +998,10 @@ class Mod:
except NoModLogChannel: except NoModLogChannel:
await self.bot.say("There's no mod-log channel set.") await self.bot.say("There's no mod-log channel set.")
except CaseMessageNotFound: except CaseMessageNotFound:
await self.bot.say("Couldn't find the case's message.") await self.bot.say("I couldn't find the case's message.")
except NoModLogAccess:
await self.bot.say("I'm not allowed to access the mod-log "
"channel (or its message history)")
else: else:
await self.bot.say("Case #{} updated.".format(case)) await self.bot.say("Case #{} updated.".format(case))
@ -1461,12 +1468,19 @@ class Mod:
dataIO.save_json("data/mod/modlog.json", self.cases) dataIO.save_json("data/mod/modlog.json", self.cases)
msg = await self.bot.get_message(channel, case["message"]) if case["message"] is None: # The case's message was never sent
if msg:
await self.bot.edit_message(msg, case_msg)
else:
raise CaseMessageNotFound() raise CaseMessageNotFound()
try:
msg = await self.bot.get_message(channel, case["message"])
except discord.NotFound:
raise CaseMessageNotFound()
except discord.Forbidden:
raise NoModLogAccess()
else:
await self.bot.edit_message(msg, case_msg)
def format_case_msg(self, case): def format_case_msg(self, case):
tmp = case.copy() tmp = case.copy()
if case["reason"] is None: if case["reason"] is None: