schemas: add role_name and verification_level types

- schemas: also fix GUILD_UPDATE.icon and GUILD_CREATE.icon
This commit is contained in:
Luna Mendes 2018-10-26 04:15:51 -03:00
parent 856839d9e7
commit d2562d3262
1 changed files with 21 additions and 5 deletions

View File

@ -6,8 +6,10 @@ from logbook import Logger
from .errors import BadRequest from .errors import BadRequest
from .permissions import Permissions from .permissions import Permissions
from .enums import ActivityType, StatusType, ExplicitFilter, \ from .enums import (
RelationshipType, MessageNotifications, ChannelType ActivityType, StatusType, ExplicitFilter, RelationshipType,
MessageNotifications, ChannelType, VerificationLevel
)
log = Logger(__name__) log = Logger(__name__)
@ -26,6 +28,14 @@ EMOJO_MENTION = re.compile(r'<:(\.+):(\d+)>', re.A | re.M)
ANIMOJI_MENTION = re.compile(r'<a:(\.+):(\d+)>', re.A | re.M) ANIMOJI_MENTION = re.compile(r'<a:(\.+):(\d+)>', re.A | re.M)
def _in_enum(enum, value: int):
try:
enum(value)
return True
except ValueError:
return False
class LitecordValidator(Validator): class LitecordValidator(Validator):
def _validate_type_username(self, value: str) -> bool: def _validate_type_username(self, value: str) -> bool:
"""Validate against the username regex.""" """Validate against the username regex."""
@ -58,7 +68,10 @@ class LitecordValidator(Validator):
def _validate_type_voice_region(self, value: str) -> bool: def _validate_type_voice_region(self, value: str) -> bool:
# TODO: complete this list # TODO: complete this list
return value in ('brazil', 'us-east', 'us-west', 'us-south', 'russia') return value.lower() in ('brazil', 'us-east', 'us-west', 'us-south', 'russia')
def _validate_type_verification_level(self, value: int) -> bool:
return _in_enum(VerificationLevel, value)
def _validate_type_activity_type(self, value: int) -> bool: def _validate_type_activity_type(self, value: int) -> bool:
return value in ActivityType.values() return value in ActivityType.values()
@ -102,6 +115,9 @@ class LitecordValidator(Validator):
def _validate_type_guild_name(self, value: str) -> bool: def _validate_type_guild_name(self, value: str) -> bool:
return 2 <= len(value) <= 100 return 2 <= len(value) <= 100
def _validate_type_role_name(self, value: str) -> bool:
return 1 <= len(value) <= 100
def _validate_type_channel_name(self, value: str) -> bool: def _validate_type_channel_name(self, value: str) -> bool:
# for now, we'll use the same validation for guild_name # for now, we'll use the same validation for guild_name
return self._validate_type_guild_name(value) return self._validate_type_guild_name(value)
@ -193,7 +209,7 @@ PARTIAL_CHANNEL_GUILD_CREATE = {
GUILD_CREATE = { GUILD_CREATE = {
'name': {'type': 'guild_name'}, 'name': {'type': 'guild_name'},
'region': {'type': 'voice_region'}, 'region': {'type': 'voice_region'},
'icon': {'type': 'icon', 'required': False, 'nullable': True}, 'icon': {'type': 'b64_icon', 'required': False, 'nullable': True},
'verification_level': { 'verification_level': {
'type': 'verification_level', 'default': 0}, 'type': 'verification_level', 'default': 0},
@ -215,7 +231,7 @@ GUILD_UPDATE = {
'required': False 'required': False
}, },
'region': {'type': 'voice_region', 'required': False}, 'region': {'type': 'voice_region', 'required': False},
'icon': {'type': 'icon', 'required': False}, 'icon': {'type': 'b64_icon', 'required': False},
'verification_level': {'type': 'verification_level', 'required': False}, 'verification_level': {'type': 'verification_level', 'required': False},
'default_message_notifications': { 'default_message_notifications': {