完整 AgentSkill:词库外部化 + 全部脚本/Skill 脱敏上传
- 高危词库从 process.py 抽到 config.toml [security] section - process.py 改为 _get_high_risk_words() 动态加载(配置优先) - 新增 15 个 QQ 操作脚本(已脱敏:QQ号/IP/Token → 占位符) - 新增 8 个 SKILL.md(qq-messenger/management/resolver/napcat-extras 等) - 新增 SKILL.md 入口(完整部署方案文档) - 保留 SDK 框架(plugin_modules.py, file_store_api.py, package.py 等)
This commit is contained in:
85
scripts/qq_get_groups.py
Normal file
85
scripts/qq_get_groups.py
Normal file
@ -0,0 +1,85 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user