Files
chatrebot_aireply_plug/skills/qq-napcat-extras/SKILL.md
root 9dff73e7bc fix: 通过本地完整测试发现的 11 个 bug
🔴 致命(5个):
- Bug1: onebot11.json 格式错误(旧 {http:{},ws:{}} → network.httpServers/httppClients)
- Bug2: 端口映射错位(WebUI 6099, OneBot API 6097 独立端口)
- Bug3: 变量名含空格 NAP CAT_HOST → NAPCAT_HOST(14脚本+2SKILL+README)
- Bug4: heredoc 单引号阻止变量展开
- Bug5: process.py 缺失 _get_high_risk_words() 方法

🟡 重要(3个):
- Bug6: onebot11.json 默认不存在(cat > 而非 edit)
- Bug7: API 须登录后才响应(新增扫码引导步骤)
- Bug8: qqrebot systemd 依赖 napcat 服务

🟢 中等(3个):
- Bug9: Skills 占位符缺 YOUR_NAPCAT_HOST sed 覆盖
- Bug10: venv 不可用需降级方案
- Bug11: 端口 25580 冲突处理
已验证全链路:NapCat + qqrebot + 插件 + OpenClaw Gateway + AI 回复
2026-05-04 19:47:26 +08:00

3.5 KiB
Raw Blame History

qq-napcat-extras Skill

NapCat 扩展能力:好友点赞 + 图片文字识别(OCR)。


跨主机文件传递机制

NapCat 运行在 Docker 容器中,宿主目录与容器目录通过 volume 映射:

宿主机 YOUR_SHARED_DIR/*  ⇔  容器内 /app/napcat/share/*

脚本清单

脚本 用途
qq_send_like.py 给 QQ 好友点赞
qq_ocr_image.py 图片文字识别(本地 Tesseract + NapCat 回退)

1. 好友点赞

给指定 QQ 好友点赞(发送「戳一戳」/点赞)。

脚本路径: YOUR_WORKSPACE_PATH/scripts/qq_send_like.py

用法

import subprocess, json

result = subprocess.run(
    ["python3", "YOUR_WORKSPACE_PATH/scripts/qq_send_like.py", "YOUR_ADMIN_QQ", "1"],
    text=True, timeout=15, capture_output=True
)
data = json.loads(result.stdout)
# data["status"] == "ok" 表示成功

参数

参数 说明
<user_id> 目标 QQ 号(必需)
<times> 点赞次数,1-20(可选,默认 1)

返回格式

{"status": "ok", "retcode": 0, "data": null, "message": "", "wording": "", "echo": null}

2. 图片文字识别 (OCR)

使用本地 Tesseract OCR(tesseract 5.5 + chi_sim/eng),NapCat 作为回退。

OCR 策略

本地图片 → Tesseract OCR(快速可靠,无需 GUI)
            ↓ 失败
           NapCat /ocr_image(Docker 环境大概率超时)

用法

import subprocess, json

# 方式1:本地文件
result = subprocess.run(
    ["python3", "YOUR_WORKSPACE_PATH/scripts/qq_ocr_image.py",
     "/tmp/screenshot.png"],
    text=True, timeout=120, capture_output=True
)
data = json.loads(result.stdout)
print(data.get("data", {}).get("full_text", ""))

# 方式2:指定语言
result = subprocess.run(
    ["python3", "YOUR_WORKSPACE_PATH/scripts/qq_ocr_image.py",
     "--file", "/tmp/image.png", "--lang", "eng"],
    text=True, timeout=120, capture_output=True
)

# 方式3:远程 URL(自动下载后 Tesseract 识别)
result = subprocess.run(
    ["python3", "YOUR_WORKSPACE_PATH/scripts/qq_ocr_image.py",
     "--url", "https://example.com/msg.png"],
    text=True, timeout=120, capture_output=True
)

# 方式4:强制走 NapCat(跳过本地 Tesseract)
result = subprocess.run(
    ["python3", "YOUR_WORKSPACE_PATH/scripts/qq_ocr_image.py",
     "--file", "/tmp/img.png", "--force-napcat"],
    text=True, timeout=120, capture_output=True
)

参数

参数 说明
<path> 本地图片路径(位置参数)
--file <path> 本地图片文件路径
--url <url> 远程图片 URL(自动下载后识别)
--lang <lang> 识别语言(默认 chi_sim+eng)
--force-napcat 强制使用 NapCat(跳过 Tesseract)

语言选项

值 说明
chi_sim 简体中文
chi_tra 繁体中文
eng 英文
chi_sim+eng 中英文混合(默认,推荐)
jpn / kor 日文 / 韩文(需安装对应 tessdata)

成功返回格式

{
  "status": "ok",
  "source": "tesseract",
  "data": {
    "texts": [
      {"text": "识别结果", "confidence": 95, "bbox": {"x": 10, "y": 20, "w": 100, "h": 30}}
    ],
    "full_text": "所有识别到的文字\n多行文本",
    "language": "chi_sim+eng"
  }
}

注意事项

  1. 点赞不可滥用,同一好友约 10 秒间隔限制
  2. 连接 NapCat 失败时检查 http://YOUR_NAPCAT_HOST:25570
  3. OCR 远程 URL 会先下载到 /tmp,识别完自动删除