koishi-plugin-wordpress-notifier 2.5.9 → 2.6.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/README.md +10 -0
- package/lib/index.js +36 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,6 +339,16 @@ npm install
|
|
|
339
339
|
|
|
340
340
|
## 版本历史
|
|
341
341
|
|
|
342
|
+
### 2.6.0 (2026-01-25)
|
|
343
|
+
|
|
344
|
+
- 🐛 修复命令返回消息过长导致的Bad Request错误
|
|
345
|
+
- ✅ 为wordpress.latest命令添加长度控制,只返回前3篇文章
|
|
346
|
+
- ✅ 为wordpress.list命令添加标题截断和消息长度控制
|
|
347
|
+
- ✅ 统一将所有命令的消息长度限制调整为390字符
|
|
348
|
+
- ✅ 优化wordpress.pushed命令的消息长度验证
|
|
349
|
+
- ✅ 确保wordpress.status命令符合QQ接口长度限制
|
|
350
|
+
- ✅ 修复TypeScript编译错误,确保代码质量
|
|
351
|
+
|
|
342
352
|
### 2.5.9 (2026-01-25)
|
|
343
353
|
|
|
344
354
|
- 🐛 彻底修复11255错误,严格遵循QQ接口规范
|
package/lib/index.js
CHANGED
|
@@ -488,18 +488,30 @@ function apply(ctx, config) {
|
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
ctx.command('wordpress.latest', '查看最新文章')
|
|
491
|
-
.action(async () => {
|
|
491
|
+
.action(async ({ session }) => {
|
|
492
492
|
ctx.logger.info('命令 wordpress.latest 被调用');
|
|
493
493
|
const posts = await fetchLatestPosts();
|
|
494
494
|
if (posts.length === 0) {
|
|
495
495
|
ctx.logger.info('没有找到文章');
|
|
496
496
|
return koishi_1.h.text('暂无文章');
|
|
497
497
|
}
|
|
498
|
+
// 计算单篇文章的最大长度,确保每条消息不超过390字符
|
|
499
|
+
// 采用简化方案:只返回前3篇文章,确保消息长度在限制内
|
|
500
|
+
const limitedPosts = posts.slice(0, 3);
|
|
498
501
|
let message = '📰 最新文章:\n\n';
|
|
499
|
-
for (const post of
|
|
502
|
+
for (const post of limitedPosts) {
|
|
500
503
|
const title = post.title.rendered.replace(/<[^>]*>/g, '');
|
|
501
|
-
|
|
502
|
-
|
|
504
|
+
// 自定义日期格式,避免过长
|
|
505
|
+
const date = new Date(post.date);
|
|
506
|
+
const formattedDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
507
|
+
const encodedLink = encodeURI(post.link);
|
|
508
|
+
// 截断标题,避免单条过长
|
|
509
|
+
const truncatedTitle = title.length > 40 ? title.substring(0, 37) + '...' : title;
|
|
510
|
+
message += `${truncatedTitle}\n📅 ${formattedDate}\n🔗 ${encodedLink}\n\n`;
|
|
511
|
+
}
|
|
512
|
+
// 如果有更多文章,添加提示
|
|
513
|
+
if (posts.length > 3) {
|
|
514
|
+
message += `... 共 ${posts.length} 篇文章,只显示前 3 篇`;
|
|
503
515
|
}
|
|
504
516
|
ctx.logger.info(`准备返回消息,长度: ${message.length}`);
|
|
505
517
|
return koishi_1.h.text(message);
|
|
@@ -511,11 +523,24 @@ function apply(ctx, config) {
|
|
|
511
523
|
if (posts.length === 0) {
|
|
512
524
|
return koishi_1.h.text('暂无文章');
|
|
513
525
|
}
|
|
514
|
-
|
|
526
|
+
// 使用数组拼接消息,便于控制格式和长度
|
|
527
|
+
const messageParts = ['📚 文章列表:'];
|
|
515
528
|
for (const post of posts) {
|
|
516
529
|
const title = post.title.rendered.replace(/<[^>]*>/g, '');
|
|
517
|
-
|
|
530
|
+
// 截断标题,避免单条过长
|
|
531
|
+
const truncatedTitle = title.length > 50 ? title.substring(0, 47) + '...' : title;
|
|
532
|
+
messageParts.push(`${post.id}. ${truncatedTitle}`);
|
|
518
533
|
}
|
|
534
|
+
let message = messageParts.join('\n');
|
|
535
|
+
// 长度验证,超过 390 字符则精简
|
|
536
|
+
if (message.length > 390) {
|
|
537
|
+
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
538
|
+
// 只保留前10篇文章
|
|
539
|
+
const shortParts = messageParts.slice(0, 11); // 1个标题 + 10篇文章
|
|
540
|
+
shortParts.push('... 更多文章请查看完整列表');
|
|
541
|
+
message = shortParts.join('\n');
|
|
542
|
+
}
|
|
543
|
+
ctx.logger.info(`准备返回消息,长度: ${message.length}`);
|
|
519
544
|
return koishi_1.h.text(message);
|
|
520
545
|
});
|
|
521
546
|
ctx.command('wordpress.push', '手动推送最新文章')
|
|
@@ -545,8 +570,8 @@ function apply(ctx, config) {
|
|
|
545
570
|
];
|
|
546
571
|
// 合并为单行文本,统一换行符
|
|
547
572
|
let message = messageParts.join('\n');
|
|
548
|
-
// 长度验证,超过
|
|
549
|
-
if (message.length >
|
|
573
|
+
// 长度验证,超过 390 字符则精简,符合 QQ 接口限制
|
|
574
|
+
if (message.length > 390) {
|
|
550
575
|
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
551
576
|
message = messageParts.slice(0, 5).join('\n') + '\n... 更多配置请查看完整状态';
|
|
552
577
|
}
|
|
@@ -666,10 +691,10 @@ function apply(ctx, config) {
|
|
|
666
691
|
messageParts.push(''); // 空行分隔
|
|
667
692
|
}
|
|
668
693
|
let message = messageParts.join('\n');
|
|
669
|
-
// 长度验证,超过
|
|
670
|
-
if (message.length >
|
|
694
|
+
// 长度验证,超过 390 字符则精简,符合 QQ 接口限制
|
|
695
|
+
if (message.length > 390) {
|
|
671
696
|
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
672
|
-
message = messageParts.slice(0,
|
|
697
|
+
message = messageParts.slice(0, 8).join('\n') + '\n... 更多记录请查看完整列表';
|
|
673
698
|
}
|
|
674
699
|
return koishi_1.h.text(message);
|
|
675
700
|
});
|