koishi-plugin-wordpress-notifier 2.6.0 → 2.7.1
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 +83 -70
- package/lib/index.js +82 -80
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,76 +339,89 @@ npm install
|
|
|
339
339
|
|
|
340
340
|
## 版本历史
|
|
341
341
|
|
|
342
|
-
### 2.
|
|
343
|
-
|
|
344
|
-
-
|
|
345
|
-
- ✅
|
|
346
|
-
- ✅
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
- ✅
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
-
|
|
358
|
-
- ✅
|
|
359
|
-
- ✅
|
|
360
|
-
- ✅
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
-
|
|
372
|
-
- ✅
|
|
373
|
-
- ✅
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
-
|
|
389
|
-
- ✅
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
-
|
|
397
|
-
- ✅
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
-
|
|
402
|
-
- ✅
|
|
403
|
-
- ✅
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
-
|
|
410
|
-
- ✅
|
|
411
|
-
- ✅
|
|
342
|
+
### 2.7.1 (2026-01-25)
|
|
343
|
+
|
|
344
|
+
- ✅ 优化 `/wordpress.latest` 命令,不再固定只显示前3篇文章
|
|
345
|
+
- ✅ 实现动态消息长度控制,在500字符限制内显示尽可能多的文章
|
|
346
|
+
- ✅ 显示实际显示的文章数量和总文章数量
|
|
347
|
+
|
|
348
|
+
### 2.7.0 (2026-01-25)
|
|
349
|
+
|
|
350
|
+
- ✅ 将所有消息长度限制从390字符提升到500字符
|
|
351
|
+
- ✅ 优化消息格式,提供更长的内容展示
|
|
352
|
+
- ✅ 保持消息格式兼容QQ接口规范
|
|
353
|
+
- ✅ 修复TypeScript编译错误,确保代码质量
|
|
354
|
+
|
|
355
|
+
### 2.6.0 (2026-01-25)
|
|
356
|
+
|
|
357
|
+
- 🐛 修复命令返回消息过长导致的Bad Request错误
|
|
358
|
+
- ✅ 为wordpress.latest命令添加长度控制,只返回前3篇文章
|
|
359
|
+
- ✅ 为wordpress.list命令添加标题截断和消息长度控制
|
|
360
|
+
- ✅ 统一将所有命令的消息长度限制调整为390字符
|
|
361
|
+
- ✅ 优化wordpress.pushed命令的消息长度验证
|
|
362
|
+
- ✅ 确保wordpress.status命令符合QQ接口长度限制
|
|
363
|
+
- ✅ 修复TypeScript编译错误,确保代码质量
|
|
364
|
+
|
|
365
|
+
### 2.5.9 (2026-01-25)
|
|
366
|
+
|
|
367
|
+
- 🐛 彻底修复11255错误,严格遵循QQ接口规范
|
|
368
|
+
- ✅ 移除所有非必要特殊符号,只保留1个极简表情
|
|
369
|
+
- ✅ 自定义时间格式:年-月-日 时:分,避免本地化特殊字符
|
|
370
|
+
- ✅ 使用encodeURI强制编码WordPress链接
|
|
371
|
+
- ✅ 双级长度控制:标题60字符,整体300字符
|
|
372
|
+
- ✅ 严格限制换行:仅2次换行,无连续或尾部换行
|
|
373
|
+
- ✅ 强化清洗规则:标准化所有空白符为单个半角空格
|
|
374
|
+
|
|
375
|
+
### 2.5.8 (2026-01-25)
|
|
376
|
+
|
|
377
|
+
- 🐛 修复推送失败的11255错误
|
|
378
|
+
- ✅ 修正消息发送逻辑,确保正确处理单个消息段
|
|
379
|
+
- ✅ 统一变量命名,将segments改为message
|
|
380
|
+
- ✅ 确保bot.sendMessage接收正确的消息类型
|
|
381
|
+
|
|
382
|
+
### 2.5.7 (2026-01-25)
|
|
383
|
+
|
|
384
|
+
- 🔧 适配QQ官方bot,优化bot获取逻辑
|
|
385
|
+
- ✅ 优先选择QQ官方bot(platform === 'qq')
|
|
386
|
+
- ✅ 优化消息格式,确保兼容QQ官方bot要求
|
|
387
|
+
- ✅ 调整消息长度限制,更严格控制在350字符内
|
|
388
|
+
- ✅ 简化消息格式,使用更兼容的分隔符
|
|
389
|
+
- ✅ 确保@全体成员格式符合QQ官方bot规范
|
|
390
|
+
|
|
391
|
+
### 2.5.6 (2026-01-25)
|
|
392
|
+
|
|
393
|
+
- 🔧 修复11255错误,重构消息构造函数
|
|
394
|
+
- ✅ 移除多段消息拼接,改为单段纯文本
|
|
395
|
+
- ✅ 强制截断长文本,控制消息长度
|
|
396
|
+
- ✅ 标准化特殊符号,使用|分隔关键信息
|
|
397
|
+
- ✅ 直接返回h.text()封装的单段消息
|
|
398
|
+
|
|
399
|
+
### 2.5.5 (2026-01-25)
|
|
400
|
+
|
|
401
|
+
- 🔧 修复wordpress.status命令Bad Request错误
|
|
402
|
+
- ✅ 为所有命令添加h.text()封装
|
|
403
|
+
- ✅ 精简字段描述,缩短消息长度
|
|
404
|
+
- ✅ 添加消息长度验证
|
|
405
|
+
- ✅ 优化消息格式,确保兼容Satorijs QQ适配器
|
|
406
|
+
|
|
407
|
+
### 2.3.0 (2026-01-25)
|
|
408
|
+
|
|
409
|
+
- 🔧 增强命令权限管理,限制敏感命令仅超级管理员可用
|
|
410
|
+
- ✅ 为`wordpress.set-url`命令添加超级管理员权限检查
|
|
411
|
+
- ✅ 为`wordpress.clean [days]`命令添加超级管理员权限检查
|
|
412
|
+
- ✅ 为`wordpress.toggle`命令添加超级管理员权限检查
|
|
413
|
+
- ✅ 为`wordpress.toggle-update`命令添加超级管理员权限检查
|
|
414
|
+
- ✅ 为`wordpress.toggle-user`命令添加超级管理员权限检查
|
|
415
|
+
- ✅ 为`wordpress.mention`命令添加超级管理员权限检查
|
|
416
|
+
- ✅ 添加了详细的日志记录,便于追踪非授权访问尝试
|
|
417
|
+
|
|
418
|
+
### 2.2.0 (2026-01-25)
|
|
419
|
+
|
|
420
|
+
- 🐛 修复重复推送问题,清理未使用的数据库表
|
|
421
|
+
- ✅ 移除了未使用的`wordpress_posts`表,统一使用`wordpress_group_pushes`表进行推送记录管理
|
|
422
|
+
- ✅ 修复了`wordpress.pushed`命令,使用`wordpress_group_pushes`表获取已推送记录
|
|
423
|
+
- ✅ 修复了`wordpress.clean`命令,移除了对`wordpress_posts`表的引用
|
|
424
|
+
- ✅ 增强了推送日志,添加了详细的调试信息,便于追踪推送流程
|
|
412
425
|
- ✅ 优化了`isGroupPushed`和`markGroupAsPushed`函数,添加了更多日志
|
|
413
426
|
### 2.1.0 (2026-01-25)
|
|
414
427
|
|
package/lib/index.js
CHANGED
|
@@ -239,17 +239,19 @@ function apply(ctx, config) {
|
|
|
239
239
|
throw error;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
+
// 1. 新增强清洗函数:针对性解决敏感字符问题
|
|
243
|
+
function sanitizeContent(content) {
|
|
244
|
+
return content
|
|
245
|
+
.replace(/<[^>]*>/g, '') // 移除所有 HTML 标签
|
|
246
|
+
.replace(/[\x00-\x1F\x7F]/g, '') // 移除不可见控制符,QQ 接口明确禁止
|
|
247
|
+
.replace(/\u3000/g, ' ') // 全角空格转半角空格,解决适配器编码缺陷
|
|
248
|
+
.replace(/\s+/g, ' ') // 标准化所有空白符为单个半角空格
|
|
249
|
+
.trim(); // 移除首尾空格
|
|
250
|
+
}
|
|
242
251
|
function formatPostMessage(post, mention = false, isUpdate = false) {
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
return text
|
|
246
|
-
.replace(/<[^>]*>/g, '') // 移除所有 HTML 标签
|
|
247
|
-
.replace(/[\x00-\x1F\x7F]/g, '') // 移除控制字符
|
|
248
|
-
.replace(/\s+/g, ' ') // 标准化所有空白符为单个半角空格
|
|
249
|
-
.trim();
|
|
250
|
-
};
|
|
252
|
+
// 使用统一的强清洗函数
|
|
253
|
+
let title = sanitizeContent(post.title.rendered);
|
|
251
254
|
// 严格截断标题为 60 字符
|
|
252
|
-
let title = sanitizeText(post.title.rendered);
|
|
253
255
|
if (title.length > 60) {
|
|
254
256
|
title = title.substring(0, 57) + '...';
|
|
255
257
|
}
|
|
@@ -269,30 +271,23 @@ function apply(ctx, config) {
|
|
|
269
271
|
// 构建 @全体成员 文本(适配 QQ 官方 bot 和其他适配器)
|
|
270
272
|
const atAllText = mention && config.mentionAll ? '@全体成员 ' : '';
|
|
271
273
|
// 只使用一个极简表情
|
|
272
|
-
const messageType = isUpdate ? '
|
|
274
|
+
const messageType = isUpdate ? '📝' : '�';
|
|
273
275
|
// 构建核心消息内容,严格控制格式
|
|
274
276
|
// 格式:[表情] [@全体] [时间] - [标题]
|
|
275
277
|
// [链接]
|
|
276
278
|
let message = `${messageType} ${atAllText}${date} - ${title}\n${encodedLink}`;
|
|
277
|
-
// 双级长度控制:整体消息兜底
|
|
278
|
-
if (message.length >
|
|
279
|
-
message = message.substring(0,
|
|
279
|
+
// 双级长度控制:整体消息兜底 500 字符
|
|
280
|
+
if (message.length > 500) {
|
|
281
|
+
message = message.substring(0, 497) + '...';
|
|
280
282
|
ctx.logger.warn(`文章消息超长,已截断,文章 ID: ${post.id}`);
|
|
281
283
|
}
|
|
282
|
-
//
|
|
283
|
-
return
|
|
284
|
+
// 直接返回纯字符串,跳过适配器复杂编码
|
|
285
|
+
return message;
|
|
284
286
|
}
|
|
285
287
|
function formatUserMessage(user, mention = false) {
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
return text
|
|
289
|
-
.replace(/<[^>]*>/g, '') // 移除所有 HTML 标签
|
|
290
|
-
.replace(/[\x00-\x1F\x7F]/g, '') // 移除控制字符
|
|
291
|
-
.replace(/\s+/g, ' ') // 标准化所有空白符为单个半角空格
|
|
292
|
-
.trim();
|
|
293
|
-
};
|
|
288
|
+
// 使用统一的强清洗函数
|
|
289
|
+
let username = sanitizeContent(user.name);
|
|
294
290
|
// 严格截断用户名为 50 字符
|
|
295
|
-
let username = sanitizeText(user.name);
|
|
296
291
|
if (username.length > 50) {
|
|
297
292
|
username = username.substring(0, 47) + '...';
|
|
298
293
|
}
|
|
@@ -350,13 +345,13 @@ function apply(ctx, config) {
|
|
|
350
345
|
// 格式:[表情] [@全体] 新用户注册 - [用户名]
|
|
351
346
|
// 注册时间: [时间]
|
|
352
347
|
let message = `${messageType} ${atAllText}新用户注册 - ${username}\n注册时间: ${registerDate}`;
|
|
353
|
-
// 严格控制整体消息长度为
|
|
354
|
-
if (message.length >
|
|
355
|
-
message = message.substring(0,
|
|
348
|
+
// 严格控制整体消息长度为 500 字符
|
|
349
|
+
if (message.length > 500) {
|
|
350
|
+
message = message.substring(0, 497) + '...';
|
|
356
351
|
ctx.logger.warn(`用户消息超长,已截断,用户 ID: ${user.id}`);
|
|
357
352
|
}
|
|
358
|
-
//
|
|
359
|
-
return
|
|
353
|
+
// 直接返回纯字符串,跳过适配器复杂编码
|
|
354
|
+
return message;
|
|
360
355
|
}
|
|
361
356
|
async function pushNewPosts() {
|
|
362
357
|
// 健壮获取 QQ Bot 实例,兼容多种适配器,优先选择 QQ 官方 bot
|
|
@@ -493,47 +488,53 @@ function apply(ctx, config) {
|
|
|
493
488
|
const posts = await fetchLatestPosts();
|
|
494
489
|
if (posts.length === 0) {
|
|
495
490
|
ctx.logger.info('没有找到文章');
|
|
496
|
-
return
|
|
497
|
-
}
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const title = post.title.rendered.replace(/<[^>]*>/g, '');
|
|
491
|
+
return '暂无文章';
|
|
492
|
+
}
|
|
493
|
+
// 动态添加文章,确保消息长度不超过500字符
|
|
494
|
+
let message = '📰 最新文章:\n';
|
|
495
|
+
let addedCount = 0;
|
|
496
|
+
for (const post of posts) {
|
|
497
|
+
const title = sanitizeContent(post.title.rendered);
|
|
504
498
|
// 自定义日期格式,避免过长
|
|
505
499
|
const date = new Date(post.date);
|
|
506
500
|
const formattedDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
507
501
|
const encodedLink = encodeURI(post.link);
|
|
508
502
|
// 截断标题,避免单条过长
|
|
509
503
|
const truncatedTitle = title.length > 40 ? title.substring(0, 37) + '...' : title;
|
|
510
|
-
|
|
504
|
+
// 单篇文章的消息片段
|
|
505
|
+
const postMessage = `${truncatedTitle}\n📅 ${formattedDate}\n🔗 ${encodedLink}\n`;
|
|
506
|
+
// 检查添加后是否超过500字符,如果超过则停止添加
|
|
507
|
+
if (message.length + postMessage.length > 500) {
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
message += postMessage;
|
|
511
|
+
addedCount++;
|
|
511
512
|
}
|
|
512
|
-
//
|
|
513
|
-
if (posts.length
|
|
514
|
-
message += `... 共 ${posts.length}
|
|
513
|
+
// 如果有更多文章未显示,添加提示
|
|
514
|
+
if (addedCount < posts.length) {
|
|
515
|
+
message += `... 共 ${posts.length} 篇文章,显示前 ${addedCount} 篇`;
|
|
515
516
|
}
|
|
516
|
-
ctx.logger.info(`准备返回消息,长度: ${message.length}
|
|
517
|
-
return
|
|
517
|
+
ctx.logger.info(`准备返回消息,长度: ${message.length},显示 ${addedCount}/${posts.length} 篇文章`);
|
|
518
|
+
return message;
|
|
518
519
|
});
|
|
519
520
|
ctx.command('wordpress.list', '查看文章列表')
|
|
520
521
|
.action(async () => {
|
|
521
522
|
ctx.logger.info('命令 wordpress.list 被调用');
|
|
522
523
|
const posts = await fetchLatestPosts();
|
|
523
524
|
if (posts.length === 0) {
|
|
524
|
-
return
|
|
525
|
+
return '暂无文章';
|
|
525
526
|
}
|
|
526
527
|
// 使用数组拼接消息,便于控制格式和长度
|
|
527
528
|
const messageParts = ['📚 文章列表:'];
|
|
528
529
|
for (const post of posts) {
|
|
529
|
-
const title = post.title.rendered
|
|
530
|
+
const title = sanitizeContent(post.title.rendered);
|
|
530
531
|
// 截断标题,避免单条过长
|
|
531
532
|
const truncatedTitle = title.length > 50 ? title.substring(0, 47) + '...' : title;
|
|
532
533
|
messageParts.push(`${post.id}. ${truncatedTitle}`);
|
|
533
534
|
}
|
|
534
535
|
let message = messageParts.join('\n');
|
|
535
|
-
// 长度验证,超过
|
|
536
|
-
if (message.length >
|
|
536
|
+
// 长度验证,超过 500 字符则精简
|
|
537
|
+
if (message.length > 500) {
|
|
537
538
|
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
538
539
|
// 只保留前10篇文章
|
|
539
540
|
const shortParts = messageParts.slice(0, 11); // 1个标题 + 10篇文章
|
|
@@ -541,13 +542,13 @@ function apply(ctx, config) {
|
|
|
541
542
|
message = shortParts.join('\n');
|
|
542
543
|
}
|
|
543
544
|
ctx.logger.info(`准备返回消息,长度: ${message.length}`);
|
|
544
|
-
return
|
|
545
|
+
return message;
|
|
545
546
|
});
|
|
546
547
|
ctx.command('wordpress.push', '手动推送最新文章')
|
|
547
548
|
.action(async () => {
|
|
548
549
|
ctx.logger.info('命令 wordpress.push 被调用');
|
|
549
550
|
await pushNewPosts();
|
|
550
|
-
return
|
|
551
|
+
return '已检查并推送最新文章';
|
|
551
552
|
});
|
|
552
553
|
ctx.command('wordpress.status', '查看插件状态')
|
|
553
554
|
.action(({ session }) => {
|
|
@@ -570,106 +571,106 @@ function apply(ctx, config) {
|
|
|
570
571
|
];
|
|
571
572
|
// 合并为单行文本,统一换行符
|
|
572
573
|
let message = messageParts.join('\n');
|
|
573
|
-
// 长度验证,超过
|
|
574
|
-
if (message.length >
|
|
574
|
+
// 长度验证,超过 500 字符则精简
|
|
575
|
+
if (message.length > 500) {
|
|
575
576
|
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
576
577
|
message = messageParts.slice(0, 5).join('\n') + '\n... 更多配置请查看完整状态';
|
|
577
578
|
}
|
|
578
579
|
ctx.logger.info(`准备返回消息,长度: ${message.length}`);
|
|
579
|
-
//
|
|
580
|
-
return
|
|
580
|
+
// 直接返回纯字符串,跳过适配器复杂编码
|
|
581
|
+
return message;
|
|
581
582
|
});
|
|
582
583
|
ctx.command('wordpress.toggle-update', '切换文章更新推送开关')
|
|
583
584
|
.action(async ({ session }) => {
|
|
584
585
|
// 检查是否为超级管理员
|
|
585
586
|
if (!session || !session.userId) {
|
|
586
587
|
ctx.logger.warn('匿名用户尝试调用 wordpress.toggle-update 命令');
|
|
587
|
-
return
|
|
588
|
+
return '您不是超级管理员,无法执行此命令';
|
|
588
589
|
}
|
|
589
590
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
590
591
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
591
592
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
592
593
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
593
594
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.toggle-update 命令`);
|
|
594
|
-
return
|
|
595
|
+
return '您不是超级管理员,无法执行此命令';
|
|
595
596
|
}
|
|
596
597
|
ctx.logger.info('命令 wordpress.toggle-update 被调用');
|
|
597
598
|
config.enableUpdatePush = !config.enableUpdatePush;
|
|
598
|
-
return
|
|
599
|
+
return `文章更新推送已${config.enableUpdatePush ? '开启' : '关闭'}`;
|
|
599
600
|
});
|
|
600
601
|
ctx.command('wordpress.toggle-user', '切换新用户注册推送开关')
|
|
601
602
|
.action(async ({ session }) => {
|
|
602
603
|
// 检查是否为超级管理员
|
|
603
604
|
if (!session || !session.userId) {
|
|
604
605
|
ctx.logger.warn('匿名用户尝试调用 wordpress.toggle-user 命令');
|
|
605
|
-
return
|
|
606
|
+
return '您不是超级管理员,无法执行此命令';
|
|
606
607
|
}
|
|
607
608
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
608
609
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
609
610
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
610
611
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
611
612
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.toggle-user 命令`);
|
|
612
|
-
return
|
|
613
|
+
return '您不是超级管理员,无法执行此命令';
|
|
613
614
|
}
|
|
614
615
|
ctx.logger.info('命令 wordpress.toggle-user 被调用');
|
|
615
616
|
config.enableUserPush = !config.enableUserPush;
|
|
616
|
-
return
|
|
617
|
+
return `新用户注册推送已${config.enableUserPush ? '开启' : '关闭'}`;
|
|
617
618
|
});
|
|
618
619
|
ctx.command('wordpress.toggle', '切换自动推送开关')
|
|
619
620
|
.action(async ({ session }) => {
|
|
620
621
|
// 检查是否为超级管理员
|
|
621
622
|
if (!session || !session.userId) {
|
|
622
623
|
ctx.logger.warn('匿名用户尝试调用 wordpress.toggle 命令');
|
|
623
|
-
return
|
|
624
|
+
return '您不是超级管理员,无法执行此命令';
|
|
624
625
|
}
|
|
625
626
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
626
627
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
627
628
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
628
629
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
629
630
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.toggle 命令`);
|
|
630
|
-
return
|
|
631
|
+
return '您不是超级管理员,无法执行此命令';
|
|
631
632
|
}
|
|
632
633
|
ctx.logger.info('命令 wordpress.toggle 被调用');
|
|
633
634
|
config.enableAutoPush = !config.enableAutoPush;
|
|
634
|
-
return
|
|
635
|
+
return `自动推送已${config.enableAutoPush ? '开启' : '关闭'}`;
|
|
635
636
|
});
|
|
636
637
|
ctx.command('wordpress.mention', '切换 @全体成员 开关')
|
|
637
638
|
.action(async ({ session }) => {
|
|
638
639
|
// 检查是否为超级管理员
|
|
639
640
|
if (!session || !session.userId) {
|
|
640
641
|
ctx.logger.warn('匿名用户尝试调用 wordpress.mention 命令');
|
|
641
|
-
return
|
|
642
|
+
return '您不是超级管理员,无法执行此命令';
|
|
642
643
|
}
|
|
643
644
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
644
645
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
645
646
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
646
647
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
647
648
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.mention 命令`);
|
|
648
|
-
return
|
|
649
|
+
return '您不是超级管理员,无法执行此命令';
|
|
649
650
|
}
|
|
650
651
|
ctx.logger.info('命令 wordpress.mention 被调用');
|
|
651
652
|
config.mentionAll = !config.mentionAll;
|
|
652
|
-
return
|
|
653
|
+
return `@全体 已${config.mentionAll ? '开启' : '关闭'}`;
|
|
653
654
|
});
|
|
654
655
|
ctx.command('wordpress.set-url <url>', '修改 WordPress 站点地址')
|
|
655
656
|
.action(async ({ session }, url) => {
|
|
656
657
|
// 检查是否为超级管理员
|
|
657
658
|
if (!session || !session.userId) {
|
|
658
659
|
ctx.logger.warn('匿名用户尝试调用 wordpress.set-url 命令');
|
|
659
|
-
return
|
|
660
|
+
return '您不是超级管理员,无法执行此命令';
|
|
660
661
|
}
|
|
661
662
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
662
663
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
663
664
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
664
665
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
665
666
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.set-url 命令`);
|
|
666
|
-
return
|
|
667
|
+
return '您不是超级管理员,无法执行此命令';
|
|
667
668
|
}
|
|
668
669
|
ctx.logger.info(`命令 wordpress.set-url 被调用,调用者:${userId},新地址:${url}`);
|
|
669
670
|
// 修改站点地址
|
|
670
671
|
config.wordpressUrl = url;
|
|
671
672
|
ctx.logger.info(`站点地址已修改为:${url}`);
|
|
672
|
-
return
|
|
673
|
+
return `WordPress 站点地址已修改为:${url}`;
|
|
673
674
|
});
|
|
674
675
|
ctx.command('wordpress.pushed', '查看已推送的文章列表')
|
|
675
676
|
.action(async () => {
|
|
@@ -681,42 +682,45 @@ function apply(ctx, config) {
|
|
|
681
682
|
}
|
|
682
683
|
});
|
|
683
684
|
if (records.length === 0) {
|
|
684
|
-
return
|
|
685
|
+
return '暂无已推送文章记录';
|
|
685
686
|
}
|
|
686
687
|
// 使用数组拼接消息,便于控制格式和长度
|
|
687
688
|
const messageParts = ['📋 已推送文章列表(按时间倒序):'];
|
|
688
689
|
for (const record of records) {
|
|
690
|
+
// 自定义时间格式,避免特殊分隔符
|
|
691
|
+
const formattedDate = new Date(record.pushedAt);
|
|
692
|
+
const dateStr = `${formattedDate.getFullYear()}-${String(formattedDate.getMonth() + 1).padStart(2, '0')}-${String(formattedDate.getDate()).padStart(2, '0')} ${String(formattedDate.getHours()).padStart(2, '0')}:${String(formattedDate.getMinutes()).padStart(2, '0')}`;
|
|
689
693
|
messageParts.push(`${record.id}. 文章 ID: ${record.postId}`);
|
|
690
|
-
messageParts.push(`📅 推送时间: ${
|
|
694
|
+
messageParts.push(`📅 推送时间: ${dateStr}`);
|
|
691
695
|
messageParts.push(''); // 空行分隔
|
|
692
696
|
}
|
|
693
697
|
let message = messageParts.join('\n');
|
|
694
|
-
// 长度验证,超过
|
|
695
|
-
if (message.length >
|
|
698
|
+
// 长度验证,超过 500 字符则精简,符合 QQ 接口限制
|
|
699
|
+
if (message.length > 500) {
|
|
696
700
|
ctx.logger.warn(`消息过长,长度: ${message.length},将进行精简`);
|
|
697
701
|
message = messageParts.slice(0, 8).join('\n') + '\n... 更多记录请查看完整列表';
|
|
698
702
|
}
|
|
699
|
-
return
|
|
703
|
+
return message;
|
|
700
704
|
});
|
|
701
705
|
ctx.command('wordpress.clean [days]', '清理指定天数前的推送记录(默认 30 天)')
|
|
702
706
|
.action(async ({ session }, days) => {
|
|
703
707
|
// 检查是否为超级管理员
|
|
704
708
|
if (!session || !session.userId) {
|
|
705
709
|
ctx.logger.warn('匿名用户尝试调用 wordpress.clean 命令');
|
|
706
|
-
return
|
|
710
|
+
return '您不是超级管理员,无法执行此命令';
|
|
707
711
|
}
|
|
708
712
|
// 获取当前用户的QQ号(兼容不同平台格式,如 onebot:123456789 -> 123456789)
|
|
709
713
|
const userId = session.userId.replace(/^\w+:/, '');
|
|
710
714
|
// 检查当前用户是否在插件配置的超级管理员列表中
|
|
711
715
|
if (!config.superAdmins || !config.superAdmins.includes(userId)) {
|
|
712
716
|
ctx.logger.warn(`非超级管理员 ${userId} 尝试调用 wordpress.clean 命令`);
|
|
713
|
-
return
|
|
717
|
+
return '您不是超级管理员,无法执行此命令';
|
|
714
718
|
}
|
|
715
719
|
ctx.logger.info(`命令 wordpress.clean 被调用,天数:${days || '默认'}`);
|
|
716
720
|
// 设置默认天数
|
|
717
721
|
const daysToKeep = days ? parseInt(days) : 30;
|
|
718
722
|
if (isNaN(daysToKeep) || daysToKeep <= 0) {
|
|
719
|
-
return
|
|
723
|
+
return '请输入有效的天数';
|
|
720
724
|
}
|
|
721
725
|
// 计算清理时间点
|
|
722
726
|
const cutoffDate = new Date();
|
|
@@ -742,7 +746,7 @@ function apply(ctx, config) {
|
|
|
742
746
|
result++;
|
|
743
747
|
}
|
|
744
748
|
ctx.logger.info(`已清理 ${result} 条 ${daysToKeep} 天前的推送记录`);
|
|
745
|
-
return
|
|
749
|
+
return `已清理 ${result} 条 ${daysToKeep} 天前的推送记录`;
|
|
746
750
|
});
|
|
747
751
|
ctx.command('wordpress', 'WordPress 推送插件菜单')
|
|
748
752
|
.action(() => {
|
|
@@ -750,7 +754,6 @@ function apply(ctx, config) {
|
|
|
750
754
|
// 使用数组拼接消息,便于控制格式和长度
|
|
751
755
|
const messageParts = [
|
|
752
756
|
'📚 WordPress 推送插件菜单:',
|
|
753
|
-
'',
|
|
754
757
|
'🔹 /wordpress.status - 查看插件状态',
|
|
755
758
|
'🔹 /wordpress.latest - 查看最新文章',
|
|
756
759
|
'🔹 /wordpress.list - 查看文章列表',
|
|
@@ -762,12 +765,11 @@ function apply(ctx, config) {
|
|
|
762
765
|
'🔹 /wordpress.toggle-update - 切换文章更新推送开关(仅超级管理员)',
|
|
763
766
|
'🔹 /wordpress.toggle-user - 切换新用户注册推送开关(仅超级管理员)',
|
|
764
767
|
'🔹 /wordpress.mention - 切换 @全体 开关(仅超级管理员)',
|
|
765
|
-
'',
|
|
766
768
|
'💡 提示:所有命令都需要加 / 前缀'
|
|
767
769
|
];
|
|
768
770
|
let message = messageParts.join('\n');
|
|
769
771
|
ctx.logger.info(`准备返回消息,长度: ${message.length}`);
|
|
770
|
-
return
|
|
772
|
+
return message;
|
|
771
773
|
});
|
|
772
774
|
ctx.setInterval(() => {
|
|
773
775
|
pushNewPosts();
|