3.5 KiB
3.5 KiB
qq-napcat-extras Skill
NapCat 扩展能力:好友点赞 + 图片文字识别(OCR)。
跨主机文件传递机制
NapCat 运行在 Docker 容器中,宿主目录与容器目录通过 volume 映射:
宿主机 YOUR_SHARED_DIR/* ⇔ 容器内 /app/files/*
脚本清单
| 脚本 | 用途 |
|---|---|
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"
}
}
注意事项
- 点赞不可滥用,同一好友约 10 秒间隔限制
- 连接 NapCat 失败时检查
http://YOUR_NAPCAT_HOST:25570 - OCR 远程 URL 会先下载到
/tmp,识别完自动删除