[V3 Modlog] add events for modlog cases (#1717)

* Give modlog case objects the bot as an attribute

* Dispatch modlog_case_create and modlog_case_edit events

* case.bot, not just bot

* fix a couple more issues resulting from refactor

* Case.edit doesn't need the bot parameter lol

* Make create_case return the case object (because tests)

* Modify create_case docstring

* Fix a docstring
This commit is contained in:
palmtree5
2018-05-27 21:18:50 -08:00
committed by GitHub
parent 6ae02d2d02
commit 05ad3fcd5c
3 changed files with 40 additions and 43 deletions

View File

@@ -1422,7 +1422,7 @@ class Mod:
)
else:
try:
case = await modlog.create_case(
await modlog.create_case(
self.bot,
guild,
message.created_at,
@@ -1515,6 +1515,34 @@ class Mod:
except RuntimeError as e:
print(e)
async def on_modlog_case_create(self, case: modlog.Case):
"""
An event for modlog case creation
"""
mod_channel = await modlog.get_modlog_channel(case.guild)
if mod_channel is None:
return
use_embeds = await case.bot.embed_requested(mod_channel, case.guild.me)
case_content = await case.message_content(use_embeds)
if use_embeds:
msg = await mod_channel.send(embed=case_content)
else:
msg = await mod_channel.send(case_content)
await case.edit({"message": msg})
async def on_modlog_case_edit(self, case: modlog.Case):
"""
Event for modlog case edits
"""
if not case.message:
return
use_embed = await case.bot.embed_requested(case.message.channel, case.guild.me)
case_content = await case.message_content(use_embed)
if use_embed:
await case.message.edit(embed=case_content)
else:
await case.message.edit(content=case_content)
async def get_audit_entry_info(self, guild: discord.Guild, action: int, target):
"""Get info about an audit log entry.

View File

@@ -146,5 +146,5 @@ class ModLog:
if case_before.moderator != author:
to_modify["amended_by"] = author
to_modify["modified_at"] = ctx.message.created_at.timestamp()
await case_before.edit(self.bot, to_modify)
await case_before.edit(to_modify)
await ctx.send(_("Reason has been updated."))