aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/hydroroll/plugins/plugin_system
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-08-13 12:24:45 +0800
committer简律纯 <i@jyunko.cn>2023-08-13 12:24:45 +0800
commit4bf6db5200affc2f623aa02301020092c0789d19 (patch)
tree9f32d49fb967b16a4f4c79bb39bf3ccff6773b9b /hydroroll/plugins/plugin_system
parentc30ca50aab37a86534b3dcd27c253cc79d0c8101 (diff)
downloadHydroRoll-4bf6db5200affc2f623aa02301020092c0789d19.tar.gz
HydroRoll-4bf6db5200affc2f623aa02301020092c0789d19.zip
refactor: 根据tests重构
Diffstat (limited to 'hydroroll/plugins/plugin_system')
-rw-r--r--hydroroll/plugins/plugin_system/__init__.py75
-rw-r--r--hydroroll/plugins/plugin_system/config.py11
2 files changed, 0 insertions, 86 deletions
diff --git a/hydroroll/plugins/plugin_system/__init__.py b/hydroroll/plugins/plugin_system/__init__.py
deleted file mode 100644
index ea797d3..0000000
--- a/hydroroll/plugins/plugin_system/__init__.py
+++ /dev/null
@@ -1,75 +0,0 @@
-import re
-from plugins.plugin_base import CommandPluginBase
-from .config import Config
-import psutil
-import time
-from hydroroll.config import GlobalConfig
-from iamai.adapter.cqhttp.message import CQHTTPMessageSegment
-
-class System(CommandPluginBase[None, Config]):
- priority: int = 0
- block: bool = True
- Config = Config
- CurrentConfig = GlobalConfig
-
- def __post_init__(self):
- self.re_pattern = re.compile(r"(?P<system_info_str>.*)", flags=re.I)
-
- def eventReply(self, message: str):
- return self.event.reply(
- self.format_str(self.config.message_str, message)
- )
-
- def get_system_status(self) -> str:
- cpu_usage = psutil.cpu_percent()
- memory_usage = psutil.virtual_memory().percent
- disk_usage = psutil.disk_usage('/').percent
-
- current_time = time.time()
- start_time = psutil.Process().create_time()
-
- uptime_seconds = int(current_time - start_time)
- uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
-
- info_str = f"{self.CurrentConfig._name} Ver.{self.CurrentConfig._version}"
- info_str += f"({self.CurrentConfig._svn}) built in Python {self.CurrentConfig._python_ver}\n"
- info_str += f"本地时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}\n"
- info_str += f"已启动时间:{uptime_str}\n"
- info_str += f"CPU使用率:{cpu_usage}%\n"
- info_str += f"内存占用率:{memory_usage}%\n"
- info_str += f"磁盘使用率:{disk_usage}%"
-
- return info_str
-
- async def handle(self) -> None:
- system = self.CurrentConfig.HydroSystem()
- try:
- sub_command = self.event.get_plain_text().split()[1]
- except IndexError:
- sub_command = ""
-
- if sub_command in ["status", "s"]:
- await self.event.reply(
- self.format_str(self.config.message_str,
- self.get_system_status())
- )
- elif sub_command in ["restart", "rst"]:
- await self.event.reply(
- self.format_str(self.config.message_str, "正在重启系统...")
- )
- self.bot.restart()
-
- elif sub_command in ["reload", "rld"]:
- await self.event.reply(
- self.format_str(self.config.message_str, "正在重载...")
- )
- self.bot.reload_plugins()
- await self.event.reply(
- self.format_str(self.config.message_str,
- f"已加载{len(self.bot.plugins)}枚插件")
- )
- else:
- await self.event.reply(
- CQHTTPMessageSegment.reply(self.event.message_id) +
- self.format_str(self.config.message_str, system.help)
- )
diff --git a/hydroroll/plugins/plugin_system/config.py b/hydroroll/plugins/plugin_system/config.py
deleted file mode 100644
index aa5f51b..0000000
--- a/hydroroll/plugins/plugin_system/config.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from typing import Set
-
-from plugins.plugin_base import CommandPluginConfig
-
-
-class Config(CommandPluginConfig):
- __config_name__ = "plugin_system_info"
- command: Set[str] = {"system"}
- """命令文本。"""
- message_str: str = "{message}"
- """最终发送消息的格式。"""