Files
DanDingNoneBot/danding_bot/plugins/danding_qqpush/__init__.py
Mr.Xia 6eed4bf3a2 修复:升级 Pydantic v2 兼容性,修复插件加载错误
- 更新 danding_points 配置使用 pydantic_settings.BaseSettings 和 SettingsConfigDict
- 更新 onmyoji_gacha 配置使用 pydantic_settings.BaseSettings
- 修复 danding_qqpush 配置加载使用 model_validate 替代 parse_obj
- 添加 group_horse_racing 插件的详细 README 文档

这些修复解决了 Pydantic v2 迁移中的导入错误和 API 变更问题。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 22:27:45 +08:00

70 lines
1.8 KiB
Python

"""Danding_QqPush 插件初始化模块"""
from nonebot import get_driver, get_bots
from nonebot.log import logger
from nonebot.plugin import PluginMetadata
from .config import Config
from .api import create_routes
from .sender import sender
__plugin_meta__ = PluginMetadata(
name="danding_qqpush",
description="通过外部 HTTP API 向 QQ 群定向推送通知",
usage="""
API 接口:
POST /danding/qqpush/{token}
请求参数:
{
"group_id": 123456789,
"qq": 987654321,
"text": "系统告警#数据库连接失败#请立即处理"
}
说明:
- text 中的 # 表示换行
- 消息会自动渲染为图片并发送到指定群
""",
config=Config,
)
# 加载配置
plugin_config = Config.model_validate(get_driver().config.dict())
def register_routes():
"""注册 FastAPI 路由"""
driver = get_driver()
# 创建并注册路由
routes = create_routes(plugin_config.Token, plugin_config)
driver.server_app.include_router(routes)
logger.info(f"[Danding_QqPush] API 路由已注册: /danding/qqpush/{plugin_config.Token}")
def init_bot():
"""初始化 Bot 实例"""
try:
bots = get_bots()
if bots:
# 获取第一个可用的 Bot
bot = list(bots.values())[0]
sender.set_bot(bot)
logger.info(f"[Danding_QqPush] Bot 已连接: {bot.self_id}")
else:
logger.warning("[Danding_QqPush] 未找到可用的 Bot 实例")
except Exception as e:
logger.warning(f"[Danding_QqPush] 初始化 Bot 失败: {str(e)}")
# 插件加载时注册路由并初始化 Bot
try:
register_routes()
init_bot()
logger.info("[Danding_QqPush] 插件加载成功")
except Exception as e:
logger.error(f"[Danding_QqPush] 插件加载失败: {str(e)}")