Files
HeXi/hexi/plugins/nonebot_plugin_galgame_card/__init__.py
T
sansenhoshiandClaude 9371a28e35 refactor: restructure plugins per MTSS standard, consolidate assets to res/
Per docs/plugin-audit-report.md (plugins normalized to
Trigger(handlers) → Service(services) → Model(repository/models) + utils):

- Split monolithic __init__.py into handlers/services/utils across
  dailywife, deer_pipe, dice, galgame_card, helldivers_tools,
  huoziyinshua, learning_chat, makeaquote, mc_server_status,
  ncm_saying, picfinder_take, picstatus, random_jm_code, regif,
  steam_info, video_analysis, group_tools
- Move static assets under res/: deer_pipe font/img, makeaquote font,
  helldivers img/templates, huoziyinshua HuoZiYinShua
- Add config.py + register_config_items to ncm_saying, random_jm_code,
  group_tools; learning_chat unified config bridge
- Remove deprecated: voice_trans plugin, bf_bot/test.py, dead code in
  dailywife/deer_pipe, empty dirs, debug scripts under helldivers temp
- Disable brash_general_supercredits_tools (stub comment only)
- bot.py: optional stdout/stderr redirect to log file for Web log viewer,
  force ANSI colorize on non-TTY sinks
- Move runtime data (jm_code.json) out of plugin dir into hexi/data
- Docs: plugin-audit-report.md; README reflects removed plugins

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-03 00:44:38 +08:00

102 lines
3.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""群聊人设卡 —— 基于群聊语料蒸馏成员形象,生成 galgame 风格人物卡
消息入口:on_message 监听全部消息事件,类型注解过滤出群聊,两级闸门(群开关 +
个人 opt-in)通过后,治理层处理落库。采集编排已下沉到 services/collector.py。
当前进度:数据层 + 采集层(消息路径)完成;总结路径(印象/画像)待实现。
"""
from nonebot import get_driver, require
require("nonebot_plugin_orm")
from nonebot.adapters.onebot.v11 import GroupMessageEvent # noqa: F401
from nonebot.plugin import PluginMetadata
# ── 禁用 nonebot_plugin_orm 的启动自动同步 ─────────────────────────────
from nonebot import logger as _logger
try:
import nonebot_plugin_orm.migrate as _orm_migrate
def _safe_sync(*_args, **_kwargs):
_logger.debug("galgame_card | 已禁用 orm 自动同步(schema 演进由 ensure_schema 接管)")
_orm_migrate.sync = _safe_sync
except ImportError:
_logger.warning("galgame_card | 无法禁用 orm 自动同步,请检查 nonebot_plugin_orm 是否安装")
from . import models # noqa: F401 # 确保表结构注册
from . import repository, processor
from . import web # noqa: F401 # Web 管理后台(/galgame_card)
from . import handlers as _handlers # noqa: E402
from hexi.web_config import register_plugin_config # noqa: E402
from hexi.web_plugin_registry import register_web_plugin # noqa: E402
from . import web_hub # noqa: E402
def _apply_galgame_config(values: dict) -> None:
import sys
conf_mod = sys.modules.get("hexi.plugins.nonebot_plugin_galgame_card.config")
if conf_mod is None:
return
conf = getattr(conf_mod, "config", None)
if conf is None:
return
for key, value in values.items():
try:
setattr(conf, key, value)
except Exception: # noqa: BLE001
pass
def _get_galgame_config_values() -> dict:
import sys
conf_mod = sys.modules.get("hexi.plugins.nonebot_plugin_galgame_card.config")
conf = getattr(conf_mod, "config", None) if conf_mod else None
if conf is None:
return {}
keys = ("web_enable", "web_username", "web_password", "web_secret_key", "image_vision_enabled")
return {k: getattr(conf, k, None) for k in keys}
register_plugin_config(
__name__,
{
"fields": [
{"key": "web_enable", "label": "Web 后台启用", "type": "bool", "default": True},
{"key": "web_username", "label": "Web 登录账号", "type": "string", "default": "admin"},
{"key": "web_password", "label": "Web 登录密码", "type": "password", "default": "galgame", "secret": True},
{"key": "web_secret_key", "label": "Web 签名密钥", "type": "password", "default": "galgame-card-secret-key", "secret": True},
{"key": "image_vision_enabled", "label": "图片识别启用", "type": "bool", "default": False},
]
},
apply=_apply_galgame_config,
getter=_get_galgame_config_values,
)
# 注册到统一 Web 管理台(/hub):hub 启动时挂载 /api/galgame_card
register_web_plugin(
"galgame_card",
"群聊人设卡",
"user",
lambda: web_hub.build_admin_app(),
module_name=__name__,
)
__plugin_meta__ = PluginMetadata(
name="群聊人设卡",
description="基于群聊语料蒸馏成员形象,生成 galgame 风格人物卡",
usage="开发中……",
type="application",
)
_driver = get_driver()
@_driver.on_startup
async def _ensure_schema():
"""老库迁移(persona_group.group_name 列),幂等"""
await repository.ensure_schema()