Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 01d9c82f80 | |||
| 66d3801e43 | |||
| 973547b6fb | |||
| edaac8aa45 | |||
| 157f51c765 | |||
| d54a69cba8 | |||
| 3b6f15ecbb | |||
| cd131697d5 | |||
| 2e3ac2cfe7 | |||
| bea22d5e9e | |||
| 7759e0b376 | |||
| 92a9d61007 |
76
.github/workflows/release_skill.yaml
vendored
76
.github/workflows/release_skill.yaml
vendored
@@ -1,75 +1,11 @@
|
|||||||
name: 技能自动化发布 (测试版-无鉴权)
|
name: 技能自动化发布
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags: ["v*"]
|
tags: ["v*"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
release:
|
||||||
runs-on: ubuntu-latest
|
uses: admin/jiangchang-platform-kit/.github/workflows/reusable-release-skill.yaml@main
|
||||||
steps:
|
with:
|
||||||
# 1. 下载源码
|
artifact_platform: windows
|
||||||
- uses: actions/checkout@v3
|
pyarmor_platform: windows.x86_64
|
||||||
|
|
||||||
# 2. 环境及工具准备
|
|
||||||
- name: Setup Tools
|
|
||||||
# 优化:使用国内清华源加速安装速度
|
|
||||||
run: pip install pyarmor requests python-frontmatter --break-system-packages -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
||||||
|
|
||||||
# 3. 【核心步骤】PyArmor 源代码混淆加密
|
|
||||||
- name: Encrypt Source Code
|
|
||||||
run: |
|
|
||||||
mkdir -p dist/package
|
|
||||||
pyarmor gen -O dist/package scripts/*.py
|
|
||||||
cp SKILL.md dist/package/
|
|
||||||
|
|
||||||
# 4. 提取元数据并物理打包
|
|
||||||
- name: Parse Metadata and Pack
|
|
||||||
id: build_task
|
|
||||||
run: |
|
|
||||||
python -c "
|
|
||||||
import frontmatter, os, json, shutil
|
|
||||||
post = frontmatter.load('SKILL.md')
|
|
||||||
metadata = post.metadata
|
|
||||||
slug = metadata['name']
|
|
||||||
version = metadata['version']
|
|
||||||
# 安全写入输出
|
|
||||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
|
|
||||||
f.write(f'slug={slug}\n')
|
|
||||||
f.write(f'version={version}\n')
|
|
||||||
f.write(f'metadata={json.dumps(metadata)}\n')
|
|
||||||
|
|
||||||
# 制作最终的发布 ZIP 包
|
|
||||||
shutil.make_archive(slug, 'zip', 'dist/package')
|
|
||||||
"
|
|
||||||
|
|
||||||
# 5. 同步数据库记录
|
|
||||||
- name: Sync Database (V2.0)
|
|
||||||
env:
|
|
||||||
METADATA_JSON: ${{ steps.build_task.outputs.metadata }}
|
|
||||||
run: |
|
|
||||||
python -c "
|
|
||||||
import requests, json, os
|
|
||||||
metadata = json.loads(os.environ['METADATA_JSON'])
|
|
||||||
url = 'https://jc2009.com/api/skill/update'
|
|
||||||
res = requests.post(url, json=metadata)
|
|
||||||
print(f'DB Sync Result: {res.text}')
|
|
||||||
if res.status_code != 200: exit(1)
|
|
||||||
"
|
|
||||||
|
|
||||||
# 6. 上传物理包
|
|
||||||
- name: Upload Encrypted ZIP
|
|
||||||
env:
|
|
||||||
SLUG: ${{ steps.build_task.outputs.slug }}
|
|
||||||
VERSION: ${{ steps.build_task.outputs.version }}
|
|
||||||
run: |
|
|
||||||
python -c "
|
|
||||||
import requests, os
|
|
||||||
url = 'https://jc2009.com/api/upload'
|
|
||||||
slug = os.environ['SLUG']
|
|
||||||
version = os.environ['VERSION']
|
|
||||||
payload = {'plugin_name': slug, 'version': version, 'artifact_type': 'skill'}
|
|
||||||
with open(f'{slug}.zip', 'rb') as f:
|
|
||||||
res = requests.post(url, data=payload, files={'file': f})
|
|
||||||
print(f'Upload Result: {res.text}')
|
|
||||||
if res.status_code != 200: exit(1)
|
|
||||||
"
|
|
||||||
36
SKILL.md
36
SKILL.md
@@ -1,16 +1,18 @@
|
|||||||
---
|
---
|
||||||
name: account-manager
|
name: 账号管理
|
||||||
description: 多平台多账号管理。管理各平台账号与Chrome Profile的对应关系,供publisher类Skill调用获取账号信息。
|
description: 多平台多账号管理。管理各平台账号与Chrome Profile的对应关系,供publisher类Skill调用获取账号信息。
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
author: 深圳匠厂科技有限公司
|
author: 深圳匠厂科技有限公司
|
||||||
metadata:
|
metadata:
|
||||||
openclaw:
|
openclaw:
|
||||||
|
slug: account-manager
|
||||||
emoji: "👤"
|
emoji: "👤"
|
||||||
|
category: "通用"
|
||||||
allowed-tools:
|
allowed-tools:
|
||||||
- bash
|
- bash
|
||||||
---
|
---
|
||||||
|
|
||||||
# 账号管理器
|
# 账号管理
|
||||||
|
|
||||||
## 使用时机
|
## 使用时机
|
||||||
|
|
||||||
@@ -23,32 +25,4 @@ allowed-tools:
|
|||||||
|
|
||||||
### 列出某平台所有账号
|
### 列出某平台所有账号
|
||||||
```bash
|
```bash
|
||||||
python3 {baseDir}/scripts/account.py list <platform>
|
python3 {baseDir}/scripts/account.py list <platform>
|
||||||
```
|
|
||||||
|
|
||||||
### 获取某个账号详情
|
|
||||||
```bash
|
|
||||||
python3 {baseDir}/scripts/account.py get <account_id>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 初始化账号登录(首次使用,打开浏览器手动登录)
|
|
||||||
```bash
|
|
||||||
python3 {baseDir}/scripts/account.py login <account_id>
|
|
||||||
```
|
|
||||||
|
|
||||||
## 输出格式
|
|
||||||
|
|
||||||
- list:逐行返回账号ID和名称
|
|
||||||
- get:返回账号完整信息
|
|
||||||
- login:打开浏览器后提示用户手动完成登录
|
|
||||||
|
|
||||||
## 错误处理
|
|
||||||
|
|
||||||
- 账号不存在:提示"未找到该账号,请检查账号ID是否正确"
|
|
||||||
- 平台无账号:提示"该平台暂无账号,请先在accounts.json中添加"
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
- 账号档案存储在 `accounts.json`,新增账号需手动编辑该文件
|
|
||||||
- Chrome Profile目录首次登录后自动创建,登录态永久保存
|
|
||||||
- 每个账号只需初始化登录一次
|
|
||||||
23
release.ps1
Normal file
23
release.ps1
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[string]$Prefix = "v",
|
||||||
|
[string]$Message = "正式发布",
|
||||||
|
[switch]$AutoCommit,
|
||||||
|
[switch]$RequireClean,
|
||||||
|
[string]$CommitMessage,
|
||||||
|
[switch]$DryRun
|
||||||
|
)
|
||||||
|
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$sharedScript = Join-Path $scriptDir "..\jiangchang-platform-kit\tools\release.ps1"
|
||||||
|
$sharedScript = [System.IO.Path]::GetFullPath($sharedScript)
|
||||||
|
|
||||||
|
if (-not (Test-Path $sharedScript)) {
|
||||||
|
throw "Shared release script not found: $sharedScript"
|
||||||
|
}
|
||||||
|
|
||||||
|
& $sharedScript @PSBoundParameters
|
||||||
|
exit $LASTEXITCODE
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
# Windows GBK 编码兼容修复
|
# Windows GBK 编码兼容修复
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
@@ -9,7 +11,8 @@ if sys.platform == "win32":
|
|||||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
ACCOUNTS_FILE = os.path.join(BASE_DIR, "accounts.json")
|
SKILL_SLUG = "account-manager"
|
||||||
|
LEGACY_ACCOUNTS_FILE = os.path.join(BASE_DIR, "accounts.json")
|
||||||
|
|
||||||
PLATFORM_URLS = {
|
PLATFORM_URLS = {
|
||||||
# 自媒体/图文平台
|
# 自媒体/图文平台
|
||||||
@@ -26,50 +29,197 @@ PLATFORM_URLS = {
|
|||||||
"yuanbao": "https://yuanbao.tencent.com"
|
"yuanbao": "https://yuanbao.tencent.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
def load_accounts():
|
|
||||||
with open(ACCOUNTS_FILE, "r", encoding="utf-8") as f:
|
def get_data_root():
|
||||||
return json.load(f)
|
return (os.getenv("JIANGCHANG_DATA_ROOT") or os.path.join(os.path.expanduser("~"), ".jiangchang-data")).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_id():
|
||||||
|
uid = (os.getenv("JIANGCHANG_USER_ID") or os.getenv("OPENCLAW_USER_ID") or "").strip()
|
||||||
|
return uid or "_anon"
|
||||||
|
|
||||||
|
|
||||||
|
def get_skill_data_dir():
|
||||||
|
path = os.path.join(get_data_root(), get_user_id(), SKILL_SLUG)
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_path():
|
||||||
|
return os.path.join(get_skill_data_dir(), "account-manager.db")
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_profile_dir(account_id):
|
||||||
|
path = os.path.join(get_skill_data_dir(), "profiles", account_id)
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_conn():
|
||||||
|
return sqlite3.connect(get_db_path())
|
||||||
|
|
||||||
|
|
||||||
|
def init_db():
|
||||||
|
conn = get_conn()
|
||||||
|
try:
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS accounts (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
platform TEXT NOT NULL,
|
||||||
|
phone TEXT,
|
||||||
|
profile_dir TEXT,
|
||||||
|
extra_json TEXT,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_legacy_json_if_needed():
|
||||||
|
init_db()
|
||||||
|
conn = get_conn()
|
||||||
|
try:
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("SELECT COUNT(1) FROM accounts")
|
||||||
|
count = cur.fetchone()[0]
|
||||||
|
if count > 0:
|
||||||
|
return
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if not os.path.exists(LEGACY_ACCOUNTS_FILE):
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(LEGACY_ACCOUNTS_FILE, "r", encoding="utf-8") as f:
|
||||||
|
raw = json.load(f)
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
now = datetime.now().isoformat(timespec="seconds")
|
||||||
|
rows = []
|
||||||
|
for platform, accounts in (raw or {}).items():
|
||||||
|
for acc in accounts:
|
||||||
|
acc_id = str(acc.get("id") or "").strip()
|
||||||
|
if not acc_id:
|
||||||
|
continue
|
||||||
|
profile_dir = (acc.get("profile_dir") or "").strip() or get_default_profile_dir(acc_id)
|
||||||
|
base = {
|
||||||
|
"id": acc_id,
|
||||||
|
"name": str(acc.get("name") or acc_id),
|
||||||
|
"platform": str(acc.get("platform") or platform),
|
||||||
|
"phone": str(acc.get("phone") or ""),
|
||||||
|
"profile_dir": profile_dir,
|
||||||
|
}
|
||||||
|
extra = {k: v for k, v in acc.items() if k not in base}
|
||||||
|
rows.append(
|
||||||
|
(
|
||||||
|
base["id"],
|
||||||
|
base["name"],
|
||||||
|
base["platform"],
|
||||||
|
base["phone"],
|
||||||
|
base["profile_dir"],
|
||||||
|
json.dumps(extra, ensure_ascii=False) if extra else None,
|
||||||
|
now,
|
||||||
|
now,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not rows:
|
||||||
|
return
|
||||||
|
|
||||||
|
conn = get_conn()
|
||||||
|
try:
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.executemany(
|
||||||
|
"""
|
||||||
|
INSERT OR REPLACE INTO accounts
|
||||||
|
(id, name, platform, phone, profile_dir, extra_json, created_at, updated_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
rows,
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def get_account_by_id(account_id):
|
||||||
|
migrate_legacy_json_if_needed()
|
||||||
|
conn = get_conn()
|
||||||
|
try:
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute(
|
||||||
|
"SELECT id, name, platform, phone, profile_dir, extra_json FROM accounts WHERE id = ?",
|
||||||
|
(account_id,),
|
||||||
|
)
|
||||||
|
row = cur.fetchone()
|
||||||
|
if not row:
|
||||||
|
return None
|
||||||
|
acc = {
|
||||||
|
"id": row[0],
|
||||||
|
"name": row[1],
|
||||||
|
"platform": row[2],
|
||||||
|
"phone": row[3] or "",
|
||||||
|
"profile_dir": row[4] or get_default_profile_dir(row[0]),
|
||||||
|
}
|
||||||
|
if row[5]:
|
||||||
|
try:
|
||||||
|
extra = json.loads(row[5])
|
||||||
|
if isinstance(extra, dict):
|
||||||
|
acc.update(extra)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return acc
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
def cmd_list(platform="all"):
|
def cmd_list(platform="all"):
|
||||||
"""
|
"""
|
||||||
修改后的 list 功能,能直观打出带着【手机号】的详细台账供AI查询匹配!
|
修改后的 list 功能,能直观打出带着【手机号】的详细台账供AI查询匹配!
|
||||||
支持查全部(all),或指定(sohu)
|
支持查全部(all),或指定(sohu)
|
||||||
"""
|
"""
|
||||||
accounts = load_accounts()
|
migrate_legacy_json_if_needed()
|
||||||
if platform == "all":
|
conn = get_conn()
|
||||||
platforms_to_check = accounts.keys()
|
|
||||||
else:
|
|
||||||
platforms_to_check = [platform]
|
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
for plat in platforms_to_check:
|
try:
|
||||||
platform_accounts = accounts.get(plat, [])
|
cur = conn.cursor()
|
||||||
for acc in platform_accounts:
|
if platform == "all":
|
||||||
phone = acc.get('phone', '未绑定手机')
|
cur.execute("SELECT id, name, phone, platform FROM accounts ORDER BY platform, id")
|
||||||
print(f"账号ID:{acc['id']} | 名称:{acc['name']} | 手机号:{phone} | 平台:{acc['platform']}")
|
else:
|
||||||
found = True
|
cur.execute(
|
||||||
|
"SELECT id, name, phone, platform FROM accounts WHERE platform = ? ORDER BY id",
|
||||||
|
(platform,),
|
||||||
|
)
|
||||||
|
rows = cur.fetchall()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for row in rows:
|
||||||
|
phone = row[2] or "未绑定手机"
|
||||||
|
print(f"账号ID:{row[0]} | 名称:{row[1]} | 手机号:{phone} | 平台:{row[3]}")
|
||||||
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
print(f"ERROR:NO_ACCOUNTS_FOUND")
|
print(f"ERROR:NO_ACCOUNTS_FOUND")
|
||||||
|
|
||||||
def cmd_get(account_id):
|
def cmd_get(account_id):
|
||||||
accounts = load_accounts()
|
acc = get_account_by_id(account_id)
|
||||||
for platform_accounts in accounts.values():
|
if acc:
|
||||||
for acc in platform_accounts:
|
print(json.dumps(acc, ensure_ascii=False))
|
||||||
if acc["id"] == account_id:
|
return
|
||||||
print(json.dumps(acc, ensure_ascii=False))
|
|
||||||
return
|
|
||||||
print("ERROR:ACCOUNT_NOT_FOUND")
|
print("ERROR:ACCOUNT_NOT_FOUND")
|
||||||
|
|
||||||
def cmd_login(account_id):
|
def cmd_login(account_id):
|
||||||
"""首次登录:打开浏览器,用户手动登录,登录态自动保存到Profile目录"""
|
"""首次登录:打开浏览器,用户手动登录,登录态自动保存到Profile目录"""
|
||||||
accounts = load_accounts()
|
target = get_account_by_id(account_id)
|
||||||
target = None
|
|
||||||
for platform_accounts in accounts.values():
|
|
||||||
for acc in platform_accounts:
|
|
||||||
if acc["id"] == account_id:
|
|
||||||
target = acc
|
|
||||||
break
|
|
||||||
|
|
||||||
if not target:
|
if not target:
|
||||||
print("ERROR:ACCOUNT_NOT_FOUND")
|
print("ERROR:ACCOUNT_NOT_FOUND")
|
||||||
|
|||||||
Reference in New Issue
Block a user