Files
HeXi/hexi/plugins/nonebot_plugin_helldivers_tools/__init__.py
T

80 lines
3.1 KiB
Python
Raw Normal View History

"""绝地潜兵小助手 —— 入口(元数据 + 依赖 + 配置/Web 注册)。"""
import os
import httpx # noqa: F401
from nonebot import logger
from nonebot.adapters.onebot.v11 import MessageEvent # noqa: F401
from nonebot.internal.params import ArgPlainText # noqa: F401
from nonebot.typing import T_State # noqa: F401
from nonebot import on_command # noqa: F401
from nonebot.plugin import PluginMetadata
from .services.equipment import get_random_equipment, get_equipment_by_combination # noqa: F401
from .services.hd2_api import get_briefing_data # noqa: F401
from .utils.war_renderer import render_war_briefing # noqa: F401
from .utils import gen_ms_img, pic2b64 # noqa: F401
from .services.equipment_store import init_db as _init_equipment_db
from .web import stratagem_admin as _stratagem_admin
from hexi.web_plugin_registry import register_web_plugin
__plugin_meta__ = PluginMetadata(
name="绝地潜兵小助手",
description="绝地潜兵小助手,提供一些小功能,让超级地球更加美好!",
usage="简报:获取星系战争简要概况(每个阵营取人数前 4 张卡片)\n"
"详报:全量绘制当前进行的战役\n"
"随机战备:让机器人帮你随机一套战备\n"
"战备管理后台:/hub/ 统一管理台内可视化编辑",
type="application",
homepage="https://github.com/sansenhoshi/nonebot_plugin_helldivers_tools",
)
basic_path = os.path.dirname(__file__)
save_path = os.path.join(basic_path, "temp")
img_path = os.path.join(basic_path, "res", "img")
data_path = os.path.join(basic_path, "data")
# 注册到统一 Web:hub 启动时会自动挂载 /api/helldivers,无需手动配置
_init_equipment_db()
register_web_plugin(
"helldivers",
"战备管理",
"rocket",
lambda: _stratagem_admin.build_admin_app(),
module_name=__name__,
)
logger.info("战备管理 Web 插件已注册(/api/helldivers)")
# 统一配置标准:把 API 相关配置暴露给 Web 管理台(/hub 插件配置)
from hexi.config_standard import register_model_config # noqa: E402
from .config import config as _hd2_config # noqa: E402
register_model_config(
__name__,
_hd2_config,
fields=[
"hd2_api_base_url",
"hd2_api_language",
"hd2_cache_ttl",
"hd2_super_client",
"hd2_super_contact",
],
labels={
"hd2_api_base_url": "API 根地址",
"hd2_api_language": "本地化语言",
"hd2_cache_ttl": "数据缓存秒数",
"hd2_super_client": "请求头 Client",
"hd2_super_contact": "请求头 Contact",
},
descriptions={
"hd2_api_base_url": "自托管 helldivers-2/api 根地址;不填则用公共社区 API",
"hd2_api_language": "请求本地化语言,自托管实例支持 zh-Hans/zh-Hant",
"hd2_cache_ttl": "战况快照约几分钟更新一次,靠这个避免频繁打接口触发限流",
"hd2_super_client": "公共/自托管都要求 X-Super-Client 头",
"hd2_super_contact": "公共/自托管都要求 X-Super-Contact 头",
},
)
from . import handlers as _handlers # noqa: E402,F401