[ModLog API] Add default casetypes, remove need for a specific auditlog action (#2901)

* I know this needs a changelog entry and docs still

* update tests for new behavior

* update docs, filter; add changelog

* Ready for review

* stop fetching the same Audit logs when the bot is the mod

* I forgot to press save

* fix a comprehension

* Fix AttributeError

* And the other place that happens

* timing fixes
This commit is contained in:
DiscordLiz
2019-07-27 15:37:29 -04:00
committed by Michael H
parent 6280fd9c28
commit 20091cc10a
16 changed files with 251 additions and 214 deletions

View File

@@ -94,77 +94,6 @@ class Events(MixinMeta):
if not deleted:
await self.check_mention_spam(message)
@commands.Cog.listener()
async def on_member_ban(self, guild: discord.Guild, member: discord.Member):
if (guild.id, member.id) in self.ban_queue:
self.ban_queue.remove((guild.id, member.id))
return
try:
await modlog.get_modlog_channel(guild)
except RuntimeError:
return # No modlog channel so no point in continuing
mod, reason, date = await self.get_audit_entry_info(
guild, discord.AuditLogAction.ban, member
)
if date is None:
date = datetime.now()
try:
await modlog.create_case(
self.bot, guild, date, "ban", member, mod, reason if reason else None
)
except RuntimeError as e:
print(e)
@commands.Cog.listener()
async def on_member_unban(self, guild: discord.Guild, user: discord.User):
if (guild.id, user.id) in self.unban_queue:
self.unban_queue.remove((guild.id, user.id))
return
try:
await modlog.get_modlog_channel(guild)
except RuntimeError:
return # No modlog channel so no point in continuing
mod, reason, date = await self.get_audit_entry_info(
guild, discord.AuditLogAction.unban, user
)
if date is None:
date = datetime.now()
try:
await modlog.create_case(self.bot, guild, date, "unban", user, mod, reason)
except RuntimeError as e:
print(e)
@commands.Cog.listener()
async def on_modlog_case_create(self, case: modlog.Case):
"""
An event for modlog case creation
"""
try:
mod_channel = await modlog.get_modlog_channel(case.guild)
except RuntimeError:
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})
@commands.Cog.listener()
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)
@commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member):
if before.name != after.name: