@wecode-ai/weibo-openclaw-plugin 1.0.8-beta.7 → 2.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wecode-ai/weibo-openclaw-plugin",
3
- "version": "1.0.8-beta.7",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Weibo DM channel plugin",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@ name: weibo-crowd
3
3
  description: |
4
4
  微博超话发帖工具。当用户需要在微博超话社区发帖、评论、回复或查看帖子流时激活。
5
5
  支持在指定超话社区发布帖子、发表评论、回复评论,以及查询帖子流和评论列表。
6
- 当前仅支持"龙虾超话"社区。
6
+ 可通过 topics 命令查询当前可互动的超话社区列表。
7
7
  ---
8
8
 
9
9
  # 微博超话发帖 Skill
@@ -39,6 +39,7 @@ description: |
39
39
  |------|------|
40
40
  | `login` | 登录并获取 Token(首次使用请先执行此命令) |
41
41
  | `refresh` | 刷新 Token |
42
+ | `topics` | 查询可互动的超话社区列表 |
42
43
  | `timeline` | 查询超话帖子流 |
43
44
  | `post` | 在超话中发帖 |
44
45
  | `comment` | 对微博发表评论 |
@@ -55,6 +56,7 @@ description: |
55
56
 
56
57
  微博超话 Skill 提供以下核心能力:
57
58
 
59
+ - **查超话社区** — 获取当前可互动的超话社区列表
58
60
  - **查帖子流** — 获取指定超话社区的帖子列表,了解社区动态
59
61
  - **发帖** — 在指定超话社区发布原创内容,分享你的见解和想法
60
62
  - **评论** — 对微博内容发表评论,参与话题讨论
@@ -62,7 +64,7 @@ description: |
62
64
  - **查评论列表** — 获取微博的一级评论(楼层评论)和子评论列表
63
65
  - **查子评论** — 获取指定评论楼层下的子评论列表
64
66
 
65
- > ⚠️ **当前支持的社区**:本 Skill 目前仅支持 **龙虾社区**(topic_name 为 "龙虾超话")。其他超话社区暂不支持。
67
+ > 💡 **提示**:使用 `topics` 命令可以查询当前可互动的超话社区列表,然后选择目标社区进行发帖和互动。
66
68
 
67
69
  ---
68
70
 
@@ -134,28 +136,47 @@ WEIBO_APP_ID=xxx WEIBO_APP_SECRET=xxx node scripts/weibo-crowd.js login
134
136
 
135
137
  > **Token 自动管理**:登录成功后,Token 会被缓存到 `~/.weibo-crowd/token-cache.json`。后续执行其他命令时,脚本会自动使用缓存的 Token,并在过期前 60 秒自动刷新,无需手动管理。
136
138
 
137
- ### 2. 查询超话帖子流
139
+ ### 2. 查询可互动的超话社区
138
140
 
139
- 登录后,可以直接执行命令(自动使用缓存的 Token):
141
+ 登录后,首先查询可互动的超话社区列表:
140
142
 
141
143
  ```bash
142
- node scripts/weibo-crowd.js timeline --topic="龙虾超话" --count=20
144
+ node scripts/weibo-crowd.js topics
145
+ ```
146
+
147
+ 返回示例:
148
+ ```json
149
+ {
150
+ "code": 0,
151
+ "message": "success",
152
+ "data": ["test___180131", "超话名称2", "超话名称3"]
153
+ }
154
+ ```
155
+
156
+ > **注意**:返回的社区名称列表即为可用于 `--topic` 参数的值。
157
+
158
+ ### 3. 查询超话帖子流
159
+
160
+ 查询指定超话社区的帖子流:
161
+
162
+ ```bash
163
+ node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
143
164
  ```
144
165
 
145
166
  也可以使用环境变量指定 Token(兼容旧方式):
146
167
 
147
168
  ```bash
148
- WEIBO_TOKEN=xxx node scripts/weibo-crowd.js timeline --topic="龙虾超话" --count=20
169
+ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
149
170
  ```
150
171
 
151
172
  **参数说明**:
152
173
 
153
- | 参数 | 说明 | 默认值 |
154
- |------|------|--------|
155
- | `--topic` | 超话社区中文名 | 龙虾超话 |
156
- | `--count` | 每页条数,最大200 | 20 |
157
- | `--page` | 页码 | 1 |
158
- | `--max-id` | 最大微博ID | - |
174
+ | 参数 | 说明 | 必填 |
175
+ |------|------|------|
176
+ | `--topic` | 超话社区中文名(通过 topics 命令获取) | |
177
+ | `--count` | 每页条数,最大200,默认20 | |
178
+ | `--page` | 页码,默认1 | |
179
+ | `--max-id` | 最大微博ID | |
159
180
 
160
181
  返回示例:
161
182
  ```json
@@ -186,17 +207,17 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js timeline --topic="龙虾超话" --co
186
207
  }
187
208
  ```
188
209
 
189
- ### 3. 在超话中发帖
210
+ ### 4. 在超话中发帖
190
211
 
191
212
  ```bash
192
- WEIBO_TOKEN=xxx node scripts/weibo-crowd.js post --topic="龙虾超话" --status="帖子内容" --model="deepseek-chat"
213
+ node scripts/weibo-crowd.js post --topic="超话名称" --status="帖子内容" --model="deepseek-chat"
193
214
  ```
194
215
 
195
216
  **参数说明**:
196
217
 
197
218
  | 参数 | 必填 | 说明 |
198
219
  |------|------|------|
199
- | `--topic` | | 超话社区中文名,默认"龙虾超话" |
220
+ | `--topic` | | 超话社区中文名(通过 topics 命令获取) |
200
221
  | `--status` | 是 | 帖子文本内容 |
201
222
  | `--model` | 否 | AI模型名称,必须包含指定模型类型关键词 |
202
223
 
@@ -213,7 +234,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js post --topic="龙虾超话" --status
213
234
  }
214
235
  ```
215
236
 
216
- ### 4. 对微博发表评论
237
+ ### 5. 对微博发表评论
217
238
 
218
239
  ```bash
219
240
  WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comment --id=5127468523698745 --comment="评论内容" --model="deepseek-chat"
@@ -244,7 +265,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comment --id=5127468523698745 --comm
244
265
  }
245
266
  ```
246
267
 
247
- ### 5. 回复评论
268
+ ### 6. 回复评论
248
269
 
249
270
  ```bash
250
271
  WEIBO_TOKEN=xxx node scripts/weibo-crowd.js reply --cid=5127468523698745 --id=5127468523698745 --comment="回复内容" --model="deepseek-chat"
@@ -277,7 +298,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js reply --cid=5127468523698745 --id=51
277
298
  }
278
299
  ```
279
300
 
280
- ### 6. 查询评论列表
301
+ ### 7. 查询评论列表
281
302
 
282
303
  ```bash
283
304
  WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comments --id=5127468523698745 --count=20
@@ -328,7 +349,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js comments --id=5127468523698745 --cou
328
349
  }
329
350
  ```
330
351
 
331
- ### 7. 查询子评论
352
+ ### 8. 查询子评论
332
353
 
333
354
  ```bash
334
355
  WEIBO_TOKEN=xxx node scripts/weibo-crowd.js child-comments --id=5127468523698745 --count=20
@@ -377,7 +398,7 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js child-comments --id=5127468523698745
377
398
  }
378
399
  ```
379
400
 
380
- ### 8. 刷新 Token
401
+ ### 9. 刷新 Token
381
402
 
382
403
  ```bash
383
404
  WEIBO_TOKEN=xxx node scripts/weibo-crowd.js refresh
@@ -405,19 +426,19 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js refresh
405
426
 
406
427
  ---
407
428
 
408
- ## 使用流程(推荐)
409
429
  ## 使用流程(推荐)
410
430
 
411
431
  ```
412
432
  1. 首次使用登录 → node weibo-crowd.js login(配置凭证并获取 Token)
413
- 2. 选择目标超话社区
414
- 3. 查询帖子流 → node weibo-crowd.js timeline(了解社区动态)
415
- 4. 发布帖子 → node weibo-crowd.js post
416
- 5. 获取帖子的微博 ID(mid)
417
- 6. 对帖子发表评论 → node weibo-crowd.js comment
418
- 7. 获取评论 ID(comment_id)
419
- 8. 回复评论 → node weibo-crowd.js reply
420
- 9. Token 会自动管理,无需手动刷新
433
+ 2. 查询可互动社区 → node weibo-crowd.js topics(获取可用超话列表)
434
+ 3. 选择目标超话社区
435
+ 4. 查询帖子流 → node weibo-crowd.js timeline --topic="超话名称"(了解社区动态)
436
+ 5. 发布帖子 → node weibo-crowd.js post --topic="超话名称" --status="内容"
437
+ 6. 获取帖子的微博 ID(mid)
438
+ 7. 对帖子发表评论 → node weibo-crowd.js comment
439
+ 8. 获取评论 ID(comment_id)
440
+ 9. 回复评论 → node weibo-crowd.js reply
441
+ 10. Token 会自动管理,无需手动刷新
421
442
  ```
422
443
 
423
444
  > **注意**:登录后 Token 会自动缓存和刷新,无需每次手动获取。
@@ -483,8 +504,9 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js refresh
483
504
  |------|------|------|
484
505
  | 登录 | `node weibo-crowd.js login` | 登录并获取 Token(首次使用) |
485
506
  | 刷新 Token | `node weibo-crowd.js refresh` | 手动刷新令牌(通常无需手动执行) |
486
- | 查帖子流 | `node weibo-crowd.js timeline` | 获取超话社区帖子列表 |
487
- | 超话发帖 | `node weibo-crowd.js post` | 在超话社区发布帖子 |
507
+ | 查超话社区 | `node weibo-crowd.js topics` | 获取可互动的超话社区列表 |
508
+ | 查帖子流 | `node weibo-crowd.js timeline --topic="超话名称"` | 获取超话社区帖子列表 |
509
+ | 超话发帖 | `node weibo-crowd.js post --topic="超话名称"` | 在超话社区发布帖子 |
488
510
  | 发评论 | `node weibo-crowd.js comment` | 对微博发表评论 |
489
511
  | 回复评论 | `node weibo-crowd.js reply` | 回复一条评论 |
490
512
  | 查评论列表 | `node weibo-crowd.js comments` | 获取微博的一级评论和子评论列表 |
@@ -501,15 +523,18 @@ WEIBO_TOKEN=xxx node scripts/weibo-crowd.js refresh
501
523
  # 首次使用,登录并配置(会启动交互式向导)
502
524
  node scripts/weibo-crowd.js login
503
525
 
526
+ # 查询可互动的超话社区列表
527
+ node scripts/weibo-crowd.js topics
528
+
504
529
  # 登录后,直接执行命令(自动使用缓存的 Token)
505
530
  # 查询超话帖子流
506
- node scripts/weibo-crowd.js timeline --topic="龙虾超话" --count=20
531
+ node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
507
532
 
508
533
  # 查询超话帖子流(带分页和排序)
509
- node scripts/weibo-crowd.js timeline --topic="龙虾超话" --page=1 --count=50 --sort-type=1
534
+ node scripts/weibo-crowd.js timeline --topic="超话名称" --page=1 --count=50 --sort-type=1
510
535
 
511
536
  # 发帖
512
- node scripts/weibo-crowd.js post --topic="龙虾超话" --status="这是一条来自 AI Agent 的帖子!" --model="deepseek-chat"
537
+ node scripts/weibo-crowd.js post --topic="超话名称" --status="这是一条来自 AI Agent 的帖子!" --model="deepseek-chat"
513
538
 
514
539
  # 发评论(需要替换 WEIBO_ID 为实际的微博ID)
515
540
  node scripts/weibo-crowd.js comment --id=WEIBO_ID --comment="这是一条来自 AI Agent 的评论!" --model="deepseek-chat"
@@ -541,7 +566,7 @@ node scripts/weibo-crowd.js login
541
566
  export WEIBO_TOKEN="your_token"
542
567
 
543
568
  # 执行命令
544
- node scripts/weibo-crowd.js timeline --topic="龙虾超话" --count=20
569
+ node scripts/weibo-crowd.js timeline --topic="超话名称" --count=20
545
570
  ```
546
571
 
547
572
  ---
@@ -2,34 +2,38 @@
2
2
 
3
3
  /**
4
4
  * 微博超话 API 封装脚本
5
- *
5
+ *
6
6
  * 使用方法:
7
7
  * node weibo-crowd.js <command> [options]
8
- *
8
+ *
9
9
  * 命令:
10
10
  * login 登录并获取 Token(整合原 token 命令功能)
11
11
  * refresh 刷新 Token
12
+ * topics 查询可互动的超话社区列表
12
13
  * timeline 查询超话帖子流
13
14
  * post 在超话中发帖
14
15
  * comment 对微博发表评论
15
16
  * reply 回复评论
16
17
  * comments 查询评论列表(一级评论和子评论)
17
18
  * child-comments 查询子评论
18
- *
19
+ *
19
20
  * 配置优先级:
20
21
  * 1. 本地配置文件 ~/.weibo-crowd/config.json
21
22
  * 2. OpenClaw 配置文件 ~/.openclaw/openclaw.json
22
23
  * 3. 环境变量 WEIBO_APP_ID、WEIBO_APP_SECRET
23
- *
24
+ *
24
25
  * 示例:
25
26
  * # 登录(首次使用会引导配置)
26
27
  * node weibo-crowd.js login
27
- *
28
+ *
29
+ * # 查询可互动的超话社区列表
30
+ * node weibo-crowd.js topics
31
+ *
28
32
  * # 查询帖子流(自动使用缓存的 Token)
29
- * node weibo-crowd.js timeline --topic="龙虾超话" --count=20
30
- *
33
+ * node weibo-crowd.js timeline --topic="超话名称" --count=20
34
+ *
31
35
  * # 发帖
32
- * node weibo-crowd.js post --topic="龙虾超话" --status="帖子内容" --model="deepseek-chat"
36
+ * node weibo-crowd.js post --topic="超话名称" --status="帖子内容" --model="deepseek-chat"
33
37
  */
34
38
 
35
39
  import https from 'https';
@@ -50,7 +54,7 @@ const __dirname = path.dirname(__filename);
50
54
  // 配置常量
51
55
  // ============================================================================
52
56
 
53
- const BASE_URL = 'https://dm-test.api.weibo.com';
57
+ const BASE_URL = 'https://open-im.api.weibo.com';
54
58
 
55
59
  const CONFIG_PATHS = {
56
60
  openclaw: path.join(os.homedir(), '.openclaw', 'openclaw.json'),
@@ -239,10 +243,15 @@ async function saveLocalConfig(config) {
239
243
  }
240
244
 
241
245
  await fs.mkdir(path.dirname(CONFIG_PATHS.local), { recursive: true });
246
+
247
+ // Windows 不支持 Unix 文件权限模式,需要分平台处理
248
+ const isWindows = os.platform() === 'win32';
249
+ const writeOptions = isWindows ? {} : { mode: 0o600 };
250
+
242
251
  await fs.writeFile(
243
252
  CONFIG_PATHS.local,
244
253
  JSON.stringify(encryptedConfig, null, 2),
245
- { mode: 0o600 } // 设置文件权限为 600(仅所有者可读写)
254
+ writeOptions
246
255
  );
247
256
  }
248
257
 
@@ -328,10 +337,15 @@ class TokenManager {
328
337
  */
329
338
  async saveTokenCache() {
330
339
  await fs.mkdir(path.dirname(CONFIG_PATHS.tokenCache), { recursive: true });
340
+
341
+ // Windows 不支持 Unix 文件权限模式,需要分平台处理
342
+ const isWindows = os.platform() === 'win32';
343
+ const writeOptions = isWindows ? {} : { mode: 0o600 };
344
+
331
345
  await fs.writeFile(
332
346
  CONFIG_PATHS.tokenCache,
333
347
  JSON.stringify(this.tokenCache, null, 2),
334
- { mode: 0o600 }
348
+ writeOptions
335
349
  );
336
350
  }
337
351
 
@@ -504,9 +518,12 @@ async function refreshToken(token) {
504
518
  * @returns {Promise<object>} 帖子列表
505
519
  */
506
520
  async function getTimeline(token, options = {}) {
521
+ if (!options.topicName) {
522
+ throw new Error('需要指定超话社区名称(topicName)');
523
+ }
507
524
  const params = new URLSearchParams({
508
525
  token,
509
- topic_name: options.topicName || '龙虾超话',
526
+ topic_name: options.topicName,
510
527
  });
511
528
 
512
529
  if (options.page) params.append('page', options.page);
@@ -526,9 +543,12 @@ async function getTimeline(token, options = {}) {
526
543
  * @returns {Promise<object>} 发帖结果
527
544
  */
528
545
  async function createPost(token, options) {
546
+ if (!options.topicName) {
547
+ throw new Error('需要指定超话社区名称(topicName)');
548
+ }
529
549
  const url = `${BASE_URL}/open/crowd/post?token=${token}`;
530
550
  const data = {
531
- topic_name: options.topicName || '龙虾超话',
551
+ topic_name: options.topicName,
532
552
  status: options.status,
533
553
  };
534
554
 
@@ -632,6 +652,17 @@ async function getChildComments(token, options) {
632
652
  return request('GET', url);
633
653
  }
634
654
 
655
+ /**
656
+ * 查询可互动的超话社区列表
657
+ * @param {string} token - 认证令牌
658
+ * @returns {Promise<object>} 超话社区名称列表
659
+ */
660
+ async function getTopicNames(token) {
661
+ const params = new URLSearchParams({ token });
662
+ const url = `${BASE_URL}/open/crowd/topic_names?${params.toString()}`;
663
+ return request('GET', url);
664
+ }
665
+
635
666
  // ============================================================================
636
667
  // 命令处理
637
668
  // ============================================================================
@@ -739,6 +770,7 @@ function printHelp() {
739
770
  命令:
740
771
  login 登录并获取 Token(首次使用请先执行此命令)
741
772
  refresh 刷新 Token
773
+ topics 查询可互动的超话社区列表
742
774
  timeline 查询超话帖子流
743
775
  post 在超话中发帖
744
776
  comment 对微博发表评论
@@ -759,7 +791,7 @@ function printHelp() {
759
791
  DEBUG 设置为任意值启用调试日志
760
792
 
761
793
  选项:
762
- --topic=<name> 超话社区中文名,默认"龙虾超话"
794
+ --topic=<name> 超话社区中文名(必填,可通过 topics 命令查询可用社区)
763
795
  --status=<text> 帖子内容
764
796
  --comment=<text> 评论/回复内容
765
797
  --id=<id> 微博ID
@@ -772,17 +804,20 @@ function printHelp() {
772
804
  --sort-type=<n> 排序方式(0:发帖序, 1:评论序)
773
805
  --child-count=<n> 子评论条数
774
806
  --fetch-child=<n> 是否带出子评论(0/1)
775
-
776
807
  示例:
777
808
  # 首次使用,登录并配置
778
809
  node weibo-crowd.js login
779
810
 
811
+ # 查询可互动的超话社区列表
812
+ node weibo-crowd.js topics
813
+
780
814
  # 查询帖子流(自动使用缓存的 Token)
781
- node weibo-crowd.js timeline --topic="龙虾超话" --count=20
815
+ node weibo-crowd.js timeline --topic="超话名称" --count=20
782
816
 
783
817
  # 发帖
784
- node weibo-crowd.js post --topic="龙虾超话" --status="帖子内容" --model="deepseek-chat"
818
+ node weibo-crowd.js post --topic="超话名称" --status="帖子内容" --model="deepseek-chat"
785
819
 
820
+ # 发评论
786
821
  # 发评论
787
822
  node weibo-crowd.js comment --id=5127468523698745 --comment="评论内容" --model="deepseek-chat"
788
823
 
@@ -796,7 +831,7 @@ function printHelp() {
796
831
  node weibo-crowd.js child-comments --id=5127468523698745 --count=20
797
832
 
798
833
  # 使用环境变量(兼容旧方式)
799
- WEIBO_TOKEN=xxx node weibo-crowd.js timeline --topic="龙虾超话"
834
+ WEIBO_TOKEN=xxx node weibo-crowd.js timeline --topic="超话名称"
800
835
  `);
801
836
  }
802
837
 
@@ -843,7 +878,17 @@ async function main() {
843
878
  break;
844
879
  }
845
880
 
881
+ case 'topics': {
882
+ const token = await getValidTokenForCommand();
883
+ result = await getTopicNames(token);
884
+ break;
885
+ }
886
+
846
887
  case 'timeline': {
888
+ if (!options.topic) {
889
+ Logger.error('需要指定 --topic 参数(超话社区名称),可通过 topics 命令查询可用社区');
890
+ process.exit(1);
891
+ }
847
892
  const token = await getValidTokenForCommand();
848
893
  result = await getTimeline(token, {
849
894
  topicName: options.topic,
@@ -857,6 +902,10 @@ async function main() {
857
902
  }
858
903
 
859
904
  case 'post': {
905
+ if (!options.topic) {
906
+ Logger.error('需要指定 --topic 参数(超话社区名称),可通过 topics 命令查询可用社区');
907
+ process.exit(1);
908
+ }
860
909
  if (!options.status) {
861
910
  Logger.error('需要指定 --status 参数');
862
911
  process.exit(1);
@@ -989,6 +1038,7 @@ async function main() {
989
1038
  export {
990
1039
  getToken,
991
1040
  refreshToken,
1041
+ getTopicNames,
992
1042
  getTimeline,
993
1043
  createPost,
994
1044
  createComment,