summaryrefslogtreecommitdiff
path: root/ATRI/plugins/status.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/status.py')
-rw-r--r--ATRI/plugins/status.py46
1 files changed, 17 insertions, 29 deletions
diff --git a/ATRI/plugins/status.py b/ATRI/plugins/status.py
index 5e48fc3..bd5d9c4 100644
--- a/ATRI/plugins/status.py
+++ b/ATRI/plugins/status.py
@@ -16,10 +16,8 @@ __doc__ = """
/ping
"""
-ping = sv.on_command(
- cmd="/ping",
- docs="测试机器人",
- rule=is_in_service('ping'))
+ping = sv.on_command(cmd="/ping", docs="测试机器人", rule=is_in_service("ping"))
+
@ping.handle()
async def _ping(bot: Bot, event: MessageEvent) -> None:
@@ -33,11 +31,8 @@ __doc__ = """
/status
"""
-status = sv.on_command(
- cmd="/status",
- docs=__doc__,
- rule=is_in_service('status')
-)
+status = sv.on_command(cmd="/status", docs=__doc__, rule=is_in_service("status"))
+
@status.handle()
async def _status(bot: Bot, event: MessageEvent) -> None:
@@ -45,13 +40,13 @@ async def _status(bot: Bot, event: MessageEvent) -> None:
cpu = psutil.cpu_percent(interval=1)
mem = psutil.virtual_memory().percent
disk = psutil.disk_usage("/").percent
- inteSENT = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore
- inteRECV = psutil.net_io_counters().bytes_recv / 1000000 # type: ignore
+ inteSENT = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore
+ inteRECV = psutil.net_io_counters().bytes_recv / 1000000 # type: ignore
except GetStatusError:
raise GetStatusError("Failed to get status.")
-
+
msg = "アトリは、高性能ですから!"
-
+
if cpu > 80: # type: ignore
msg = "咱感觉有些头晕..."
if mem > 80:
@@ -60,7 +55,7 @@ async def _status(bot: Bot, event: MessageEvent) -> None:
msg = "咱感觉有点累..."
elif disk > 80:
msg = "咱感觉身体要被塞满了..."
-
+
msg0 = (
"Self status:\n"
f"* CPU: {cpu}%\n"
@@ -69,26 +64,22 @@ async def _status(bot: Bot, event: MessageEvent) -> None:
f"* netSENT: {inteSENT}MB\n"
f"* netRECV: {inteRECV}MB\n"
) + msg
-
+
await status.finish(msg0)
- 'interval',
- minutes=5,
- misfire_grace_time=10
-)
[email protected]_job("interval", minutes=5, misfire_grace_time=10)
async def _():
log.info("开始自检")
try:
cpu = psutil.cpu_percent(interval=1)
mem = psutil.virtual_memory().percent
disk = psutil.disk_usage("/").percent
- inteSENT = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore
- inteRECV = psutil.net_io_counters().bytes_recv / 1000000 # type: ignore
+ inteSENT = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore
+ inteRECV = psutil.net_io_counters().bytes_recv / 1000000 # type: ignore
except GetStatusError:
raise GetStatusError("Failed to get status.")
-
+
msg = ""
if cpu > 80: # type: ignore
msg = "咱感觉有些头晕..."
@@ -101,7 +92,7 @@ async def _():
else:
log.info("运作正常")
return
-
+
msg0 = (
"Self status:\n"
f"* CPU: {cpu}%\n"
@@ -110,9 +101,6 @@ async def _():
f"* netSENT: {inteSENT}MB\n"
f"* netRECV: {inteRECV}MB\n"
) + msg
-
+
for sup in Config.BotSelfConfig.superusers:
- await sv.NetworkPost.send_private_msg(
- user_id=sup,
- message=msg0
- )
+ await sv.NetworkPost.send_private_msg(user_id=sup, message=msg0)