koishi-plugin-wordpress-notifier 2.0.9 → 2.3.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 +57 -29
- package/lib/index.d.ts +0 -6
- package/lib/index.js +39 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -265,35 +265,6 @@ targets:
|
|
|
265
265
|
|
|
266
266
|
不会!插件使用数据库持久化存储已推送的文章记录,机器人重启后不会重复推送。
|
|
267
267
|
|
|
268
|
-
## 开发
|
|
269
|
-
|
|
270
|
-
插件位于 `external/wordpress-notifier/` 目录。
|
|
271
|
-
|
|
272
|
-
### 编译插件
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
cd external/wordpress-notifier
|
|
276
|
-
npm run build
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### 重新安装依赖
|
|
280
|
-
|
|
281
|
-
```bash
|
|
282
|
-
cd external/wordpress-notifier
|
|
283
|
-
npm install
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
## 版本历史
|
|
287
|
-
|
|
288
|
-
### 2.0.9 (2026-01-25)
|
|
289
|
-
|
|
290
|
-
- 🔧 增强用户注册日期处理,支持多种日期字段格式
|
|
291
|
-
- ✅ 支持WordPress主题中添加的`user_registered`和`registered_date`字段
|
|
292
|
-
- ✅ 在API请求中添加_fields参数,明确请求注册日期相关字段
|
|
293
|
-
- ✅ 请求字段包括:id,name,slug,date,date_registered,registered_date,user_registered,created_at,registeredAt,email,roles,url,description,link,avatar_urls
|
|
294
|
-
- ✅ 确保API返回完整的用户信息,包括注册日期
|
|
295
|
-
- ✅ 优化日期字段优先级顺序,优先使用`registered_date`和`user_registered`字段
|
|
296
|
-
|
|
297
268
|
### 如何获取用户注册日期
|
|
298
269
|
|
|
299
270
|
WordPress REST API默认可能不会返回用户注册日期字段。您可以通过以下两种方式之一来启用:
|
|
@@ -348,6 +319,63 @@ function add_user_registered_date_to_rest($response, $user, $request) {
|
|
|
348
319
|
|
|
349
320
|
添加上述代码后,插件将能够正确获取并显示用户注册日期。
|
|
350
321
|
|
|
322
|
+
## 开发
|
|
323
|
+
|
|
324
|
+
插件位于 `external/wordpress-notifier/` 目录。
|
|
325
|
+
|
|
326
|
+
### 编译插件
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
cd external/wordpress-notifier
|
|
330
|
+
npm run build
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 重新安装依赖
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
cd external/wordpress-notifier
|
|
337
|
+
npm install
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## 版本历史
|
|
341
|
+
|
|
342
|
+
### 2.3.0 (2026-01-25)
|
|
343
|
+
|
|
344
|
+
- 🔧 增强命令权限管理,限制敏感命令仅超级管理员可用
|
|
345
|
+
- ✅ 为`wordpress.set-url`命令添加超级管理员权限检查
|
|
346
|
+
- ✅ 为`wordpress.clean [days]`命令添加超级管理员权限检查
|
|
347
|
+
- ✅ 为`wordpress.toggle`命令添加超级管理员权限检查
|
|
348
|
+
- ✅ 为`wordpress.toggle-update`命令添加超级管理员权限检查
|
|
349
|
+
- ✅ 为`wordpress.toggle-user`命令添加超级管理员权限检查
|
|
350
|
+
- ✅ 为`wordpress.mention`命令添加超级管理员权限检查
|
|
351
|
+
- ✅ 添加了详细的日志记录,便于追踪非授权访问尝试
|
|
352
|
+
|
|
353
|
+
### 2.2.0 (2026-01-25)
|
|
354
|
+
|
|
355
|
+
- 🐛 修复重复推送问题,清理未使用的数据库表
|
|
356
|
+
- ✅ 移除了未使用的`wordpress_posts`表,统一使用`wordpress_group_pushes`表进行推送记录管理
|
|
357
|
+
- ✅ 修复了`wordpress.pushed`命令,使用`wordpress_group_pushes`表获取已推送记录
|
|
358
|
+
- ✅ 修复了`wordpress.clean`命令,移除了对`wordpress_posts`表的引用
|
|
359
|
+
- ✅ 增强了推送日志,添加了详细的调试信息,便于追踪推送流程
|
|
360
|
+
- ✅ 优化了`isGroupPushed`和`markGroupAsPushed`函数,添加了更多日志
|
|
361
|
+
|
|
362
|
+
### 2.1.0 (2026-01-25)
|
|
363
|
+
|
|
364
|
+
- 🔧 更新文档结构,将"如何获取用户注册日期"内容从版本历史移至常见问题部分
|
|
365
|
+
- ✅ 优化文档组织,提高用户查找信息的便利性
|
|
366
|
+
- ✅ 保持原有详细说明和代码示例不变
|
|
367
|
+
|
|
368
|
+
### 2.0.9 (2026-01-25)
|
|
369
|
+
|
|
370
|
+
- 🔧 增强用户注册日期处理,支持多种日期字段格式
|
|
371
|
+
- ✅ 支持WordPress主题中添加的`user_registered`和`registered_date`字段
|
|
372
|
+
- ✅ 在API请求中添加_fields参数,明确请求注册日期相关字段
|
|
373
|
+
- ✅ 请求字段包括:id,name,slug,date,date_registered,registered_date,user_registered,created_at,registeredAt,email,roles,url,description,link,avatar_urls
|
|
374
|
+
- ✅ 确保API返回完整的用户信息,包括注册日期
|
|
375
|
+
- ✅ 优化日期字段优先级顺序,优先使用`registered_date`和`user_registered`字段
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
351
379
|
### 2.0.8 (2026-01-25)
|
|
352
380
|
|
|
353
381
|
- 🔧 增强用户注册日期处理逻辑,尝试所有可能的日期字段
|
package/lib/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare const inject: string[];
|
|
|
3
3
|
export declare const name = "wordpress-notifier";
|
|
4
4
|
declare module 'koishi' {
|
|
5
5
|
interface Tables {
|
|
6
|
-
wordpress_posts: WordPressPostRecord;
|
|
7
6
|
wordpress_post_updates: WordPressPostUpdateRecord;
|
|
8
7
|
wordpress_user_registrations: WordPressUserRegistrationRecord;
|
|
9
8
|
wordpress_group_pushes: WordPressGroupPushRecord;
|
|
@@ -50,11 +49,6 @@ export interface WordPressUser {
|
|
|
50
49
|
roles: string[];
|
|
51
50
|
[key: string]: any;
|
|
52
51
|
}
|
|
53
|
-
export interface WordPressPostRecord {
|
|
54
|
-
id: number;
|
|
55
|
-
postId: number;
|
|
56
|
-
pushedAt: Date;
|
|
57
|
-
}
|
|
58
52
|
export interface WordPressPostUpdateRecord {
|
|
59
53
|
id: number;
|
|
60
54
|
postId: number;
|
package/lib/index.js
CHANGED
|
@@ -19,14 +19,6 @@ exports.Config = koishi_1.Schema.object({
|
|
|
19
19
|
});
|
|
20
20
|
function apply(ctx, config) {
|
|
21
21
|
ctx.logger.info('WordPress 推送插件已加载');
|
|
22
|
-
ctx.model.extend('wordpress_posts', {
|
|
23
|
-
id: 'integer',
|
|
24
|
-
postId: 'integer',
|
|
25
|
-
pushedAt: 'timestamp'
|
|
26
|
-
}, {
|
|
27
|
-
primary: ['id'],
|
|
28
|
-
autoInc: true
|
|
29
|
-
});
|
|
30
22
|
ctx.model.extend('wordpress_post_updates', {
|
|
31
23
|
id: 'integer',
|
|
32
24
|
postId: 'integer',
|
|
@@ -151,6 +143,7 @@ function apply(ctx, config) {
|
|
|
151
143
|
}
|
|
152
144
|
async function isGroupPushed(groupId, postId) {
|
|
153
145
|
const record = await ctx.database.get('wordpress_group_pushes', { groupId, postId });
|
|
146
|
+
ctx.logger.info(`检查群 ${groupId} 是否已推送文章 ${postId}:${record.length > 0 ? '是' : '否'}`);
|
|
154
147
|
return record.length > 0;
|
|
155
148
|
}
|
|
156
149
|
async function markUserAsPushed(userId) {
|
|
@@ -173,16 +166,20 @@ function apply(ctx, config) {
|
|
|
173
166
|
}
|
|
174
167
|
async function markGroupAsPushed(groupId, postId, isUpdate) {
|
|
175
168
|
const record = await ctx.database.get('wordpress_group_pushes', { groupId, postId });
|
|
176
|
-
|
|
169
|
+
ctx.logger.info(`准备标记群 ${groupId} 已推送文章 ${postId},当前记录数量:${record.length}`);
|
|
170
|
+
if (record.length > 0) {
|
|
177
171
|
// Koishi database API 不支持 update 方法,使用 remove + create 代替
|
|
172
|
+
ctx.logger.info(`已存在记录,删除旧记录`);
|
|
178
173
|
await ctx.database.remove('wordpress_group_pushes', { groupId, postId });
|
|
179
174
|
}
|
|
175
|
+
ctx.logger.info(`创建新的推送记录`);
|
|
180
176
|
await ctx.database.create('wordpress_group_pushes', {
|
|
181
177
|
groupId,
|
|
182
178
|
postId,
|
|
183
179
|
pushedAt: new Date(),
|
|
184
180
|
isUpdate
|
|
185
181
|
});
|
|
182
|
+
ctx.logger.info(`已标记群 ${groupId} 已推送文章 ${postId}`);
|
|
186
183
|
}
|
|
187
184
|
function formatPostMessage(post, mention = false, isUpdate = false) {
|
|
188
185
|
// 彻底过滤 HTML 标签和非法字符,只保留安全文本
|
|
@@ -464,30 +461,55 @@ ${targetText}
|
|
|
464
461
|
});
|
|
465
462
|
ctx.command('wordpress.toggle-update', '切换文章更新推送开关')
|
|
466
463
|
.action(async ({ session }) => {
|
|
464
|
+
// 检查是否为超级管理员
|
|
465
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
466
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.toggle-update 命令`);
|
|
467
|
+
return '您不是超级管理员,无法执行此命令';
|
|
468
|
+
}
|
|
467
469
|
ctx.logger.info('命令 wordpress.toggle-update 被调用');
|
|
468
470
|
config.enableUpdatePush = !config.enableUpdatePush;
|
|
469
471
|
return `文章更新推送已${config.enableUpdatePush ? '开启' : '关闭'}`;
|
|
470
472
|
});
|
|
471
473
|
ctx.command('wordpress.toggle-user', '切换新用户注册推送开关')
|
|
472
474
|
.action(async ({ session }) => {
|
|
475
|
+
// 检查是否为超级管理员
|
|
476
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
477
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.toggle-user 命令`);
|
|
478
|
+
return '您不是超级管理员,无法执行此命令';
|
|
479
|
+
}
|
|
473
480
|
ctx.logger.info('命令 wordpress.toggle-user 被调用');
|
|
474
481
|
config.enableUserPush = !config.enableUserPush;
|
|
475
482
|
return `新用户注册推送已${config.enableUserPush ? '开启' : '关闭'}`;
|
|
476
483
|
});
|
|
477
484
|
ctx.command('wordpress.toggle', '切换自动推送开关')
|
|
478
485
|
.action(async ({ session }) => {
|
|
486
|
+
// 检查是否为超级管理员
|
|
487
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
488
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.toggle 命令`);
|
|
489
|
+
return '您不是超级管理员,无法执行此命令';
|
|
490
|
+
}
|
|
479
491
|
ctx.logger.info('命令 wordpress.toggle 被调用');
|
|
480
492
|
config.enableAutoPush = !config.enableAutoPush;
|
|
481
493
|
return `自动推送已${config.enableAutoPush ? '开启' : '关闭'}`;
|
|
482
494
|
});
|
|
483
495
|
ctx.command('wordpress.mention', '切换 @全体成员 开关')
|
|
484
496
|
.action(async ({ session }) => {
|
|
497
|
+
// 检查是否为超级管理员
|
|
498
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
499
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.mention 命令`);
|
|
500
|
+
return '您不是超级管理员,无法执行此命令';
|
|
501
|
+
}
|
|
485
502
|
ctx.logger.info('命令 wordpress.mention 被调用');
|
|
486
503
|
config.mentionAll = !config.mentionAll;
|
|
487
504
|
return `@全体成员 已${config.mentionAll ? '开启' : '关闭'}`;
|
|
488
505
|
});
|
|
489
506
|
ctx.command('wordpress.set-url <url>', '修改 WordPress 站点地址')
|
|
490
507
|
.action(async ({ session }, url) => {
|
|
508
|
+
// 检查是否为超级管理员
|
|
509
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
510
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.set-url 命令`);
|
|
511
|
+
return '您不是超级管理员,无法执行此命令';
|
|
512
|
+
}
|
|
491
513
|
const userId = session?.userId || 'unknown';
|
|
492
514
|
ctx.logger.info(`命令 wordpress.set-url 被调用,调用者:${userId},新地址:${url}`);
|
|
493
515
|
// 修改站点地址
|
|
@@ -498,8 +520,8 @@ ${targetText}
|
|
|
498
520
|
ctx.command('wordpress.pushed', '查看已推送的文章列表')
|
|
499
521
|
.action(async () => {
|
|
500
522
|
ctx.logger.info('命令 wordpress.pushed 被调用');
|
|
501
|
-
//
|
|
502
|
-
const records = await ctx.database.get('
|
|
523
|
+
// 获取已推送的文章记录,使用 wordpress_group_pushes 表
|
|
524
|
+
const records = await ctx.database.get('wordpress_group_pushes', {}, {
|
|
503
525
|
sort: {
|
|
504
526
|
pushedAt: 'desc'
|
|
505
527
|
}
|
|
@@ -509,13 +531,18 @@ ${targetText}
|
|
|
509
531
|
}
|
|
510
532
|
let message = '📋 已推送文章列表(按时间倒序):\n\n';
|
|
511
533
|
for (const record of records) {
|
|
512
|
-
message += `${record.id}. 文章 ID: ${record.postId}
|
|
534
|
+
message += `${record.id}. 文章 ID: ${record.postId}(群:${record.groupId},${record.isUpdate ? '更新' : '新文章'})\n`;
|
|
513
535
|
message += `📅 推送时间: ${new Date(record.pushedAt).toLocaleString('zh-CN')}\n\n`;
|
|
514
536
|
}
|
|
515
537
|
return message;
|
|
516
538
|
});
|
|
517
539
|
ctx.command('wordpress.clean [days]', '清理指定天数前的推送记录(默认 30 天)')
|
|
518
540
|
.action(async ({ session }, days) => {
|
|
541
|
+
// 检查是否为超级管理员
|
|
542
|
+
if (!session || !session.userId || !ctx.root || !ctx.root.config || !ctx.root.config.superusers || !ctx.root.config.superusers.includes(session.userId)) {
|
|
543
|
+
ctx.logger.warn(`非超级管理员 ${session?.userId} 尝试调用 wordpress.clean 命令`);
|
|
544
|
+
return '您不是超级管理员,无法执行此命令';
|
|
545
|
+
}
|
|
519
546
|
ctx.logger.info(`命令 wordpress.clean 被调用,天数:${days || '默认'}`);
|
|
520
547
|
// 设置默认天数
|
|
521
548
|
const daysToKeep = days ? parseInt(days) : 30;
|
|
@@ -526,14 +553,10 @@ ${targetText}
|
|
|
526
553
|
const cutoffDate = new Date();
|
|
527
554
|
cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
|
|
528
555
|
// 获取所有记录
|
|
529
|
-
const allPostRecords = await ctx.database.get('wordpress_posts', {});
|
|
530
556
|
const allUpdateRecords = await ctx.database.get('wordpress_post_updates', {});
|
|
531
557
|
const allUserRecords = await ctx.database.get('wordpress_user_registrations', {});
|
|
532
558
|
const allGroupRecords = await ctx.database.get('wordpress_group_pushes', {});
|
|
533
559
|
// 筛选需要删除的记录
|
|
534
|
-
const postRecordsToRemove = allPostRecords.filter(record => {
|
|
535
|
-
return new Date(record.pushedAt) < cutoffDate;
|
|
536
|
-
});
|
|
537
560
|
const updateRecordsToRemove = allUpdateRecords.filter(record => {
|
|
538
561
|
return new Date(record.pushedAt) < cutoffDate;
|
|
539
562
|
});
|
|
@@ -545,10 +568,6 @@ ${targetText}
|
|
|
545
568
|
});
|
|
546
569
|
// 删除旧记录
|
|
547
570
|
let result = 0;
|
|
548
|
-
for (const record of postRecordsToRemove) {
|
|
549
|
-
await ctx.database.remove('wordpress_posts', { id: record.id });
|
|
550
|
-
result++;
|
|
551
|
-
}
|
|
552
571
|
for (const record of updateRecordsToRemove) {
|
|
553
572
|
await ctx.database.remove('wordpress_post_updates', { id: record.id });
|
|
554
573
|
result++;
|