blob: 0f9098d940e1fc63e1711e603e6f0554e7615551 (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File : __init__.py
@Time : 2020/10/11 14:40:55
@Author : Kyomotoi
@Contact : [email protected]
@Github : https://github.com/Kyomotoi
@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
'''
__author__ = 'kyomotoi'
import psutil
import sqlite3
from pathlib import Path
from nonebot.plugin import on_command
from nonebot.typing import Bot, Event
from ATRI.utils.utils_error import errorRepo
from ATRI.utils.utils_rule import check_banlist
status_info = on_command('status', rule=check_banlist())
@status_info.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
msg = str(event.message).strip()
if msg:
pass
else:
msg0 = "States parameter:\n"
msg0 += "├info\n"
msg0 += "└sqlite\n"
msg0 += "* DEMO: status info"
await status_info.finish(msg0)
if msg == "info":
try:
cpu = psutil.cpu_percent(interval=1)
memory = psutil.virtual_memory().percent
disk = psutil.disk_usage('/').percent
inteSENT = psutil.net_io_counters().bytes_sent # type: ignore
inteRECV = psutil.net_io_counters().bytes_recv # type: ignore
except:
await status_info.finish(errorRepo("读取系统状态失败"))
status = "アトリは、高性能ですから!"
if cpu > 80: # type: ignore
status = 'ATRI感觉头有点晕...'
if memory > 80: # type: ignore
status = 'ATRI感觉有点头晕并且有点累...'
elif disk > 80: # type: ignore
status = 'ATRI感觉身体要被塞满了...'
msg0 = "ATRI status-info:\n"
msg0 += f"* CPU: {cpu}%\n" # type: ignore
msg0 += f"* MEM: {memory}%\n" # type: ignore
msg0 += f"* Disk {disk}%\n" # type: ignore
msg0 += f"* BytesSENT: {inteSENT}\n" # type: ignore
msg0 += f"* BytesRECV: {inteRECV}\n" # type: ignore
msg0 += status
await status_info.finish(msg0)
elif msg == "sqlite":
con = sqlite3.connect(
Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' /
'normal.db') # setu-normal
cur = con.cursor()
cur.execute("select * from normal")
data_normal = len(cur.fetchall())
con.close()
con = sqlite3.connect(
Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' /
'nearR18.db') # setu-nearR18
cur = con.cursor()
cur.execute("select * from nearR18")
data_nearR18 = len(cur.fetchall())
con.close()
con = sqlite3.connect(
Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' /
'r18.db') # setu-r18
cur = con.cursor()
cur.execute("select * from r18")
data_r18 = len(cur.fetchall())
con.close()
msg0 = "ATRI status-sqlite:\n"
msg0 += "Setu:\n"
msg0 += f"├normal: {data_normal}\n"
msg0 += f"├nearR18: {data_nearR18}\n"
msg0 += f"└R18: {data_r18}"
await status_info.finish(msg0)
|