koishi-plugin-wordpress-notifier 2.5.7 → 2.5.9
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 +26 -10
- package/lib/index.js +58 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,6 +339,23 @@ npm install
|
|
|
339
339
|
|
|
340
340
|
## 版本历史
|
|
341
341
|
|
|
342
|
+
### 2.5.9 (2026-01-25)
|
|
343
|
+
|
|
344
|
+
- 🐛 彻底修复11255错误,严格遵循QQ接口规范
|
|
345
|
+
- ✅ 移除所有非必要特殊符号,只保留1个极简表情
|
|
346
|
+
- ✅ 自定义时间格式:年-月-日 时:分,避免本地化特殊字符
|
|
347
|
+
- ✅ 使用encodeURI强制编码WordPress链接
|
|
348
|
+
- ✅ 双级长度控制:标题60字符,整体300字符
|
|
349
|
+
- ✅ 严格限制换行:仅2次换行,无连续或尾部换行
|
|
350
|
+
- ✅ 强化清洗规则:标准化所有空白符为单个半角空格
|
|
351
|
+
|
|
352
|
+
### 2.5.8 (2026-01-25)
|
|
353
|
+
|
|
354
|
+
- 🐛 修复推送失败的11255错误
|
|
355
|
+
- ✅ 修正消息发送逻辑,确保正确处理单个消息段
|
|
356
|
+
- ✅ 统一变量命名,将segments改为message
|
|
357
|
+
- ✅ 确保bot.sendMessage接收正确的消息类型
|
|
358
|
+
|
|
342
359
|
### 2.5.7 (2026-01-25)
|
|
343
360
|
|
|
344
361
|
- 🔧 适配QQ官方bot,优化bot获取逻辑
|
|
@@ -373,17 +390,16 @@ npm install
|
|
|
373
390
|
- ✅ 为`wordpress.toggle-update`命令添加超级管理员权限检查
|
|
374
391
|
- ✅ 为`wordpress.toggle-user`命令添加超级管理员权限检查
|
|
375
392
|
- ✅ 为`wordpress.mention`命令添加超级管理员权限检查
|
|
376
|
-
- ✅ 添加了详细的日志记录,便于追踪非授权访问尝试
|
|
377
|
-
|
|
378
|
-
### 2.2.0 (2026-01-25)
|
|
379
|
-
|
|
380
|
-
- 🐛 修复重复推送问题,清理未使用的数据库表
|
|
381
|
-
- ✅ 移除了未使用的`wordpress_posts`表,统一使用`wordpress_group_pushes`表进行推送记录管理
|
|
382
|
-
- ✅ 修复了`wordpress.pushed`命令,使用`wordpress_group_pushes`表获取已推送记录
|
|
383
|
-
- ✅ 修复了`wordpress.clean`命令,移除了对`wordpress_posts`表的引用
|
|
384
|
-
- ✅ 增强了推送日志,添加了详细的调试信息,便于追踪推送流程
|
|
393
|
+
- ✅ 添加了详细的日志记录,便于追踪非授权访问尝试
|
|
394
|
+
|
|
395
|
+
### 2.2.0 (2026-01-25)
|
|
396
|
+
|
|
397
|
+
- 🐛 修复重复推送问题,清理未使用的数据库表
|
|
398
|
+
- ✅ 移除了未使用的`wordpress_posts`表,统一使用`wordpress_group_pushes`表进行推送记录管理
|
|
399
|
+
- ✅ 修复了`wordpress.pushed`命令,使用`wordpress_group_pushes`表获取已推送记录
|
|
400
|
+
- ✅ 修复了`wordpress.clean`命令,移除了对`wordpress_posts`表的引用
|
|
401
|
+
- ✅ 增强了推送日志,添加了详细的调试信息,便于追踪推送流程
|
|
385
402
|
- ✅ 优化了`isGroupPushed`和`markGroupAsPushed`函数,添加了更多日志
|
|
386
|
-
|
|
387
403
|
### 2.1.0 (2026-01-25)
|
|
388
404
|
|
|
389
405
|
- 🔧 更新文档结构,将"如何获取用户注册日期"内容从版本历史移至常见问题部分
|
package/lib/index.js
CHANGED
|
@@ -240,46 +240,64 @@ function apply(ctx, config) {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
function formatPostMessage(post, mention = false, isUpdate = false) {
|
|
243
|
-
//
|
|
243
|
+
// 强化清洗规则:标准化所有空白符为单个半角空格
|
|
244
244
|
const sanitizeText = (text) => {
|
|
245
245
|
return text
|
|
246
246
|
.replace(/<[^>]*>/g, '') // 移除所有 HTML 标签
|
|
247
247
|
.replace(/[\x00-\x1F\x7F]/g, '') // 移除控制字符
|
|
248
|
-
.replace(
|
|
248
|
+
.replace(/\s+/g, ' ') // 标准化所有空白符为单个半角空格
|
|
249
249
|
.trim();
|
|
250
250
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
// 严格截断标题为 60 字符
|
|
252
|
+
let title = sanitizeText(post.title.rendered);
|
|
253
|
+
if (title.length > 60) {
|
|
254
|
+
title = title.substring(0, 57) + '...';
|
|
255
|
+
}
|
|
256
|
+
// 自定义时间格式:年-月-日 时:分
|
|
257
|
+
const formatDate = (dateString) => {
|
|
258
|
+
const date = new Date(dateString);
|
|
259
|
+
const year = date.getFullYear();
|
|
260
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
261
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
262
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
263
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
264
|
+
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
265
|
+
};
|
|
266
|
+
const date = formatDate(post.date);
|
|
267
|
+
// 链接强制编码
|
|
268
|
+
const encodedLink = encodeURI(post.link);
|
|
256
269
|
// 构建 @全体成员 文本(适配 QQ 官方 bot 和其他适配器)
|
|
257
270
|
const atAllText = mention && config.mentionAll ? '@全体成员 ' : '';
|
|
258
|
-
//
|
|
259
|
-
const messageType = isUpdate ? '
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
271
|
+
// 只使用一个极简表情
|
|
272
|
+
const messageType = isUpdate ? '�' : '📝';
|
|
273
|
+
// 构建核心消息内容,严格控制格式
|
|
274
|
+
// 格式:[表情] [@全体] [时间] - [标题]
|
|
275
|
+
// [链接]
|
|
276
|
+
let message = `${messageType} ${atAllText}${date} - ${title}\n${encodedLink}`;
|
|
277
|
+
// 双级长度控制:整体消息兜底 300 字符
|
|
278
|
+
if (message.length > 300) {
|
|
279
|
+
message = message.substring(0, 297) + '...';
|
|
266
280
|
ctx.logger.warn(`文章消息超长,已截断,文章 ID: ${post.id}`);
|
|
267
281
|
}
|
|
268
282
|
// 返回单段文本,使用 h.text() 封装,确保兼容性
|
|
269
283
|
return koishi_1.h.text(message);
|
|
270
284
|
}
|
|
271
285
|
function formatUserMessage(user, mention = false) {
|
|
272
|
-
//
|
|
286
|
+
// 强化清洗规则:标准化所有空白符为单个半角空格
|
|
273
287
|
const sanitizeText = (text) => {
|
|
274
288
|
return text
|
|
275
289
|
.replace(/<[^>]*>/g, '') // 移除所有 HTML 标签
|
|
276
290
|
.replace(/[\x00-\x1F\x7F]/g, '') // 移除控制字符
|
|
277
|
-
.replace(
|
|
291
|
+
.replace(/\s+/g, ' ') // 标准化所有空白符为单个半角空格
|
|
278
292
|
.trim();
|
|
279
293
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
294
|
+
// 严格截断用户名为 50 字符
|
|
295
|
+
let username = sanitizeText(user.name);
|
|
296
|
+
if (username.length > 50) {
|
|
297
|
+
username = username.substring(0, 47) + '...';
|
|
298
|
+
}
|
|
299
|
+
// 安全处理日期,避免显示 "Invalid Date",自定义格式
|
|
300
|
+
let registerDate = '未知时间';
|
|
283
301
|
try {
|
|
284
302
|
ctx.logger.info(`正在处理用户 ${username} 的注册日期`);
|
|
285
303
|
// 尝试所有可能的日期字段,按优先级排序
|
|
@@ -306,36 +324,33 @@ function apply(ctx, config) {
|
|
|
306
324
|
ctx.logger.info(`用户 ${username} 的原始数据: ${JSON.stringify(user)}`);
|
|
307
325
|
}
|
|
308
326
|
if (dateStr) {
|
|
309
|
-
//
|
|
310
|
-
// 或者可能是其他格式,需要安全处理
|
|
327
|
+
// 尝试解析日期,使用自定义格式:年-月-日 时:分
|
|
311
328
|
const date = new Date(dateStr);
|
|
312
329
|
ctx.logger.info(`解析日期 ${dateStr} 结果: ${date.toString()}`);
|
|
313
330
|
if (!isNaN(date.getTime())) {
|
|
314
|
-
|
|
331
|
+
const year = date.getFullYear();
|
|
332
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
333
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
334
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
335
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
336
|
+
registerDate = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
315
337
|
ctx.logger.info(`格式化后的日期: ${registerDate}`);
|
|
316
338
|
}
|
|
317
|
-
else {
|
|
318
|
-
// 如果日期解析失败,使用原始字符串或占位符
|
|
319
|
-
registerDate = dateStr || '未知时间';
|
|
320
|
-
ctx.logger.info(`日期解析失败,使用原始字符串: ${registerDate}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
// 如果日期字段不存在,使用占位符
|
|
325
|
-
registerDate = '未知时间';
|
|
326
|
-
ctx.logger.info(`未找到日期字段,使用默认值: ${registerDate}`);
|
|
327
339
|
}
|
|
328
340
|
}
|
|
329
341
|
catch (error) {
|
|
330
342
|
// 捕获任何异常,确保消息能正常生成
|
|
331
343
|
ctx.logger.error(`处理用户 ${username} 日期时出错: ${error}`);
|
|
332
|
-
registerDate = '未知时间';
|
|
333
344
|
}
|
|
334
345
|
// 构建 @全体成员 文本(适配 QQ 官方 bot 和其他适配器)
|
|
335
346
|
const atAllText = mention && config.mentionAll ? '@全体成员 ' : '';
|
|
336
|
-
//
|
|
337
|
-
|
|
338
|
-
//
|
|
347
|
+
// 只使用一个极简表情
|
|
348
|
+
const messageType = '👤';
|
|
349
|
+
// 构建核心消息内容,严格控制格式和换行
|
|
350
|
+
// 格式:[表情] [@全体] 新用户注册 - [用户名]
|
|
351
|
+
// 注册时间: [时间]
|
|
352
|
+
let message = `${messageType} ${atAllText}新用户注册 - ${username}\n注册时间: ${registerDate}`;
|
|
353
|
+
// 严格控制整体消息长度为 300 字符
|
|
339
354
|
if (message.length > 300) {
|
|
340
355
|
message = message.substring(0, 297) + '...';
|
|
341
356
|
ctx.logger.warn(`用户消息超长,已截断,用户 ID: ${user.id}`);
|
|
@@ -392,9 +407,9 @@ function apply(ctx, config) {
|
|
|
392
407
|
ctx.logger.info(`正在处理目标: ${target}`);
|
|
393
408
|
// 直接使用原始目标字符串,不进行数字转换,避免丢失平台前缀等信息
|
|
394
409
|
const stringTarget = target;
|
|
395
|
-
const
|
|
410
|
+
const message = formatPostMessage(post, true, false);
|
|
396
411
|
ctx.logger.info(`准备推送新文章到目标: ${stringTarget}`);
|
|
397
|
-
await bot.sendMessage(stringTarget,
|
|
412
|
+
await bot.sendMessage(stringTarget, message);
|
|
398
413
|
ctx.logger.info(`已推送新文章到 ${stringTarget}: ${post.title.rendered}`);
|
|
399
414
|
}
|
|
400
415
|
catch (error) {
|
|
@@ -427,9 +442,9 @@ function apply(ctx, config) {
|
|
|
427
442
|
try {
|
|
428
443
|
ctx.logger.info(`正在处理目标: ${target}`);
|
|
429
444
|
const stringTarget = target;
|
|
430
|
-
const
|
|
445
|
+
const message = formatPostMessage(post, true, true);
|
|
431
446
|
ctx.logger.info(`准备推送文章更新到目标: ${stringTarget}`);
|
|
432
|
-
await bot.sendMessage(stringTarget,
|
|
447
|
+
await bot.sendMessage(stringTarget, message);
|
|
433
448
|
ctx.logger.info(`已推送文章更新到 ${stringTarget}: ${post.title.rendered}`);
|
|
434
449
|
}
|
|
435
450
|
catch (error) {
|
|
@@ -455,9 +470,9 @@ function apply(ctx, config) {
|
|
|
455
470
|
ctx.logger.info(`正在处理目标: ${target}`);
|
|
456
471
|
// 直接使用原始目标字符串,与新文章推送逻辑保持一致
|
|
457
472
|
const stringTarget = target;
|
|
458
|
-
const
|
|
473
|
+
const message = formatUserMessage(user, true);
|
|
459
474
|
ctx.logger.info(`准备推送新用户到目标: ${stringTarget}`);
|
|
460
|
-
await bot.sendMessage(stringTarget,
|
|
475
|
+
await bot.sendMessage(stringTarget, message);
|
|
461
476
|
ctx.logger.info(`已推送新用户到 ${stringTarget}: ${user.name}`);
|
|
462
477
|
}
|
|
463
478
|
catch (error) {
|