功能:通过 HTTP API 实现 Danding_QqPush 插件,用于 QQ 群通知

- 增加了通过外部 HTTP API 向 QQ 群组发送消息的核心功能。
- 实现了对长文本消息的图片渲染,以避免被认定为垃圾信息。
- 支持在消息中提及特定的 QQ 用户。
- 创建了用于 API 令牌和图片渲染设置的配置选项。
- 开发了一个测试脚本以验证 API 功能。
- 对现有代码进行了重构,以提高组织性和可维护性。
This commit is contained in:
2026-01-20 21:19:05 +08:00
parent 4a944316fe
commit dedc872f1b
14 changed files with 1065 additions and 48 deletions

49
test_qqpush.py Normal file
View File

@@ -0,0 +1,49 @@
"""Danding_QqPush 插件测试脚本"""
import requests
import json
def test_qqpush_api():
"""测试 QQ 推送 API"""
# 配置
base_url = "http://localhost:8080" # NoneBot 默认端口
token = "danding-8HkL9xQ2" # 默认 Token
# 构造请求数据
data = {
"group_id": 574727392, # 替换为实际群号
"qq": 1424473282, # 替换为实际 QQ 号
"text": "系统告警#数据库连接失败#请立即处理#测试消息"
}
# 发送请求
url = f"{base_url}/danding/qqpush/{token}"
print(f"正在测试 API: {url}")
print(f"请求数据: {json.dumps(data, ensure_ascii=False, indent=2)}")
try:
response = requests.post(
url,
json=data,
headers={"Content-Type": "application/json"},
timeout=10
)
print(f"\n响应状态码: {response.status_code}")
print(f"响应内容: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
if response.status_code == 200:
print("\n✅ 测试成功!")
else:
print(f"\n❌ 测试失败,状态码: {response.status_code}")
except requests.exceptions.ConnectionError:
print("\n❌ 连接失败,请确认 NoneBot 是否已启动")
except Exception as e:
print(f"\n❌ 测试异常: {str(e)}")
if __name__ == "__main__":
test_qqpush_api()