From 25b34c6a8a5f2c1cc1505d08463e599c117644a5 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Fri, 19 Oct 2018 04:31:20 -0300 Subject: [PATCH] enums: add MessageNotifications - schemas: add msg_notifications type validator - schemas: add GUILD_SETTINGS, GUILD_SETTINGS_CHAN_OVERRIDE --- litecord/enums.py | 6 ++++++ litecord/schemas.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/litecord/enums.py b/litecord/enums.py index a408944..1c2a920 100644 --- a/litecord/enums.py +++ b/litecord/enums.py @@ -157,3 +157,9 @@ class RelationshipType(EasyEnum): BLOCK = 2 INCOMING = 3 OUTGOING = 4 + + +class MessageNotifications(EasyEnum): + ALL = 0 + MENTIONS = 1 + NOTHING = 2 diff --git a/litecord/schemas.py b/litecord/schemas.py index 556b84a..2c6687e 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -4,7 +4,8 @@ from cerberus import Validator from logbook import Logger from .errors import BadRequest -from .enums import ActivityType, StatusType, ExplicitFilter, RelationshipType +from .enums import ActivityType, StatusType, ExplicitFilter, \ + RelationshipType, MessageNotifications log = Logger(__name__) @@ -85,6 +86,14 @@ class LitecordValidator(Validator): return val in (RelationshipType.FRIEND.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): validator = LitecordValidator(schema) @@ -355,3 +364,31 @@ SPECIFIC_FRIEND = { 'username': {'type': 'username'}, '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, + } +}