Make audit_type optional in casetypes (#1119)

This commit is contained in:
Tobotimus 2017-11-23 17:17:42 +11:00 committed by palmtree5
parent acbb5b1720
commit 2c96844209
2 changed files with 22 additions and 20 deletions

View File

@ -128,16 +128,17 @@ class ModLog:
bot_perms = guild.me.guild_permissions bot_perms = guild.me.guild_permissions
if bot_perms.view_audit_log: if bot_perms.view_audit_log:
case_type = await modlog.get_casetype(case_before.action_type, guild) case_type = await modlog.get_casetype(case_before.action_type, guild)
audit_type = getattr(discord.AuditLogAction, case_type.audit_type) if case_type is not None and case_type.audit_type is not None:
if audit_type: audit_type = getattr(discord.AuditLogAction, case_type.audit_type)
audit_case = None if audit_type:
async for entry in guild.audit_logs(action=audit_type): audit_case = None
if entry.target.id == case_before.user.id and \ async for entry in guild.audit_logs(action=audit_type):
entry.user.id == case_before.moderator.id: if entry.target.id == case_before.user.id and \
audit_case = entry entry.user.id == case_before.moderator.id:
break audit_case = entry
if audit_case: break
case_before.moderator = audit_case.user if audit_case:
case_before.moderator = audit_case.user
is_guild_owner = author == guild.owner is_guild_owner = author == guild.owner
is_case_author = author == case_before.moderator is_case_author = author == case_before.moderator
author_is_mod = await ctx.bot.is_mod(author) author_is_mod = await ctx.bot.is_mod(author)

View File

@ -223,13 +223,13 @@ class CaseType:
The emoji to use for the case type (for example, :boot:) The emoji to use for the case type (for example, :boot:)
case_str: str case_str: str
The string representation of the case (example: Ban) The string representation of the case (example: Ban)
audit_type: str audit_type: `str`, optional
The action type of the action as it would appear in the The action type of the action as it would appear in the
audit log audit log
""" """
def __init__( def __init__(
self, name: str, default_setting: bool, image: str, self, name: str, default_setting: bool, image: str,
case_str: str, audit_type: str, guild: discord.Guild = None): case_str: str, audit_type: str=None, guild: discord.Guild=None):
self.name = name self.name = name
self.default_setting = default_setting self.default_setting = default_setting
self.image = image self.image = image
@ -493,7 +493,7 @@ async def get_all_casetypes(guild: discord.Guild=None) -> List[CaseType]:
async def register_casetype( async def register_casetype(
name: str, default_setting: bool, name: str, default_setting: bool,
image: str, case_str: str, audit_type: str) -> CaseType: image: str, case_str: str, audit_type: str=None) -> CaseType:
""" """
Registers a case type. If the case type exists and Registers a case type. If the case type exists and
there are differences between the values passed and there are differences between the values passed and
@ -511,7 +511,7 @@ async def register_casetype(
The emoji to use for the case type (for example, :boot:) The emoji to use for the case type (for example, :boot:)
case_str: str case_str: str
The string representation of the case (example: Ban) The string representation of the case (example: Ban)
audit_type: str audit_type: `str`, optional
The action type of the action as it would appear in the The action type of the action as it would appear in the
audit log audit log
@ -540,12 +540,13 @@ async def register_casetype(
raise ValueError("The 'image' is not a string!") raise ValueError("The 'image' is not a string!")
if not isinstance(case_str, str): if not isinstance(case_str, str):
raise ValueError("The 'case_str' is not a string!") raise ValueError("The 'case_str' is not a string!")
if not isinstance(audit_type, str): if audit_type is not None:
raise ValueError("The 'audit_type' is not a string!") if not isinstance(audit_type, str):
try: raise ValueError("The 'audit_type' is not a string!")
getattr(discord.AuditLogAction, audit_type) try:
except AttributeError: getattr(discord.AuditLogAction, audit_type)
raise except AttributeError:
raise
ct = await get_casetype(name) ct = await get_casetype(name)
if ct is None: if ct is None:
casetype = CaseType(name, default_setting, image, case_str, audit_type) casetype = CaseType(name, default_setting, image, case_str, audit_type)