Refactor error handling for system commands

This commit is contained in:
Ske
2018-09-09 20:50:53 +02:00
parent a079db8be0
commit e95d8a4e0d
3 changed files with 41 additions and 24 deletions

View File

@@ -1,36 +1,57 @@
from typing import Tuple
class PluralKitError(Exception):
pass
def __init__(self, message):
self.message = message
self.help_page = None
def with_help(self, help_page: Tuple[str, str]):
self.help_page = help_page
class ExistingSystemError(PluralKitError):
pass
def __init__(self):
super().__init__("You already have a system registered. To delete your system, use `pk;system delete`, or to unlink your system from this account, use `pk;system unlink`.")
class DescriptionTooLongError(PluralKitError):
pass
def __init__(self):
super().__init__("You can't have a description longer than 1024 characters.")
class TagTooLongError(PluralKitError):
pass
def __init__(self):
super().__init__("You can't have a system tag longer than 32 characters.")
class TagTooLongWithMembersError(PluralKitError):
def __init__(self, member_names):
super().__init__("The maximum length of a name plus the system tag is 32 characters. The following members would exceed the limit: {}. Please reduce the length of the tag, or rename the members.".format(", ".join(member_names)))
self.member_names = member_names
class CustomEmojiError(PluralKitError):
pass
def __init__(self):
super().__init__("Due to a Discord limitation, custom emojis aren't supported. Please use a standard emoji instead.")
class InvalidAvatarURLError(PluralKitError):
pass
def __init__(self):
super().__init__("Invalid image URL.")
class AccountInOwnSystemError(PluralKitError):
def __init__(self):
super().__init__("That account is already linked to your own system.")
class AccountAlreadyLinkedError(PluralKitError):
def __init__(self, existing_system):
super().__init__("The mentioned account is already linked to a system (`{}`)".format(existing_system.hid))
self.existing_system = existing_system
class UnlinkingLastAccountError(PluralKitError):
pass
def __init__(self):
super().__init__("This is the only account on your system, so you can't unlink it.")