From d8dde99fb3a6f742488aee09c20bec7b9f4a3a1b Mon Sep 17 00:00:00 2001 From: Kyomotoi Date: Sat, 14 May 2022 00:02:20 +0800 Subject: =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=8E=A7=E5=88=B6=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/console/driver/view.py | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 ATRI/plugins/console/driver/view.py (limited to 'ATRI/plugins/console/driver/view.py') diff --git a/ATRI/plugins/console/driver/view.py b/ATRI/plugins/console/driver/view.py new file mode 100644 index 0000000..624e41f --- /dev/null +++ b/ATRI/plugins/console/driver/view.py @@ -0,0 +1,101 @@ +from ..data_source import Console +from ..listener import get_message_deal_info +from .api import ( + control_service, + edit_block_list, + get_block_list, + get_processing_data, + get_service_list, +) + + +def auth_token(token: str) -> tuple: + auth_data: dict = Console().get_auth_info() + if not auth_data.get("token", None): + return False, {"status": 500, "msg": "This bot is not create auth data yet."} + _token = auth_data["token"] + if token != _token: + return False, {"status": 403, "msg": "Token error, please check again."} + else: + return True, {"status": 200, "msg": "OK"} + + +def handle_base_uri(): + return {"status": 204, "msg": "This path just for console load."} + + +def handle_auther(token: str): + auth, data = auth_token(token) + return data if auth else data + + +def handle_runtime_info(token: str): + auth, data = auth_token(token) + if not auth: + return data + + plat, bot = get_processing_data() + return {"status": 200, "data": {"platform": plat, "bot": bot}} + + +def handle_message_deal_info(token: str): + auth, data = auth_token(token) + if not auth: + return data + + return {"status": 200, "data": get_message_deal_info()} + + +def handle_get_service_list(token: str): + auth, data = auth_token(token) + if not auth: + return data + + return {"status": 200, "data": get_service_list()} + + +def handle_control_service( + token: str, + service: str, + is_enabled: int = 1, + enabled_user: str = str(), + enabled_group: str = str(), + disable_user: str = str(), + disable_group: str = str(), +): + auth, data = auth_token(token) + if not auth: + return data + + is_ok, data = control_service( + service, is_enabled, enabled_user, enabled_group, disable_user, disable_group + ) + if not is_ok: + return {"status": 422, "msg": "Dealing service data failed"} + + return {"status": 200, "data": data} + + +def handle_get_block_list(token: str): + auth, data = auth_token(token) + if not auth: + return data + + return {"status": 200, "data": get_block_list()} + + +def handle_edit_block( + token: str, + is_enabled: bool, + user_id: str = str(), + group_id: str = str(), +): + auth, data = auth_token(token) + if not auth: + return data + + is_ok, data = edit_block_list(is_enabled, user_id, group_id) + if not is_ok: + return {"status": 422, "msg": "Dealing block data failed"} + + return {"status": 200, "data": data} -- cgit v1.2.3