enums: add MessageNotifications

- schemas: add msg_notifications type validator
 - schemas: add GUILD_SETTINGS, GUILD_SETTINGS_CHAN_OVERRIDE
This commit is contained in:
Luna Mendes 2018-10-19 04:31:20 -03:00
parent b1a362418c
commit 25b34c6a8a
2 changed files with 44 additions and 1 deletions

View File

@ -157,3 +157,9 @@ class RelationshipType(EasyEnum):
BLOCK = 2 BLOCK = 2
INCOMING = 3 INCOMING = 3
OUTGOING = 4 OUTGOING = 4
class MessageNotifications(EasyEnum):
ALL = 0
MENTIONS = 1
NOTHING = 2

View File

@ -4,7 +4,8 @@ from cerberus import Validator
from logbook import Logger from logbook import Logger
from .errors import BadRequest from .errors import BadRequest
from .enums import ActivityType, StatusType, ExplicitFilter, RelationshipType from .enums import ActivityType, StatusType, ExplicitFilter, \
RelationshipType, MessageNotifications
log = Logger(__name__) log = Logger(__name__)
@ -85,6 +86,14 @@ class LitecordValidator(Validator):
return val in (RelationshipType.FRIEND.value, return val in (RelationshipType.FRIEND.value,
RelationshipType.BLOCK.value) RelationshipType.BLOCK.value)
def _validate_type_msg_notifications(self, value: str):
try:
val = int(value)
except (TypeError, ValueError):
return False
return val in MessageNotifications.values()
def validate(reqjson, schema, raise_err: bool = True): def validate(reqjson, schema, raise_err: bool = True):
validator = LitecordValidator(schema) validator = LitecordValidator(schema)
@ -355,3 +364,31 @@ SPECIFIC_FRIEND = {
'username': {'type': 'username'}, 'username': {'type': 'username'},
'discriminator': {'type': 'discriminator'} 'discriminator': {'type': 'discriminator'}
} }
GUILD_SETTINGS_CHAN_OVERRIDE = {
'muted': {
'type': 'bool', 'required': False},
'message_notifications': {
'type': 'msg_notifications',
'required': False,
}
}
GUILD_SETTINGS = {
'channel_overrides': {
'type': 'dict',
'schema': GUILD_SETTINGS_CHAN_OVERRIDE,
'keyschema': {'type': 'snowflake'},
'required': False,
},
'supress_everyone': {
'type': 'bool', 'required': False},
'muted': {
'type': 'bool', 'required': False},
'mobile_push': {
'type': 'bool', 'required': False},
'message_notifications': {
'type': 'msg_notifications',
'required': False,
}
}