schemas: fix GW_ACTIVITY schema

- blueprints.guilds: use GUILD_CREATE schema
This commit is contained in:
Luna Mendes 2018-10-26 03:39:11 -03:00
parent aaa11be258
commit e8ebfe6eeb
2 changed files with 70 additions and 55 deletions

View File

@ -4,7 +4,7 @@ from ..auth import token_check
from ..snowflake import get_snowflake
from ..enums import ChannelType
from ..errors import Forbidden, GuildNotFound, BadRequest
from ..schemas import validate, GUILD_UPDATE
from ..schemas import validate, GUILD_CREATE, GUILD_UPDATE
from .channels import channel_ack
from .checks import guild_check
@ -160,7 +160,7 @@ async def create_guild():
the user creating it as the owner and
making them join."""
user_id = await token_check()
j = await request.get_json()
j = validate(await request.get_json(), GUILD_CREATE)
guild_id = get_snowflake()

View File

@ -32,7 +32,7 @@ class LitecordValidator(Validator):
return bool(USERNAME_REGEX.match(value))
def _validate_type_email(self, value: str) -> bool:
"""Validate against the username regex."""
"""Validate against the email regex."""
return bool(EMAIL_REGEX.match(value))
def _validate_type_b64_icon(self, value: str) -> bool:
@ -114,7 +114,13 @@ def validate(reqjson: Union[Dict, List], schema: Dict,
"""
validator = LitecordValidator(schema)
if not validator.validate(reqjson):
try:
valid = validator.validate(reqjson)
except Exception:
log.exception('Error while validating')
raise Exception(f'Error while validating: {reqjson}')
if not valid:
errs = validator.errors
log.warning('Error validating doc {!r}: {!r}', reqjson, errs)
@ -163,6 +169,8 @@ USER_UPDATE = {
}
PARTIAL_ROLE_GUILD_CREATE = {
'type': 'dict',
'schema': {
'name': {'type': 'role_name'},
'color': {'type': 'number', 'default': 0},
'hoist': {'type': 'boolean', 'default': False},
@ -172,10 +180,14 @@ PARTIAL_ROLE_GUILD_CREATE = {
'permissions': {'coerce': Permissions, 'required': False},
'mentionable': {'type': 'boolean', 'default': False},
}
}
PARTIAL_CHANNEL_GUILD_CREATE = {
'type': 'dict',
'schema': {
'name': {'type': 'channel_name'},
'type': {'type': 'channel_type'}
'type': {'type': 'channel_type'},
}
}
GUILD_CREATE = {
@ -244,6 +256,8 @@ MESSAGE_CREATE = {
GW_ACTIVITY = {
'type': 'dict',
'schema': {
'name': {'type': 'string', 'required': True},
'type': {'type': 'activity_type', 'required': True},
@ -254,7 +268,7 @@ GW_ACTIVITY = {
'required': False,
'schema': {
'start': {'type': 'number', 'required': True},
'end': {'type': 'number', 'required': True},
'end': {'type': 'number', 'required': False},
},
},
@ -296,6 +310,7 @@ GW_ACTIVITY = {
'instance': {'type': 'boolean', 'required': False},
'flags': {'type': 'number', 'required': False},
}
}
GW_STATUS_UPDATE = {
'status': {'type': 'status_external', 'required': False},