diff options
Diffstat (limited to 'pysite/views/api/bot')
-rw-r--r-- | pysite/views/api/bot/hiphopify.py | 42 | ||||
-rw-r--r-- | pysite/views/api/bot/tags.py | 37 |
2 files changed, 32 insertions, 47 deletions
diff --git a/pysite/views/api/bot/hiphopify.py b/pysite/views/api/bot/hiphopify.py index 50a811c6..3a47b64e 100644 --- a/pysite/views/api/bot/hiphopify.py +++ b/pysite/views/api/bot/hiphopify.py @@ -12,25 +12,19 @@ from pysite.utils.time import is_expired, parse_duration log = logging.getLogger(__name__) -GET_SCHEMA = Schema([ - { - "user_id": str - } -]) - -POST_SCHEMA = Schema([ - { - "user_id": str, - "duration": str, - Optional("forced_nick"): str - } -]) - -DELETE_SCHEMA = Schema([ - { - "user_id": str - } -]) +GET_SCHEMA = Schema({ + "user_id": str +}) + +POST_SCHEMA = Schema({ + "user_id": str, + "duration": str, + Optional("forced_nick"): str +}) + +DELETE_SCHEMA = Schema({ + "user_id": str +}) class HiphopifyView(APIView, DBMixin): @@ -55,7 +49,7 @@ class HiphopifyView(APIView, DBMixin): API key must be provided as header. """ - user_id = params[0].get("user_id") + user_id = params.get("user_id") log.debug(f"Checking if user ({user_id}) is permitted to change their nickname.") data = self.db.get(self.prison_table, user_id) or {} @@ -83,9 +77,9 @@ class HiphopifyView(APIView, DBMixin): API key must be provided as header. """ - user_id = json_data[0].get("user_id") - duration = json_data[0].get("duration") - forced_nick = json_data[0].get("forced_nick") + user_id = json_data.get("user_id") + duration = json_data.get("duration") + forced_nick = json_data.get("forced_nick") log.debug(f"Attempting to imprison user ({user_id}).") @@ -146,7 +140,7 @@ class HiphopifyView(APIView, DBMixin): API key must be provided as header. """ - user_id = json_data[0].get("user_id") + user_id = json_data.get("user_id") log.debug(f"Attempting to release user ({user_id}) from hiphop-prison.") prisoner_data = self.db.get(self.prison_table, user_id) diff --git a/pysite/views/api/bot/tags.py b/pysite/views/api/bot/tags.py index 7fdaee3c..4394c224 100644 --- a/pysite/views/api/bot/tags.py +++ b/pysite/views/api/bot/tags.py @@ -6,24 +6,18 @@ from pysite.constants import ValidationTypes from pysite.decorators import api_key, api_params from pysite.mixins import DBMixin -GET_SCHEMA = Schema([ - { - Optional("tag_name"): str - } -]) - -POST_SCHEMA = Schema([ - { - "tag_name": str, - "tag_content": str - } -]) - -DELETE_SCHEMA = Schema([ - { - "tag_name": str - } -]) +GET_SCHEMA = Schema({ + Optional("tag_name"): str +}) + +POST_SCHEMA = Schema({ + "tag_name": str, + "tag_content": str +}) + +DELETE_SCHEMA = Schema({ + "tag_name": str +}) class TagsView(APIView, DBMixin): @@ -53,7 +47,7 @@ class TagsView(APIView, DBMixin): tag_name = None if params: - tag_name = params[0].get("tag_name") + tag_name = params.get("tag_name") if tag_name: data = self.db.get(self.table_name, tag_name) or {} @@ -76,8 +70,6 @@ class TagsView(APIView, DBMixin): API key must be provided as header. """ - json_data = json_data[0] - tag_name = json_data.get("tag_name") tag_content = json_data.get("tag_content") @@ -102,8 +94,7 @@ class TagsView(APIView, DBMixin): API key must be provided as header. """ - json = data[0] - tag_name = json.get("tag_name") + tag_name = data.get("tag_name") tag_exists = self.db.get(self.table_name, tag_name) if tag_exists: |