mirror of https://gitlab.com/litecord/litecord.git
schemas: fix GW_ACTIVITY schema
- blueprints.guilds: use GUILD_CREATE schema
This commit is contained in:
parent
aaa11be258
commit
e8ebfe6eeb
|
|
@ -4,7 +4,7 @@ from ..auth import token_check
|
||||||
from ..snowflake import get_snowflake
|
from ..snowflake import get_snowflake
|
||||||
from ..enums import ChannelType
|
from ..enums import ChannelType
|
||||||
from ..errors import Forbidden, GuildNotFound, BadRequest
|
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 .channels import channel_ack
|
||||||
from .checks import guild_check
|
from .checks import guild_check
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ async def create_guild():
|
||||||
the user creating it as the owner and
|
the user creating it as the owner and
|
||||||
making them join."""
|
making them join."""
|
||||||
user_id = await token_check()
|
user_id = await token_check()
|
||||||
j = await request.get_json()
|
j = validate(await request.get_json(), GUILD_CREATE)
|
||||||
|
|
||||||
guild_id = get_snowflake()
|
guild_id = get_snowflake()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class LitecordValidator(Validator):
|
||||||
return bool(USERNAME_REGEX.match(value))
|
return bool(USERNAME_REGEX.match(value))
|
||||||
|
|
||||||
def _validate_type_email(self, value: str) -> bool:
|
def _validate_type_email(self, value: str) -> bool:
|
||||||
"""Validate against the username regex."""
|
"""Validate against the email regex."""
|
||||||
return bool(EMAIL_REGEX.match(value))
|
return bool(EMAIL_REGEX.match(value))
|
||||||
|
|
||||||
def _validate_type_b64_icon(self, value: str) -> bool:
|
def _validate_type_b64_icon(self, value: str) -> bool:
|
||||||
|
|
@ -114,7 +114,13 @@ def validate(reqjson: Union[Dict, List], schema: Dict,
|
||||||
"""
|
"""
|
||||||
validator = LitecordValidator(schema)
|
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
|
errs = validator.errors
|
||||||
log.warning('Error validating doc {!r}: {!r}', reqjson, errs)
|
log.warning('Error validating doc {!r}: {!r}', reqjson, errs)
|
||||||
|
|
||||||
|
|
@ -163,6 +169,8 @@ USER_UPDATE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
PARTIAL_ROLE_GUILD_CREATE = {
|
PARTIAL_ROLE_GUILD_CREATE = {
|
||||||
|
'type': 'dict',
|
||||||
|
'schema': {
|
||||||
'name': {'type': 'role_name'},
|
'name': {'type': 'role_name'},
|
||||||
'color': {'type': 'number', 'default': 0},
|
'color': {'type': 'number', 'default': 0},
|
||||||
'hoist': {'type': 'boolean', 'default': False},
|
'hoist': {'type': 'boolean', 'default': False},
|
||||||
|
|
@ -172,10 +180,14 @@ PARTIAL_ROLE_GUILD_CREATE = {
|
||||||
'permissions': {'coerce': Permissions, 'required': False},
|
'permissions': {'coerce': Permissions, 'required': False},
|
||||||
'mentionable': {'type': 'boolean', 'default': False},
|
'mentionable': {'type': 'boolean', 'default': False},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PARTIAL_CHANNEL_GUILD_CREATE = {
|
PARTIAL_CHANNEL_GUILD_CREATE = {
|
||||||
|
'type': 'dict',
|
||||||
|
'schema': {
|
||||||
'name': {'type': 'channel_name'},
|
'name': {'type': 'channel_name'},
|
||||||
'type': {'type': 'channel_type'}
|
'type': {'type': 'channel_type'},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILD_CREATE = {
|
GUILD_CREATE = {
|
||||||
|
|
@ -244,6 +256,8 @@ MESSAGE_CREATE = {
|
||||||
|
|
||||||
|
|
||||||
GW_ACTIVITY = {
|
GW_ACTIVITY = {
|
||||||
|
'type': 'dict',
|
||||||
|
'schema': {
|
||||||
'name': {'type': 'string', 'required': True},
|
'name': {'type': 'string', 'required': True},
|
||||||
'type': {'type': 'activity_type', 'required': True},
|
'type': {'type': 'activity_type', 'required': True},
|
||||||
|
|
||||||
|
|
@ -254,7 +268,7 @@ GW_ACTIVITY = {
|
||||||
'required': False,
|
'required': False,
|
||||||
'schema': {
|
'schema': {
|
||||||
'start': {'type': 'number', 'required': True},
|
'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},
|
'instance': {'type': 'boolean', 'required': False},
|
||||||
'flags': {'type': 'number', 'required': False},
|
'flags': {'type': 'number', 'required': False},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GW_STATUS_UPDATE = {
|
GW_STATUS_UPDATE = {
|
||||||
'status': {'type': 'status_external', 'required': False},
|
'status': {'type': 'status_external', 'required': False},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue