@wecode-ai/weibo-openclaw-plugin 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -23,15 +23,13 @@ OpenClaw Weibo DM channel plugin - 微博私信通道插件
|
|
|
23
23
|
#### 安装插件
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
|
|
26
|
+
openclaw plugins install @wecode-ai/weibo-openclaw-plugin
|
|
27
27
|
```
|
|
28
|
-
此命令会自动检测您的 OpenClaw 版本并安装对应版本的插件。
|
|
29
28
|
|
|
30
29
|
#### 更新插件
|
|
31
30
|
```bash
|
|
32
|
-
|
|
31
|
+
openclaw plugins update weibo-openclaw-plugin
|
|
33
32
|
```
|
|
34
|
-
此命令会自动检测您的 OpenClaw 版本并更新到对应的兼容版本。
|
|
35
33
|
|
|
36
34
|
#### 配置凭证
|
|
37
35
|
使用命令配置:
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wecode-ai/weibo-openclaw-plugin",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenClaw Weibo DM channel plugin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
8
8
|
"src",
|
|
9
|
-
"bin",
|
|
10
9
|
"index.js",
|
|
11
10
|
"index.d.ts",
|
|
12
11
|
"index.js.map",
|
|
@@ -14,9 +13,6 @@
|
|
|
14
13
|
"openclaw.plugin.json",
|
|
15
14
|
"skills"
|
|
16
15
|
],
|
|
17
|
-
"bin": {
|
|
18
|
-
"weibo-openclaw-plugin": "./bin/install.js"
|
|
19
|
-
},
|
|
20
16
|
"dependencies": {
|
|
21
17
|
"@sinclair/typebox": "0.34.48",
|
|
22
18
|
"ws": "^8.18.0",
|
|
@@ -21,16 +21,6 @@ description: |
|
|
|
21
21
|
|
|
22
22
|
1. **本地配置文件** `~/.weibo-crowd/config.json`(优先级最高)
|
|
23
23
|
2. **OpenClaw 配置文件** `~/.openclaw/openclaw.json`
|
|
24
|
-
3. **环境变量** `WEIBO_APP_ID`、`WEIBO_APP_SECRET`
|
|
25
|
-
|
|
26
|
-
### 环境变量
|
|
27
|
-
|
|
28
|
-
| 环境变量 | 说明 |
|
|
29
|
-
|----------|------|
|
|
30
|
-
| `WEIBO_APP_ID` | 开发者应用ID |
|
|
31
|
-
| `WEIBO_APP_SECRET` | 开发者应用密钥 |
|
|
32
|
-
| `WEIBO_TOKEN` | 认证令牌(可选,如果已有token) |
|
|
33
|
-
| `DEBUG` | 设置为任意值启用调试日志 |
|
|
34
24
|
|
|
35
25
|
### 可用命令
|
|
36
26
|
|
|
@@ -129,12 +119,6 @@ Token: eyJhbGciOiJIUzI1NiIs...
|
|
|
129
119
|
}
|
|
130
120
|
```
|
|
131
121
|
|
|
132
|
-
**使用环境变量方式**(兼容旧方式):
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
WEIBO_APP_ID=xxx WEIBO_APP_SECRET=xxx node scripts/weibo-crowd.js login
|
|
136
|
-
```
|
|
137
|
-
|
|
138
122
|
> **Token 自动管理**:登录成功后,Token 会被缓存到 `~/.weibo-crowd/token-cache.json`。后续执行其他命令时,脚本会自动使用缓存的 Token,并在过期前 60 秒自动刷新,无需手动管理。
|
|
139
123
|
|
|
140
124
|
### 2. 查询可互动的超话社区
|
|
@@ -189,12 +173,6 @@ node scripts/weibo-crowd.js topics
|
|
|
189
173
|
node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
|
|
190
174
|
```
|
|
191
175
|
|
|
192
|
-
也可以使用环境变量指定 Token(兼容旧方式):
|
|
193
|
-
|
|
194
|
-
```bash
|
|
195
|
-
WEIBO_TOKEN=xxx node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
|
|
196
|
-
```
|
|
197
|
-
|
|
198
176
|
**参数说明**:
|
|
199
177
|
|
|
200
178
|
| 参数 | 说明 | 必填 |
|
|
@@ -340,7 +318,7 @@ node scripts/weibo-crowd.js post --topic="超话名称" --status="视频帖子
|
|
|
340
318
|
### 5. 对微博发表评论
|
|
341
319
|
|
|
342
320
|
```bash
|
|
343
|
-
|
|
321
|
+
node scripts/weibo-crowd.js comment --id=5127468523698745 --comment="评论内容" --model="deepseek-chat"
|
|
344
322
|
```
|
|
345
323
|
|
|
346
324
|
**参数说明**:
|
|
@@ -371,7 +349,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comment --id=5127468523698745 --comm
|
|
|
371
349
|
### 6. 回复评论
|
|
372
350
|
|
|
373
351
|
```bash
|
|
374
|
-
|
|
352
|
+
node scripts/weibo-crowd.js reply --cid=5127468523698745 --id=5127468523698745 --comment="回复内容" --model="deepseek-chat"
|
|
375
353
|
```
|
|
376
354
|
|
|
377
355
|
**参数说明**:
|
|
@@ -404,7 +382,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js reply --cid=5127468523698745 --id=51
|
|
|
404
382
|
### 7. 查询评论列表
|
|
405
383
|
|
|
406
384
|
```bash
|
|
407
|
-
|
|
385
|
+
node scripts/weibo-crowd.js comments --id=5127468523698745 --count=20
|
|
408
386
|
```
|
|
409
387
|
|
|
410
388
|
**参数说明**:
|
|
@@ -455,7 +433,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comments --id=5127468523698745 --cou
|
|
|
455
433
|
### 8. 查询子评论
|
|
456
434
|
|
|
457
435
|
```bash
|
|
458
|
-
|
|
436
|
+
node scripts/weibo-crowd.js child-comments --id=5127468523698745 --count=20
|
|
459
437
|
```
|
|
460
438
|
|
|
461
439
|
**参数说明**:
|
|
@@ -504,7 +482,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js child-comments --id=5127468523698745
|
|
|
504
482
|
### 9. 刷新 Token
|
|
505
483
|
|
|
506
484
|
```bash
|
|
507
|
-
|
|
485
|
+
node scripts/weibo-crowd.js refresh
|
|
508
486
|
```
|
|
509
487
|
|
|
510
488
|
返回示例:
|
|
@@ -656,23 +634,6 @@ node scripts/weibo-crowd.js child-comments --id=COMMENT_ID --count=20 --need-roo
|
|
|
656
634
|
node scripts/weibo-crowd.js help
|
|
657
635
|
```
|
|
658
636
|
|
|
659
|
-
### 方式二:使用环境变量(兼容旧方式)
|
|
660
|
-
|
|
661
|
-
```bash
|
|
662
|
-
# 设置环境变量
|
|
663
|
-
export WEIBO_APP_ID="your_app_id"
|
|
664
|
-
export WEIBO_APP_SECRET="your_app_secret"
|
|
665
|
-
|
|
666
|
-
# 登录获取 Token
|
|
667
|
-
node scripts/weibo-crowd.js login
|
|
668
|
-
|
|
669
|
-
# 或者直接使用已有的 Token
|
|
670
|
-
export WEIBO_TOKEN="your_token"
|
|
671
|
-
|
|
672
|
-
# 执行命令
|
|
673
|
-
node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
|
|
674
|
-
```
|
|
675
|
-
|
|
676
637
|
---
|
|
677
638
|
|
|
678
639
|
## 配置文件说明
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
* 配置优先级:
|
|
22
22
|
* 1. 本地配置文件 ~/.weibo-crowd/config.json
|
|
23
23
|
* 2. OpenClaw 配置文件 ~/.openclaw/openclaw.json
|
|
24
|
-
* 3. 环境变量 WEIBO_APP_ID、WEIBO_APP_SECRET
|
|
25
24
|
*
|
|
26
25
|
* 示例:
|
|
27
26
|
* # 登录(首次使用会引导配置)
|
|
@@ -109,12 +108,15 @@ const RETRYABLE_ERRORS = new Set([50000, 50001]);
|
|
|
109
108
|
// 日志工具
|
|
110
109
|
// ============================================================================
|
|
111
110
|
|
|
111
|
+
// 调试模式开关(默认关闭)
|
|
112
|
+
const DEBUG_MODE = false;
|
|
113
|
+
|
|
112
114
|
const Logger = {
|
|
113
115
|
info: (msg) => console.log(`[INFO] ${msg}`),
|
|
114
116
|
success: (msg) => console.log(`[SUCCESS] ✓ ${msg}`),
|
|
115
117
|
warn: (msg) => console.warn(`[WARN] ⚠ ${msg}`),
|
|
116
118
|
error: (msg) => console.error(`[ERROR] ✗ ${msg}`),
|
|
117
|
-
debug: (msg) =>
|
|
119
|
+
debug: (msg) => DEBUG_MODE && console.log(`[DEBUG] ${msg}`)
|
|
118
120
|
};
|
|
119
121
|
|
|
120
122
|
// ============================================================================
|
|
@@ -189,8 +191,8 @@ function decrypt(encryptedText) {
|
|
|
189
191
|
*/
|
|
190
192
|
async function loadConfig() {
|
|
191
193
|
const config = {
|
|
192
|
-
appId:
|
|
193
|
-
appSecret:
|
|
194
|
+
appId: undefined,
|
|
195
|
+
appSecret: undefined
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
// 尝试读取 OpenClaw 配置
|
|
@@ -739,18 +741,11 @@ async function handleLoginCommand() {
|
|
|
739
741
|
}
|
|
740
742
|
|
|
741
743
|
/**
|
|
742
|
-
* 获取有效的 Token
|
|
744
|
+
* 获取有效的 Token(自动从配置获取)
|
|
743
745
|
* @returns {Promise<string>} Token
|
|
744
746
|
*/
|
|
745
747
|
async function getValidTokenForCommand() {
|
|
746
|
-
//
|
|
747
|
-
const envToken = process.env.WEIBO_TOKEN;
|
|
748
|
-
if (envToken) {
|
|
749
|
-
Logger.debug('使用环境变量中的 Token');
|
|
750
|
-
return envToken;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// 尝试从配置获取 Token
|
|
748
|
+
// 从配置获取 Token
|
|
754
749
|
const config = await loadConfig();
|
|
755
750
|
|
|
756
751
|
if (!config.appId || !config.appSecret) {
|
|
@@ -804,13 +799,6 @@ function printHelp() {
|
|
|
804
799
|
配置优先级:
|
|
805
800
|
1. 本地配置文件 ~/.weibo-crowd/config.json
|
|
806
801
|
2. OpenClaw 配置文件 ~/.openclaw/openclaw.json
|
|
807
|
-
3. 环境变量 WEIBO_APP_ID、WEIBO_APP_SECRET
|
|
808
|
-
|
|
809
|
-
环境变量:
|
|
810
|
-
WEIBO_APP_ID 开发者应用ID
|
|
811
|
-
WEIBO_APP_SECRET 开发者应用密钥
|
|
812
|
-
WEIBO_TOKEN 认证令牌(可选,如果已有token)
|
|
813
|
-
DEBUG 设置为任意值启用调试日志
|
|
814
802
|
|
|
815
803
|
选项:
|
|
816
804
|
--topic=<name> 超话社区中文名(必填,可通过 topics 命令查询可用社区)
|
|
@@ -862,9 +850,6 @@ function printHelp() {
|
|
|
862
850
|
|
|
863
851
|
# 查询子评论
|
|
864
852
|
node weibo-crowd.js child-comments --id=5127468523698745 --count=20
|
|
865
|
-
|
|
866
|
-
# 使用环境变量(兼容旧方式)
|
|
867
|
-
WEIBO_TOKEN=xxx node weibo-crowd.js timeline --topic="超话名称"
|
|
868
853
|
`);
|
|
869
854
|
}
|
|
870
855
|
|
|
@@ -21,16 +21,6 @@ description: |
|
|
|
21
21
|
|
|
22
22
|
1. **本地配置文件** `~/.weibo-video/config.json`(优先级最高)
|
|
23
23
|
2. **OpenClaw 配置文件** `~/.openclaw/openclaw.json`
|
|
24
|
-
3. **环境变量** `WEIBO_APP_ID`、`WEIBO_APP_SECRET`
|
|
25
|
-
|
|
26
|
-
### 环境变量
|
|
27
|
-
|
|
28
|
-
| 环境变量 | 说明 |
|
|
29
|
-
|----------|------|
|
|
30
|
-
| `WEIBO_APP_ID` | 开发者应用ID |
|
|
31
|
-
| `WEIBO_APP_SECRET` | 开发者应用密钥 |
|
|
32
|
-
| `WEIBO_TOKEN` | 认证令牌(可选,如果已有token) |
|
|
33
|
-
| `DEBUG` | 设置为任意值启用调试日志 |
|
|
34
24
|
|
|
35
25
|
### 可用命令
|
|
36
26
|
|
|
@@ -97,12 +87,6 @@ Token: eyJhbGciOiJIUzI1NiIs...
|
|
|
97
87
|
}
|
|
98
88
|
```
|
|
99
89
|
|
|
100
|
-
**使用环境变量方式**(兼容旧方式):
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
WEIBO_APP_ID=xxx WEIBO_APP_SECRET=xxx node scripts/weibo-video.js login
|
|
104
|
-
```
|
|
105
|
-
|
|
106
90
|
> **Token 自动管理**:登录成功后,Token 会被缓存到 `~/.weibo-video/token-cache.json`。后续执行其他命令时,脚本会自动使用缓存的 Token,并在过期前 60 秒自动刷新,无需手动管理。
|
|
107
91
|
|
|
108
92
|
### 2. 上传视频
|
|
@@ -113,12 +97,6 @@ WEIBO_APP_ID=xxx WEIBO_APP_SECRET=xxx node scripts/weibo-video.js login
|
|
|
113
97
|
node scripts/weibo-video.js upload --file="/path/to/video.mp4"
|
|
114
98
|
```
|
|
115
99
|
|
|
116
|
-
也可以使用环境变量指定 Token(兼容旧方式):
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
WEIBO_TOKEN=xxx node scripts/weibo-video.js upload --file="/path/to/video.mp4"
|
|
120
|
-
```
|
|
121
|
-
|
|
122
100
|
**参数说明**:
|
|
123
101
|
|
|
124
102
|
| 参数 | 说明 | 必填 |
|
|
@@ -337,23 +315,6 @@ node scripts/weibo-video.js upload --file="/path/to/video.mp4" --video-type=norm
|
|
|
337
315
|
node scripts/weibo-video.js help
|
|
338
316
|
```
|
|
339
317
|
|
|
340
|
-
### 方式二:使用环境变量(兼容旧方式)
|
|
341
|
-
|
|
342
|
-
```bash
|
|
343
|
-
# 设置环境变量
|
|
344
|
-
export WEIBO_APP_ID="your_app_id"
|
|
345
|
-
export WEIBO_APP_SECRET="your_app_secret"
|
|
346
|
-
|
|
347
|
-
# 登录获取 Token
|
|
348
|
-
node scripts/weibo-video.js login
|
|
349
|
-
|
|
350
|
-
# 或者直接使用已有的 Token
|
|
351
|
-
export WEIBO_TOKEN="your_token"
|
|
352
|
-
|
|
353
|
-
# 执行命令
|
|
354
|
-
node scripts/weibo-video.js upload --file="/path/to/video.mp4"
|
|
355
|
-
```
|
|
356
|
-
|
|
357
318
|
---
|
|
358
319
|
|
|
359
320
|
## 配置文件说明
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* 配置优先级:
|
|
15
15
|
* 1. 本地配置文件 ~/.weibo-video/config.json
|
|
16
16
|
* 2. OpenClaw 配置文件 ~/.openclaw/openclaw.json
|
|
17
|
-
* 3. 环境变量 WEIBO_APP_ID、WEIBO_APP_SECRET
|
|
18
17
|
*
|
|
19
18
|
* 示例:
|
|
20
19
|
* # 登录(首次使用会引导配置)
|
|
@@ -102,12 +101,15 @@ const RETRYABLE_ERRORS = new Set([50000, 50001]);
|
|
|
102
101
|
// 日志工具
|
|
103
102
|
// ============================================================================
|
|
104
103
|
|
|
104
|
+
// 调试模式开关(默认关闭)
|
|
105
|
+
const DEBUG_MODE = false;
|
|
106
|
+
|
|
105
107
|
const Logger = {
|
|
106
108
|
info: (msg) => console.log(`[INFO] ${msg}`),
|
|
107
109
|
success: (msg) => console.log(`[SUCCESS] ✓ ${msg}`),
|
|
108
110
|
warn: (msg) => console.warn(`[WARN] ⚠ ${msg}`),
|
|
109
111
|
error: (msg) => console.error(`[ERROR] ✗ ${msg}`),
|
|
110
|
-
debug: (msg) =>
|
|
112
|
+
debug: (msg) => DEBUG_MODE && console.log(`[DEBUG] ${msg}`),
|
|
111
113
|
progress: (current, total, msg) => {
|
|
112
114
|
const percent = Math.round((current / total) * 100);
|
|
113
115
|
const bar = '█'.repeat(Math.floor(percent / 5)) + '░'.repeat(20 - Math.floor(percent / 5));
|
|
@@ -188,8 +190,8 @@ function decrypt(encryptedText) {
|
|
|
188
190
|
*/
|
|
189
191
|
async function loadConfig() {
|
|
190
192
|
const config = {
|
|
191
|
-
appId:
|
|
192
|
-
appSecret:
|
|
193
|
+
appId: undefined,
|
|
194
|
+
appSecret: undefined
|
|
193
195
|
};
|
|
194
196
|
|
|
195
197
|
// 尝试读取 OpenClaw 配置
|
|
@@ -829,18 +831,11 @@ async function handleLoginCommand() {
|
|
|
829
831
|
}
|
|
830
832
|
|
|
831
833
|
/**
|
|
832
|
-
* 获取有效的 Token
|
|
834
|
+
* 获取有效的 Token(自动从配置获取)
|
|
833
835
|
* @returns {Promise<string>} Token
|
|
834
836
|
*/
|
|
835
837
|
async function getValidTokenForCommand() {
|
|
836
|
-
//
|
|
837
|
-
const envToken = process.env.WEIBO_TOKEN;
|
|
838
|
-
if (envToken) {
|
|
839
|
-
Logger.debug('使用环境变量中的 Token');
|
|
840
|
-
return envToken;
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
// 尝试从配置获取 Token
|
|
838
|
+
// 从配置获取 Token
|
|
844
839
|
const config = await loadConfig();
|
|
845
840
|
|
|
846
841
|
if (!config.appId || !config.appSecret) {
|
|
@@ -887,13 +882,6 @@ function printHelp() {
|
|
|
887
882
|
配置优先级:
|
|
888
883
|
1. 本地配置文件 ~/.weibo-video/config.json
|
|
889
884
|
2. OpenClaw 配置文件 ~/.openclaw/openclaw.json
|
|
890
|
-
3. 环境变量 WEIBO_APP_ID、WEIBO_APP_SECRET
|
|
891
|
-
|
|
892
|
-
环境变量:
|
|
893
|
-
WEIBO_APP_ID 开发者应用ID
|
|
894
|
-
WEIBO_APP_SECRET 开发者应用密钥
|
|
895
|
-
WEIBO_TOKEN 认证令牌(可选,如果已有token)
|
|
896
|
-
DEBUG 设置为任意值启用调试日志
|
|
897
885
|
|
|
898
886
|
选项:
|
|
899
887
|
--file=<path> 视频文件路径(必填)
|
|
@@ -908,9 +896,6 @@ function printHelp() {
|
|
|
908
896
|
|
|
909
897
|
# 上传视频(自动使用缓存的 Token)
|
|
910
898
|
node weibo-video.js upload --file="/path/to/video.mp4"
|
|
911
|
-
|
|
912
|
-
# 使用环境变量(兼容旧方式)
|
|
913
|
-
WEIBO_TOKEN=xxx node weibo-video.js upload --file="/path/to/video.mp4"
|
|
914
899
|
`);
|
|
915
900
|
}
|
|
916
901
|
|
package/bin/install.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 自动检测 openclaw 版本并安装/更新对应版本的 weibo-openclaw-plugin
|
|
5
|
-
*
|
|
6
|
-
* 用法:
|
|
7
|
-
* npx @wecode-ai/weibo-openclaw-plugin # 安装插件
|
|
8
|
-
* npx @wecode-ai/weibo-openclaw-plugin update # 更新插件
|
|
9
|
-
*
|
|
10
|
-
* 版本兼容性:
|
|
11
|
-
* - OpenClaw >= 2026.3.23: 安装最新版本 (2.1.0+)
|
|
12
|
-
* - OpenClaw < 2026.3.23: 安装 2.0.1 版本
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { execSync, spawn } from 'child_process';
|
|
16
|
-
|
|
17
|
-
const PACKAGE_NAME = '@wecode-ai/weibo-openclaw-plugin';
|
|
18
|
-
const PLUGIN_NAME = 'weibo-openclaw-plugin';
|
|
19
|
-
const VERSION_THRESHOLD = '2026.3.23';
|
|
20
|
-
const LEGACY_VERSION = '2.0.1';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 比较两个版本号
|
|
24
|
-
* @param {string} v1
|
|
25
|
-
* @param {string} v2
|
|
26
|
-
* @returns {number} -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2
|
|
27
|
-
*/
|
|
28
|
-
function compareVersions(v1, v2) {
|
|
29
|
-
const parts1 = v1.split('.').map(Number);
|
|
30
|
-
const parts2 = v2.split('.').map(Number);
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
33
|
-
const p1 = parts1[i] || 0;
|
|
34
|
-
const p2 = parts2[i] || 0;
|
|
35
|
-
if (p1 < p2) return -1;
|
|
36
|
-
if (p1 > p2) return 1;
|
|
37
|
-
}
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 获取 openclaw 版本
|
|
43
|
-
* @returns {string|null}
|
|
44
|
-
*/
|
|
45
|
-
function getOpenclawVersion() {
|
|
46
|
-
try {
|
|
47
|
-
const output = execSync('openclaw --version', {
|
|
48
|
-
encoding: 'utf8',
|
|
49
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
50
|
-
});
|
|
51
|
-
// 输出格式可能是 "openclaw 2026.3.23" 或 "2026.3.23"
|
|
52
|
-
const match = output.match(/(\d+\.\d+\.\d+)/);
|
|
53
|
-
return match ? match[1] : null;
|
|
54
|
-
} catch {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 执行 openclaw plugins 命令
|
|
61
|
-
* @param {string} action - 'install' 或 'update'
|
|
62
|
-
* @param {string} packageSpec - 包名或包名@版本
|
|
63
|
-
*/
|
|
64
|
-
function runPluginCommand(action, packageSpec) {
|
|
65
|
-
const actionText = action === 'install' ? '安装' : '更新';
|
|
66
|
-
const actionEmoji = action === 'install' ? '📦' : '🔄';
|
|
67
|
-
|
|
68
|
-
console.log(`\n${actionEmoji} 正在${actionText} ${packageSpec}...\n`);
|
|
69
|
-
|
|
70
|
-
const args = action === 'update'
|
|
71
|
-
? ['plugins', 'update', PLUGIN_NAME]
|
|
72
|
-
: ['plugins', 'install', packageSpec];
|
|
73
|
-
|
|
74
|
-
const child = spawn('openclaw', args, {
|
|
75
|
-
stdio: 'inherit',
|
|
76
|
-
shell: true
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
child.on('close', (code) => {
|
|
80
|
-
if (code === 0) {
|
|
81
|
-
console.log(`\n✅ ${packageSpec} ${actionText}成功!`);
|
|
82
|
-
} else {
|
|
83
|
-
console.error(`\n❌ ${actionText}失败,退出码: ${code}`);
|
|
84
|
-
process.exit(code);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
child.on('error', (err) => {
|
|
89
|
-
console.error(`\n❌ ${actionText}失败: ${err.message}`);
|
|
90
|
-
process.exit(1);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 显示帮助信息
|
|
96
|
-
*/
|
|
97
|
-
function showHelp() {
|
|
98
|
-
console.log(`
|
|
99
|
-
微博 OpenClaw 插件安装工具
|
|
100
|
-
|
|
101
|
-
用法:
|
|
102
|
-
npx ${PACKAGE_NAME} 安装插件(自动检测版本)
|
|
103
|
-
npx ${PACKAGE_NAME} update 更新插件到最新兼容版本
|
|
104
|
-
npx ${PACKAGE_NAME} help 显示此帮助信息
|
|
105
|
-
|
|
106
|
-
版本兼容性:
|
|
107
|
-
OpenClaw >= ${VERSION_THRESHOLD}: 安装最新版本的插件
|
|
108
|
-
OpenClaw < ${VERSION_THRESHOLD}: 安装 ${LEGACY_VERSION} 版本的插件
|
|
109
|
-
`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function main() {
|
|
113
|
-
const args = process.argv.slice(2);
|
|
114
|
-
const command = args[0]?.toLowerCase();
|
|
115
|
-
|
|
116
|
-
// 处理帮助命令
|
|
117
|
-
if (command === 'help' || command === '--help' || command === '-h') {
|
|
118
|
-
showHelp();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 检测 OpenClaw 版本
|
|
123
|
-
console.log('🔍 检测 OpenClaw 版本...');
|
|
124
|
-
|
|
125
|
-
const version = getOpenclawVersion();
|
|
126
|
-
|
|
127
|
-
if (!version) {
|
|
128
|
-
console.error('❌ 未检测到 OpenClaw,请先安装 OpenClaw。');
|
|
129
|
-
console.error(' 安装方法: npm install -g openclaw');
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
console.log(` 检测到 OpenClaw 版本: ${version}`);
|
|
134
|
-
|
|
135
|
-
const isNewVersion = compareVersions(version, VERSION_THRESHOLD) >= 0;
|
|
136
|
-
|
|
137
|
-
// 处理 update 命令
|
|
138
|
-
if (command === 'update') {
|
|
139
|
-
if (isNewVersion) {
|
|
140
|
-
console.log(` 版本 >= ${VERSION_THRESHOLD},将更新到最新版本的插件`);
|
|
141
|
-
runPluginCommand('update', PACKAGE_NAME);
|
|
142
|
-
} else {
|
|
143
|
-
console.log(` 版本 < ${VERSION_THRESHOLD},将更新到 ${LEGACY_VERSION} 版本的插件`);
|
|
144
|
-
// 对于旧版本,使用 install 命令来"更新"到指定版本
|
|
145
|
-
runPluginCommand('install', `${PACKAGE_NAME}@${LEGACY_VERSION}`);
|
|
146
|
-
}
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 默认:安装命令
|
|
151
|
-
if (isNewVersion) {
|
|
152
|
-
console.log(` 版本 >= ${VERSION_THRESHOLD},将安装最新版本的插件`);
|
|
153
|
-
runPluginCommand('install', PACKAGE_NAME);
|
|
154
|
-
} else {
|
|
155
|
-
console.log(` 版本 < ${VERSION_THRESHOLD},将安装 ${LEGACY_VERSION} 版本的插件`);
|
|
156
|
-
runPluginCommand('install', `${PACKAGE_NAME}@${LEGACY_VERSION}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
main();
|