From c325543242c932943d4b555c4737bbea1a49ab41 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 11 Mar 2019 01:40:18 -0300 Subject: [PATCH] enums: move Feature to EasyEnum - schemas: add validator for guild_features type --- litecord/enums.py | 8 ++++++-- litecord/schemas.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/litecord/enums.py b/litecord/enums.py index 0a7c075..52cd742 100644 --- a/litecord/enums.py +++ b/litecord/enums.py @@ -18,12 +18,16 @@ along with this program. If not, see . """ import inspect +from typing import List, Any from enum import Enum, IntEnum class EasyEnum(Enum): + """Wrapper around the enum class for convenience.""" + @classmethod - def values(cls): + def values(cls) -> List[Any]: + """Return list of values for the given enum.""" return [v.value for v in cls.__members__.values()] @@ -210,7 +214,7 @@ class PremiumType: NONE = None -class Feature(Enum): +class Feature(EasyEnum): """Guild features.""" invite_splash = 'INVITE_SPLASH' vip = 'VIP_REGIONS' diff --git a/litecord/schemas.py b/litecord/schemas.py index 40499da..54bed7c 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -28,7 +28,7 @@ from .permissions import Permissions from .types import Color from .enums import ( ActivityType, StatusType, ExplicitFilter, RelationshipType, - MessageNotifications, ChannelType, VerificationLevel + MessageNotifications, ChannelType, VerificationLevel, Features ) from litecord.embed.schemas import EMBED_OBJECT @@ -145,6 +145,9 @@ class LitecordValidator(Validator): def _validate_type_nickname(self, value: str) -> bool: return isinstance(value, str) and (len(value) < 32) + def _validate_type_guild_feature(self, value: str) -> bool: + return value in Features.values() + def validate(reqjson: Union[Dict, List], schema: Dict, raise_err: bool = True) -> Dict: