summaryrefslogtreecommitdiff
path: root/ATRI/plugins/console
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/console')
-rw-r--r--ATRI/plugins/console/__init__.py10
-rw-r--r--ATRI/plugins/console/data_source.py13
-rw-r--r--ATRI/plugins/console/drivers.py18
-rw-r--r--ATRI/plugins/console/view.py15
4 files changed, 22 insertions, 34 deletions
diff --git a/ATRI/plugins/console/__init__.py b/ATRI/plugins/console/__init__.py
index 60cc305..d7240c9 100644
--- a/ATRI/plugins/console/__init__.py
+++ b/ATRI/plugins/console/__init__.py
@@ -32,6 +32,7 @@ error_freq = 0
record_msg = Console().on_message(block=False)
+
@record_msg.handle()
async def _record_msg(bot: Bot, event: Event):
global msg_freq
@@ -44,7 +45,7 @@ async def _record_is_error(
exception: Optional[Exception],
bot: Bot,
event: Event,
- state: T_State
+ state: T_State,
):
global health_freq, error_freq
if matcher.type != "message":
@@ -60,11 +61,7 @@ async def _record_data():
now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
data = {
"time": now_time,
- "freq_data": {
- "msg": msg_freq,
- "health": health_freq,
- "error": error_freq
- }
+ "freq_data": {"msg": msg_freq, "health": health_freq, "error": error_freq},
}
Console().record_data(data)
msg_freq, health_freq, error_freq = 0, 0, 0
@@ -73,4 +70,5 @@ async def _record_data():
def init():
register_route()
+
init()
diff --git a/ATRI/plugins/console/data_source.py b/ATRI/plugins/console/data_source.py
index 8fe6c04..990b1c9 100644
--- a/ATRI/plugins/console/data_source.py
+++ b/ATRI/plugins/console/data_source.py
@@ -14,25 +14,24 @@ is_connect = False
class Console(Service):
-
def __init__(self):
Service.__init__(self, "控制台")
-
+
@staticmethod
def record_data(data: dict) -> None:
now_time = datetime.now().strftime("%Y-%m-%d")
file_name = f"{now_time}-runtime.json"
path = CONSOLE_DIR / file_name
if not path.is_file():
- with open(path ,"w", encoding="utf-8") as w:
+ with open(path, "w", encoding="utf-8") as w:
w.write(json.dumps(list()))
temp_data = list()
-
+
temp_data: list = json.loads(path.read_bytes())
temp_data.append(data)
with open(path, "w", encoding="utf-8") as w:
w.write(json.dumps(temp_data, indent=4))
-
+
@staticmethod
def load_data() -> list:
now_time = datetime.now().strftime("%Y-%m-%d")
@@ -42,7 +41,7 @@ class Console(Service):
with open(path, "w", encoding="utf-8") as w:
w.write(json.dumps(list()))
return list()
-
+
data: list = json.loads(path.read_bytes())
return data
@@ -50,7 +49,7 @@ class Console(Service):
def store_connect_stat(i: bool):
global is_connect
is_connect = i
-
+
@staticmethod
def is_connect() -> bool:
return is_connect
diff --git a/ATRI/plugins/console/drivers.py b/ATRI/plugins/console/drivers.py
index e691a7c..55157cd 100644
--- a/ATRI/plugins/console/drivers.py
+++ b/ATRI/plugins/console/drivers.py
@@ -12,7 +12,7 @@ origins = [
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8080",
- "http://localhost:20000"
+ "http://localhost:20000",
]
@@ -23,15 +23,15 @@ def register_route():
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
- allow_headers=["*"]
+ allow_headers=["*"],
)
-
- static_path = str((Path(".") / "ATRI" / "plugins" / "console" / "atri-manege" / "dist").absolute())
-
+
+ static_path = str(
+ (Path(".") / "ATRI" / "plugins" / "console" / "atri-manege" / "dist").absolute()
+ )
+
app.get("/bot/is_connect")(handle_is_connect)
app.get("/bot/status")(handle_status)
app.get("/bot/dashboard_info")(handle_dashboard_info)
-
- app.mount("/",
- StaticFiles(directory=static_path, html=True),
- name="bot")
+
+ app.mount("/", StaticFiles(directory=static_path, html=True), name="bot")
diff --git a/ATRI/plugins/console/view.py b/ATRI/plugins/console/view.py
index dde3533..9de39b4 100644
--- a/ATRI/plugins/console/view.py
+++ b/ATRI/plugins/console/view.py
@@ -8,22 +8,13 @@ driver = ATRI.driver()
async def handle_is_connect():
data = Console().is_connect()
- return {
- "status": 200,
- "is_connect": data
- }
+ return {"status": 200, "is_connect": data}
async def handle_status():
- return {
- "status": 200,
- "message": info_msg
- }
+ return {"status": 200, "message": info_msg}
async def handle_dashboard_info():
data = Console().load_data()
- return {
- "status": 200,
- "data": data
- }
+ return {"status": 200, "data": data}