feat: 新增通知图片测试命令

This commit is contained in:
2026-09-22 21:50:27 +08:00
parent 87c59a0335
commit f4d3abcd09
9 changed files with 2068 additions and 680 deletions

View File

@@ -1,65 +1,74 @@
"""Danding_QqPush 插件初始化模块"""
from nonebot import get_driver
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,
"""Danding_QqPush 插件初始化模块"""
from nonebot import get_driver
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,
"text": "系统告警#数据库连接失败#请立即处理"
}
说明:
- text 中的 # 表示换行
- 消息会自动渲染为图片并发送到指定群
""",
config=Config,
)
# 加载配置
plugin_config = Config.model_validate(get_driver().config.model_dump())
def register_routes():
"""注册 FastAPI 路由"""
driver = get_driver()
# 创建并注册路由
routes = create_routes(plugin_config.Token, plugin_config)
driver.server_app.include_router(routes)
masked = plugin_config.Token[:4] + "***" if len(plugin_config.Token) > 4 else "***"
logger.info(f"[Danding_QqPush] API 路由已注册: /danding/qqpush/{masked}")
# 插件加载时注册路由
try:
register_routes()
logger.info("[Danding_QqPush] 插件加载成功")
except Exception as e:
logger.error(f"[Danding_QqPush] 插件加载失败: {str(e)}")
# Bot 连接时自动初始化 sender
driver = get_driver()
@driver.on_bot_connect
async def _(bot):
"""Bot 连接时自动设置 sender"""
try:
sender.set_bot(bot)
logger.info(f"[Danding_QqPush] Bot 已连接: {bot.self_id}")
except Exception as e:
logger.error(f"[Danding_QqPush] Bot 连接初始化失败: {e}")
}
说明:
- text 中的 # 表示换行
- 消息会自动渲染为图片并发送到指定群
测试命令(仅超级用户):
测试通知图片(别名:通知图片测试、测试通知卡片)
- 群聊中发送渲染群聊通知卡片,私聊中发送渲染私聊通知卡片
- 固定预览内容覆盖标题、中文、多行、Emoji 与中文标点,用于肉眼核对版式
""",
config=Config,
)
# 加载配置
plugin_config = Config.model_validate(get_driver().config.model_dump())
# 配置初始化完成后再导入测试命令模块,避免反向依赖尚未初始化完成的插件包
from . import test_command # noqa: E402,F401 - 导入即注册测试命令 matcher
def register_routes():
"""注册 FastAPI 路由"""
driver = get_driver()
# 创建并注册路由
routes = create_routes(plugin_config.Token, plugin_config)
driver.server_app.include_router(routes)
masked = plugin_config.Token[:4] + "***" if len(plugin_config.Token) > 4 else "***"
logger.info(f"[Danding_QqPush] API 路由已注册: /danding/qqpush/{masked}")
# 插件加载时注册路由
try:
register_routes()
logger.info("[Danding_QqPush] 插件加载成功")
except Exception as e:
logger.error(f"[Danding_QqPush] 插件加载失败: {str(e)}")
# Bot 连接时自动初始化 sender
driver = get_driver()
@driver.on_bot_connect
async def _(bot):
"""Bot 连接时自动设置 sender"""
try:
sender.set_bot(bot)
logger.info(f"[Danding_QqPush] Bot 已连接: {bot.self_id}")
except Exception as e:
logger.error(f"[Danding_QqPush] Bot 连接初始化失败: {e}")