Files
chat_rebot-connect-with-one…/scripts/qq_get_groups.py
Claw 4068869217 feat(plugin): 集成 OpenClaw Bridge + QQ 操作技能套件
新增 openclaw_bridge 插件,实现 QQ ↔ OpenClaw Gateway 桥接:

src/process.py:
  - QQ 消息自动转发 OpenClaw Gateway
  - 内置安全检测(高危词、管理员白名单、MC指令过滤)
  - 高危词库外部化到 config.toml [security] section
  - 群昵称自动解析
  - Session 隔离(按群×用户)

config/openclawbridge/config.toml:
  - 插件配置模板(已脱敏:占位符替代个人信息)

scripts/qq_*.py (×15):
  - 消息发送/文件传输/群管理/好友管理
  - 信息查询/历史回溯/OCR/点赞
  - 全部脱敏(QQ号→YOUR_ADMIN_QQ, IP→YOUR_NAPCAT_HOST等)

skills/*/SKILL.md (×8):
  - AgentSkills 使用指导
  - qq-messenger / qq-management / qq-resolver / qq-napcat-extras
  - browser / file-process / mc-query / nix-helper

SKILL.md:
  - AgentSkill 入口,完整架构说明和部署步骤
2026-05-04 16:28:12 +08:00

86 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
获取群聊列表 - 通过 NapCat (OneBot) HTTP API
用法:
python3 qq_get_groups.py # 输出格式化群列表
python3 qq_get_groups.py --json # 输出 JSON供 agent 使用)
python3 qq_get_groups.py --keyword 我的世界 # 搜索群名包含"我的世界"的群
"""
import json
import sys
import argparse
import requests
CQHTTP_URL = "http://YOUR_NAP CAT_HOST:25570"
def get_group_list():
"""获取群聊列表,返回群字典列表"""
url = f"{CQHTTP_URL}/get_group_list"
resp = requests.post(url, json={}, timeout=10)
data = resp.json()
if data.get("status") == "ok":
return data.get("data", [])
raise Exception(f"API 返回异常: {json.dumps(data, ensure_ascii=False)}")
def format_groups(groups, keyword=None):
"""格式化为可读文本"""
if keyword:
keyword = keyword.lower()
filtered = []
for g in groups:
gid = str(g.get("group_id", ""))
name = g.get("group_name", "")
if keyword in gid or keyword in name.lower():
filtered.append(g)
groups = filtered
if not groups:
return "暂无群聊数据" if not keyword else f"未找到包含「{keyword}」的群"
lines = [f"{len(groups)} 个群\n"]
for g in groups:
gid = g.get("group_id", "?")
name = g.get("group_name", "?")
member_count = g.get("member_count", "?")
max_member = g.get("max_member_count", "?")
lines.append(f"{name} ({gid}) — {member_count}/{max_member}")
return "\n".join(lines)
def main():
parser = argparse.ArgumentParser(description="获取 QQ 群聊列表")
parser.add_argument("--json", action="store_true", help="输出 JSON 格式")
parser.add_argument("--keyword", type=str, help="按群名关键词筛选")
args = parser.parse_args()
try:
groups = get_group_list()
if args.keyword:
kw = args.keyword.lower()
groups = [
g for g in groups
if kw in str(g.get("group_id", ""))
or kw in g.get("group_name", "").lower()
]
if args.json:
print(json.dumps(groups, ensure_ascii=False, indent=2))
else:
print(format_groups(groups, args.keyword))
except requests.exceptions.ConnectionError:
print(f"❌ 连接失败: 无法连接到 NapCat ({CQHTTP_URL})")
sys.exit(1)
except Exception as e:
print(f"❌ 获取群聊列表失败: {e}")
sys.exit(1)
if __name__ == "__main__":
main()