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,6 +128,7 @@ 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)
if case_type is not None and case_type.audit_type is not None:
audit_type = getattr(discord.AuditLogAction, case_type.audit_type) audit_type = getattr(discord.AuditLogAction, case_type.audit_type)
if audit_type: if audit_type:
audit_case = None audit_case = None

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,6 +540,7 @@ 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 audit_type is not None:
if not isinstance(audit_type, str): if not isinstance(audit_type, str):
raise ValueError("The 'audit_type' is not a string!") raise ValueError("The 'audit_type' is not a string!")
try: try: