summaryrefslogtreecommitdiff
path: root/ATRI/plugins/status/driver/view.py
blob: 5d8c56f99ee058cebcc941764dd78fd180861656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from ..data_source import Status
from ..listener import get_message_deal_info


def handle_base_uri():
    return {"status": 204, "msg": "This path just for console load."}


def handle_runtime_info(token: str):
    auth, data = auth_token(token)
    plat, bot = Status().get_status(True)
    if auth:
        return {"status": 200, "data": {"platform": plat, "bot": bot}}
    else:
        return data


def handle_message_deal_info(token: str):
    auth, data = auth_token(token)
    if auth:
        return {"status": 200, "data": get_message_deal_info()}
    else:
        return data


def handle_auther(token: str):
    auth, data = auth_token(token)
    return data if auth else data


def auth_token(token: str) -> tuple:
    auth_data: dict = Status().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"}