117 lines
3.7 KiB
Python
117 lines
3.7 KiB
Python
# ruff: noqa: E402
|
|
|
|
from nonebot import get_driver, require
|
|
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
|
|
|
|
require("nonebot_plugin_apscheduler")
|
|
require("nonebot_plugin_alconna")
|
|
require("nonebot_plugin_uninfo")
|
|
require("nonebot_plugin_localstore")
|
|
|
|
from . import __main__ as __main__, misc_statistics as misc_statistics
|
|
from .bg_provider import bg_preloader
|
|
from .services.collectors import (
|
|
enable_collectors,
|
|
load_builtin_collectors,
|
|
registered_collectors,
|
|
)
|
|
from .config import ConfigModel, config
|
|
from .templates import load_builtin_templates, loaded_templates
|
|
|
|
# 统一配置标准:把常用、可安全热更的配置暴露给 Web 管理台
|
|
# (路径/嵌套模型/复杂 list 字段不改,避免格式互转出错)
|
|
from hexi.web_hub.config_standard import register_model_config # noqa: E402
|
|
|
|
register_model_config(
|
|
__name__,
|
|
config,
|
|
fields=[
|
|
"ps_template",
|
|
"ps_command",
|
|
"ps_only_su",
|
|
"ps_need_at",
|
|
"ps_reply_target",
|
|
"ps_bg_provider",
|
|
"ps_collect_interval",
|
|
"ps_proc_len",
|
|
"ps_test_timeout",
|
|
"ps_show_current_bot_only",
|
|
"ps_ob_v11_use_get_status",
|
|
],
|
|
types={"ps_bg_provider": "enum"},
|
|
options={"ps_bg_provider": [
|
|
{"value": "loli", "label": "loliapi"},
|
|
{"value": "lolicon", "label": "lolicon"},
|
|
{"value": "local", "label": "本地背景"},
|
|
{"value": "none", "label": "无背景"},
|
|
]},
|
|
labels={
|
|
"ps_template": "状态卡片模板",
|
|
"ps_command": "触发指令(每行一个)",
|
|
"ps_only_su": "仅超级管理员可用",
|
|
"ps_need_at": "需要 @ 机器人",
|
|
"ps_reply_target": "回复原消息",
|
|
"ps_bg_provider": "背景来源",
|
|
"ps_collect_interval": "采集间隔(秒)",
|
|
"ps_proc_len": "进程列表长度",
|
|
"ps_test_timeout": "测速超时(秒)",
|
|
"ps_show_current_bot_only": "只显示当前 bot",
|
|
"ps_ob_v11_use_get_status": "OneBot v11 用 get_status",
|
|
},
|
|
descriptions={
|
|
"ps_template": "内置: default",
|
|
"ps_command": "每行一个命令,缺省为 运行状态/状态/zt/yxzt/status",
|
|
"ps_bg_provider": "loli/lolicon 在线随机图,local 本地, none 关闭",
|
|
"ps_collect_interval": "后台采集数据的时间间隔(秒)",
|
|
},
|
|
)
|
|
|
|
|
|
driver = get_driver()
|
|
|
|
|
|
# lazy load builtin templates and collectors
|
|
@driver.on_startup
|
|
async def _():
|
|
if config.ps_template not in loaded_templates:
|
|
load_builtin_templates()
|
|
current_template = loaded_templates.get(config.ps_template)
|
|
if current_template is None:
|
|
raise ValueError(f"Template {config.ps_template} not found")
|
|
|
|
if (current_template.collectors is None) or any(
|
|
(x not in registered_collectors) for x in current_template.collectors
|
|
):
|
|
load_builtin_collectors()
|
|
|
|
collectors = (
|
|
set(registered_collectors)
|
|
if current_template.collectors is None
|
|
else current_template.collectors
|
|
)
|
|
await enable_collectors(*collectors)
|
|
|
|
bg_preloader.start_preload()
|
|
|
|
|
|
usage = f"指令:{' / '.join(config.ps_command)}"
|
|
if config.ps_need_at:
|
|
usage += "\n注意:使用指令时需要@机器人"
|
|
if config.ps_only_su:
|
|
usage += "\n注意:仅SuperUser可以使用此指令"
|
|
|
|
__version__ = "2.2.2"
|
|
__plugin_meta__ = PluginMetadata(
|
|
name="PicStatus",
|
|
description="以图片形式显示当前设备的运行状态",
|
|
usage=usage,
|
|
type="application",
|
|
homepage="https://github.com/lgc-NB2Dev/nonebot-plugin-picstatus",
|
|
config=ConfigModel,
|
|
supported_adapters=inherit_supported_adapters(
|
|
"nonebot_plugin_alconna",
|
|
"nonebot_plugin_uninfo",
|
|
),
|
|
extra={"License": "MIT", "Author": "LgCookie"},
|
|
)
|