koishi-plugin-wordpress-notifier 2.0.0 → 2.0.2

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.
Files changed (3) hide show
  1. package/README.md +54 -14
  2. package/lib/index.js +29 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,13 +6,17 @@
6
6
 
7
7
  - ✅ 自动从 WordPress REST API 获取最新文章
8
8
  - ✅ 定时推送新文章到指定 QQ 群或私聊
9
+ - ✅ 支持文章更新推送
10
+ - ✅ 支持新用户注册推送
9
11
  - ✅ 支持手动查询最新文章和文章列表
10
- - ✅ 支持查询 WordPress 站点用户信息
11
12
  - ✅ 支持 @全体成员
12
13
  - ✅ 完善的去重机制,避免重复推送
14
+ - ✅ 按群聊标记推送记录,确保每个群只收到一次相同内容
13
15
  - ✅ 数据库持久化存储,机器人重启不丢失记录
14
16
  - ✅ 采用服务模式架构,便于扩展和维护
15
17
  - ✅ 支持自动推送开关
18
+ - ✅ 支持文章更新推送开关
19
+ - ✅ 支持新用户注册推送开关
16
20
 
17
21
  ## 安装
18
22
 
@@ -53,9 +57,10 @@ plugins:
53
57
  | `interval` | number | 3600000 | 检查间隔,单位毫秒(默认 1 小时 = 3600000 毫秒) |
54
58
  | `targets` | array | 必填 | 推送目标列表,可以是群号或 QQ 号 |
55
59
  | `enableAutoPush` | boolean | true | 是否启用自动推送 |
60
+ | `enableUpdatePush` | boolean | false | 是否启用文章更新推送 |
61
+ | `enableUserPush` | boolean | false | 是否启用新用户注册推送 |
56
62
  | `mentionAll` | boolean | false | 是否在推送时 @全体成员 |
57
63
  | `maxArticles` | number | 5 | 每次最多推送的文章数量 |
58
- | `superAdmins` | array | [] | 超级管理员列表(QQ 号),拥有修改站点地址的权限 |
59
64
 
60
65
  ## 使用命令
61
66
 
@@ -107,21 +112,21 @@ plugins:
107
112
 
108
113
  开启或关闭 @全体成员 功能。
109
114
 
110
- ### 查看站点用户列表
115
+ ### 切换文章更新推送开关
111
116
 
112
117
  ```
113
- /wordpress.users
118
+ /wordpress.toggle-update
114
119
  ```
115
120
 
116
- 显示 WordPress 站点的所有用户列表,包含用户 ID、名称、角色和个人主页链接。
121
+ 开启或关闭文章更新推送功能。
117
122
 
118
- ### 查看特定用户信息
123
+ ### 切换新用户注册推送开关
119
124
 
120
125
  ```
121
- /wordpress.user <id>
126
+ /wordpress.toggle-user
122
127
  ```
123
128
 
124
- 显示指定 ID 用户的详细信息,包括用户 ID、昵称、角色、个人主页、注册时间和个人简介。
129
+ 开启或关闭新用户注册推送功能。
125
130
 
126
131
  ### 修改 WordPress 站点地址
127
132
 
@@ -129,7 +134,7 @@ plugins:
129
134
  /wordpress.set-url <url>
130
135
  ```
131
136
 
132
- 修改 WordPress 站点地址,仅超级管理员可用。
137
+ 修改 WordPress 站点地址。
133
138
 
134
139
  ### 查看已推送文章列表
135
140
 
@@ -157,11 +162,23 @@ plugins:
157
162
 
158
163
  ## 工作原理
159
164
 
160
- 1. 插件启动时会自动创建数据库表 `wordpress_posts` 用于记录已推送的文章
161
- 2. 定时器每隔指定时间(默认 1 小时)检查一次 WordPress 网站的最新文章
162
- 3. 对于每篇新文章,检查是否已推送过
163
- 4. 如果是新文章,则格式化消息并推送到所有配置的目标
164
- 5. 推送成功后,将文章 ID 记录到数据库中
165
+ 1. 插件启动时会自动创建以下数据库表:
166
+ - `wordpress_posts`:记录已推送的新文章
167
+ - `wordpress_post_updates`:记录文章更新情况
168
+ - `wordpress_user_registrations`:记录已推送的新用户
169
+ - `wordpress_group_pushes`:按群聊标记推送记录,确保每个群只收到一次相同内容
170
+
171
+ 2. 定时器每隔指定时间(默认 1 小时)检查一次 WordPress 网站:
172
+ - 检查最新文章
173
+ - 检查文章更新
174
+ - 检查新用户注册
175
+
176
+ 3. 推送逻辑:
177
+ - 对于新文章,检查每个群聊是否已推送过
178
+ - 对于文章更新,检查是否有更新且该群聊已收到过原文
179
+ - 对于新用户,检查是否已推送过
180
+ - 格式化消息并推送到所有配置的目标
181
+ - 推送成功后,更新相应的数据库记录
165
182
 
166
183
  ## 注意事项
167
184
 
@@ -248,6 +265,29 @@ npm install
248
265
 
249
266
  ## 版本历史
250
267
 
268
+ ### 2.0.2 (2026-01-25)
269
+
270
+ - 🐛 修复每次重载时重新推送的问题
271
+ - 🔧 优化推送去重机制,只使用群聊记录跟踪推送状态
272
+ - 🔧 确保每个群聊只会收到一次相同的文章推送
273
+ - 🔧 优化错误处理,确保插件核心功能正常工作
274
+
275
+ ### 2.0.1 (2026-01-25)
276
+
277
+ - 📝 更新文档,完善新功能说明
278
+ - 🔧 优化代码结构
279
+
280
+ ### 2.0.0 (2026-01-25)
281
+
282
+ - ✨ 新增文章更新推送功能
283
+ - ✨ 新增新用户注册推送功能
284
+ - ✨ 实现按群聊标记推送记录,确保每个群只收到一次相同内容
285
+ - ✅ 支持开启/关闭文章更新推送
286
+ - ✅ 支持开启/关闭新用户注册推送
287
+ - ✅ 修改 wordpress.status 命令,仅显示当前群的推送目标
288
+ - 🔧 优化数据库表结构,添加多张数据表
289
+ - 🔧 优化清理命令,支持清理所有类型的推送记录
290
+
251
291
  ### 1.8.2 (2026-01-25)
252
292
 
253
293
  - 🐛 修复 Bot 实例获取方式,使用 `Object.values(ctx.bots)` 正确处理 Bot 对象
package/lib/index.js CHANGED
@@ -78,6 +78,8 @@ function apply(ctx, config) {
78
78
  }
79
79
  catch (error) {
80
80
  ctx.logger.error(`获取 WordPress 用户失败: ${error}`);
81
+ ctx.logger.error(`WordPress REST API 的 users 端点可能需要认证才能访问,当前版本暂不支持认证配置`);
82
+ // 返回空数组,确保插件继续运行
81
83
  return [];
82
84
  }
83
85
  }
@@ -94,10 +96,6 @@ function apply(ctx, config) {
94
96
  return [];
95
97
  }
96
98
  }
97
- async function isPostPushed(postId) {
98
- const record = await ctx.database.get('wordpress_posts', { postId });
99
- return record.length > 0;
100
- }
101
99
  async function isUserPushed(userId) {
102
100
  const record = await ctx.database.get('wordpress_user_registrations', { userId });
103
101
  return record.length > 0;
@@ -110,12 +108,6 @@ function apply(ctx, config) {
110
108
  const record = await ctx.database.get('wordpress_group_pushes', { groupId, postId });
111
109
  return record.length > 0;
112
110
  }
113
- async function markPostAsPushed(postId) {
114
- await ctx.database.create('wordpress_posts', {
115
- postId,
116
- pushedAt: new Date()
117
- });
118
- }
119
111
  async function markUserAsPushed(userId) {
120
112
  await ctx.database.create('wordpress_user_registrations', {
121
113
  userId,
@@ -243,10 +235,6 @@ function apply(ctx, config) {
243
235
  ctx.logger.error(`错误详情: ${JSON.stringify(error)}`);
244
236
  }
245
237
  }
246
- // 标记文章已推送(全局记录)
247
- if (!(await isPostPushed(post.id))) {
248
- await markPostAsPushed(post.id);
249
- }
250
238
  }
251
239
  }
252
240
  }
@@ -441,17 +429,41 @@ ${targetText}
441
429
  const cutoffDate = new Date();
442
430
  cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
443
431
  // 获取所有记录
444
- const allRecords = await ctx.database.get('wordpress_posts', {});
432
+ const allPostRecords = await ctx.database.get('wordpress_posts', {});
433
+ const allUpdateRecords = await ctx.database.get('wordpress_post_updates', {});
434
+ const allUserRecords = await ctx.database.get('wordpress_user_registrations', {});
435
+ const allGroupRecords = await ctx.database.get('wordpress_group_pushes', {});
445
436
  // 筛选需要删除的记录
446
- const recordsToRemove = allRecords.filter(record => {
437
+ const postRecordsToRemove = allPostRecords.filter(record => {
438
+ return new Date(record.pushedAt) < cutoffDate;
439
+ });
440
+ const updateRecordsToRemove = allUpdateRecords.filter(record => {
441
+ return new Date(record.pushedAt) < cutoffDate;
442
+ });
443
+ const userRecordsToRemove = allUserRecords.filter(record => {
444
+ return new Date(record.pushedAt) < cutoffDate;
445
+ });
446
+ const groupRecordsToRemove = allGroupRecords.filter(record => {
447
447
  return new Date(record.pushedAt) < cutoffDate;
448
448
  });
449
449
  // 删除旧记录
450
450
  let result = 0;
451
- for (const record of recordsToRemove) {
451
+ for (const record of postRecordsToRemove) {
452
452
  await ctx.database.remove('wordpress_posts', { id: record.id });
453
453
  result++;
454
454
  }
455
+ for (const record of updateRecordsToRemove) {
456
+ await ctx.database.remove('wordpress_post_updates', { id: record.id });
457
+ result++;
458
+ }
459
+ for (const record of userRecordsToRemove) {
460
+ await ctx.database.remove('wordpress_user_registrations', { id: record.id });
461
+ result++;
462
+ }
463
+ for (const record of groupRecordsToRemove) {
464
+ await ctx.database.remove('wordpress_group_pushes', { id: record.id });
465
+ result++;
466
+ }
455
467
  ctx.logger.info(`已清理 ${result} 条 ${daysToKeep} 天前的推送记录`);
456
468
  return `已清理 ${result} 条 ${daysToKeep} 天前的推送记录`;
457
469
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordpress-notifier",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "WordPress 文章自动推送到 QQ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",