koishi-plugin-wordpress-notifier 1.7.0 → 1.8.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 +124 -51
- package/lib/index.d.ts +6 -2
- package/lib/index.js +88 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
自动从 WordPress 网站获取最新文章并推送到指定 QQ 群或私聊。
|
|
4
4
|
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- ✅ 自动从 WordPress REST API 获取最新文章
|
|
8
|
-
- ✅ 定时推送新文章到指定 QQ 群或私聊
|
|
9
|
-
- ✅ 支持手动查询最新文章和文章列表
|
|
10
|
-
- ✅
|
|
11
|
-
- ✅
|
|
12
|
-
- ✅
|
|
13
|
-
- ✅
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- ✅ 自动从 WordPress REST API 获取最新文章
|
|
8
|
+
- ✅ 定时推送新文章到指定 QQ 群或私聊
|
|
9
|
+
- ✅ 支持手动查询最新文章和文章列表
|
|
10
|
+
- ✅ 支持查询 WordPress 站点用户信息
|
|
11
|
+
- ✅ 支持 @全体成员
|
|
12
|
+
- ✅ 完善的去重机制,避免重复推送
|
|
13
|
+
- ✅ 数据库持久化存储,机器人重启不丢失记录
|
|
14
|
+
- ✅ 采用服务模式架构,便于扩展和维护
|
|
14
15
|
- ✅ 支持自动推送开关
|
|
15
16
|
|
|
16
17
|
## 安装
|
|
@@ -46,14 +47,15 @@ plugins:
|
|
|
46
47
|
|
|
47
48
|
### 配置参数说明
|
|
48
49
|
|
|
49
|
-
| 参数 | 类型 | 默认值 | 说明 |
|
|
50
|
-
|------|------|--------|------|
|
|
51
|
-
| `wordpressUrl` | string | 必填 | WordPress 网站地址(例如:https://example.com) |
|
|
52
|
-
| `interval` | number | 3600000 | 检查间隔,单位毫秒(默认 1 小时 = 3600000 毫秒) |
|
|
53
|
-
| `targets` | array | 必填 | 推送目标列表,可以是群号或 QQ 号 |
|
|
54
|
-
| `enableAutoPush` | boolean | true | 是否启用自动推送 |
|
|
55
|
-
| `mentionAll` | boolean | false | 是否在推送时 @全体成员 |
|
|
56
|
-
| `maxArticles` | number | 5 | 每次最多推送的文章数量 |
|
|
50
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
51
|
+
|------|------|--------|------|
|
|
52
|
+
| `wordpressUrl` | string | 必填 | WordPress 网站地址(例如:https://example.com) |
|
|
53
|
+
| `interval` | number | 3600000 | 检查间隔,单位毫秒(默认 1 小时 = 3600000 毫秒) |
|
|
54
|
+
| `targets` | array | 必填 | 推送目标列表,可以是群号或 QQ 号 |
|
|
55
|
+
| `enableAutoPush` | boolean | true | 是否启用自动推送 |
|
|
56
|
+
| `mentionAll` | boolean | false | 是否在推送时 @全体成员 |
|
|
57
|
+
| `maxArticles` | number | 5 | 每次最多推送的文章数量 |
|
|
58
|
+
| `superAdmins` | array | [] | 超级管理员列表(QQ 号),拥有修改站点地址的权限 |
|
|
57
59
|
|
|
58
60
|
## 使用命令
|
|
59
61
|
|
|
@@ -97,14 +99,54 @@ plugins:
|
|
|
97
99
|
|
|
98
100
|
开启或关闭自动推送功能。
|
|
99
101
|
|
|
100
|
-
### 切换 @全体成员 开关
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
/wordpress.mention
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
开启或关闭 @全体成员 功能。
|
|
107
|
-
|
|
102
|
+
### 切换 @全体成员 开关
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
/wordpress.mention
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
开启或关闭 @全体成员 功能。
|
|
109
|
+
|
|
110
|
+
### 查看站点用户列表
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
/wordpress.users
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
显示 WordPress 站点的所有用户列表,包含用户 ID、名称、角色和个人主页链接。
|
|
117
|
+
|
|
118
|
+
### 查看特定用户信息
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
/wordpress.user <id>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
显示指定 ID 用户的详细信息,包括用户 ID、昵称、角色、个人主页、注册时间和个人简介。
|
|
125
|
+
|
|
126
|
+
### 修改 WordPress 站点地址
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
/wordpress.set-url <url>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
修改 WordPress 站点地址,仅超级管理员可用。
|
|
133
|
+
|
|
134
|
+
### 查看已推送文章列表
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
/wordpress.pushed
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
查看已推送的文章列表,按推送时间倒序排列,显示文章 ID 和推送时间。
|
|
141
|
+
|
|
142
|
+
### 清理旧推送记录
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
/wordpress.clean [days]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
清理指定天数前的推送记录,默认清理 30 天前的记录,仅超级管理员可用。
|
|
149
|
+
|
|
108
150
|
### 插件菜单
|
|
109
151
|
|
|
110
152
|
```
|
|
@@ -204,32 +246,63 @@ cd external/wordpress-notifier
|
|
|
204
246
|
npm install
|
|
205
247
|
```
|
|
206
248
|
|
|
207
|
-
## 版本历史
|
|
208
|
-
|
|
209
|
-
### 1.
|
|
210
|
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
-
|
|
249
|
+
## 版本历史
|
|
250
|
+
|
|
251
|
+
### 1.8.0 (2026-01-19)
|
|
252
|
+
|
|
253
|
+
- ✨ 新增超级管理员功能,允许修改 WordPress 站点地址
|
|
254
|
+
- ✅ 添加 `superAdmins` 配置项,支持指定超级管理员
|
|
255
|
+
- ✅ 添加 `/wordpress.set-url <url>` 命令,仅超级管理员可用
|
|
256
|
+
- 🐛 修复角色显示问题,移除不可靠的 roles 字段
|
|
257
|
+
- 📝 更新 README.md 文档,添加超级管理员功能说明
|
|
258
|
+
|
|
259
|
+
### 1.7.1 (2026-01-19)
|
|
260
|
+
|
|
261
|
+
- 🐛 修复用户查询功能中 roles 字段为 undefined 的错误
|
|
262
|
+
- 📝 更新 README.md 文档,添加用户查询功能说明
|
|
263
|
+
|
|
264
|
+
### 1.7.0 (2026-01-19)
|
|
265
|
+
|
|
266
|
+
- ✨ 新增查询 WordPress 站点用户信息功能
|
|
267
|
+
- ✅ 添加 `/wordpress.users` 命令,查看站点用户列表
|
|
268
|
+
- ✅ 添加 `/wordpress.user <id>` 命令,查看特定用户信息
|
|
269
|
+
- 📝 更新主菜单,添加新命令选项
|
|
270
|
+
- 🔧 优化数据库表定义
|
|
271
|
+
|
|
272
|
+
### 1.6.0 (2026-01-15)
|
|
273
|
+
|
|
274
|
+
- 🐛 修复消息发送问题,使用 `bot.sendMessage` 替代 `broadcast`
|
|
275
|
+
- 🔧 优化消息发送逻辑
|
|
276
|
+
|
|
277
|
+
### 1.5.0 (2026-01-15)
|
|
278
|
+
|
|
279
|
+
- 🐛 修复数据库主键问题,添加 `id` 字段作为主键
|
|
280
|
+
- 🔧 优化数据库表结构
|
|
281
|
+
|
|
282
|
+
### 1.3.0 (2024-01-14)
|
|
283
|
+
|
|
284
|
+
- 📝 更新作者邮箱为 kate522@88.com
|
|
285
|
+
- 🔗 更新仓库地址为正确的 GitHub URL
|
|
286
|
+
- 📝 优化 README.md 文档和链接
|
|
287
|
+
|
|
288
|
+
### 1.2.0 (2024-01-14)
|
|
289
|
+
|
|
290
|
+
- 📝 优化 README.md 文档,添加详细的安装说明和常见问题
|
|
291
|
+
- 📦 优化 npm 包结构,只包含必要文件
|
|
292
|
+
|
|
293
|
+
### 1.1.0 (2024-01-14)
|
|
294
|
+
|
|
295
|
+
- ✨ 新增数据库持久化存储功能
|
|
296
|
+
- 🐛 修复推送目标配置问题,使用 `ctx.broadcast([target], message)` 正确发送到指定目标
|
|
297
|
+
- 🐛 修复 HTTP 服务注入问题,添加 `'http'` 到 inject 数组
|
|
298
|
+
- 📝 添加 `.npmignore` 文件,确保 npm 发布时只包含必要文件
|
|
299
|
+
- 📦 更新依赖项
|
|
300
|
+
|
|
301
|
+
### 1.0.0 (初始版本)
|
|
302
|
+
|
|
303
|
+
- 🎉 首次发布
|
|
304
|
+
- ✅ 基础推送功能
|
|
305
|
+
- ✅ 命令系统
|
|
233
306
|
- ✅ 去重机制
|
|
234
307
|
|
|
235
308
|
## 许可证
|
package/lib/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface Config {
|
|
|
13
13
|
enableAutoPush: boolean;
|
|
14
14
|
mentionAll: boolean;
|
|
15
15
|
maxArticles: number;
|
|
16
|
+
superAdmins: string[];
|
|
16
17
|
}
|
|
17
18
|
export interface WordPressPost {
|
|
18
19
|
id: number;
|
|
@@ -38,8 +39,11 @@ export interface WordPressUser {
|
|
|
38
39
|
'48': string;
|
|
39
40
|
'96': string;
|
|
40
41
|
};
|
|
41
|
-
registered_date
|
|
42
|
-
roles
|
|
42
|
+
registered_date?: string;
|
|
43
|
+
roles?: string[];
|
|
44
|
+
slug?: string;
|
|
45
|
+
url?: string;
|
|
46
|
+
meta?: any[];
|
|
43
47
|
}
|
|
44
48
|
export interface WordPressPostRecord {
|
|
45
49
|
id: number;
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,8 @@ exports.Config = koishi_1.Schema.object({
|
|
|
11
11
|
targets: koishi_1.Schema.array(koishi_1.Schema.string()).description('推送目标(群号或 QQ 号)'),
|
|
12
12
|
enableAutoPush: koishi_1.Schema.boolean().default(true).description('是否启用自动推送'),
|
|
13
13
|
mentionAll: koishi_1.Schema.boolean().default(false).description('是否 @全体成员'),
|
|
14
|
-
maxArticles: koishi_1.Schema.number().default(5).description('每次最多推送的文章数量')
|
|
14
|
+
maxArticles: koishi_1.Schema.number().default(5).description('每次最多推送的文章数量'),
|
|
15
|
+
superAdmins: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description('超级管理员列表(QQ 号)')
|
|
15
16
|
});
|
|
16
17
|
function apply(ctx, config) {
|
|
17
18
|
ctx.logger.info('WordPress 推送插件已加载');
|
|
@@ -19,6 +20,9 @@ function apply(ctx, config) {
|
|
|
19
20
|
id: 'integer',
|
|
20
21
|
postId: 'integer',
|
|
21
22
|
pushedAt: 'timestamp'
|
|
23
|
+
}, {
|
|
24
|
+
primary: ['id'],
|
|
25
|
+
autoInc: true
|
|
22
26
|
});
|
|
23
27
|
async function fetchLatestPosts() {
|
|
24
28
|
try {
|
|
@@ -151,7 +155,7 @@ function apply(ctx, config) {
|
|
|
151
155
|
}
|
|
152
156
|
let message = '👥 WordPress 站点用户列表:\n\n';
|
|
153
157
|
for (const user of users) {
|
|
154
|
-
message += `${user.id}. ${user.name}
|
|
158
|
+
message += `${user.id}. ${user.name}\n`;
|
|
155
159
|
message += `🔗 ${user.link}\n\n`;
|
|
156
160
|
}
|
|
157
161
|
return message;
|
|
@@ -170,12 +174,13 @@ function apply(ctx, config) {
|
|
|
170
174
|
let message = `👤 用户信息:\n\n`;
|
|
171
175
|
message += `ID: ${user.id}\n`;
|
|
172
176
|
message += `昵称: ${user.name}\n`;
|
|
173
|
-
message += `角色: ${user.roles.join(', ')}\n`;
|
|
174
177
|
message += `个人主页: ${user.link}\n`;
|
|
175
178
|
if (user.description) {
|
|
176
179
|
message += `简介: ${user.description.replace(/<[^>]*>/g, '')}\n`;
|
|
177
180
|
}
|
|
178
|
-
|
|
181
|
+
if (user.registered_date) {
|
|
182
|
+
message += `注册时间: ${new Date(user.registered_date).toLocaleString('zh-CN')}\n`;
|
|
183
|
+
}
|
|
179
184
|
return message;
|
|
180
185
|
});
|
|
181
186
|
ctx.command('wordpress.push', '手动推送最新文章')
|
|
@@ -207,20 +212,88 @@ function apply(ctx, config) {
|
|
|
207
212
|
config.mentionAll = !config.mentionAll;
|
|
208
213
|
return `@全体成员 已${config.mentionAll ? '开启' : '关闭'}`;
|
|
209
214
|
});
|
|
215
|
+
ctx.command('wordpress.set-url <url>', '修改 WordPress 站点地址(仅超级管理员可用)')
|
|
216
|
+
.action(async ({ session }, url) => {
|
|
217
|
+
const userId = session?.userId || 'unknown';
|
|
218
|
+
ctx.logger.info(`命令 wordpress.set-url 被调用,调用者:${userId},新地址:${url}`);
|
|
219
|
+
// 检查是否为超级管理员
|
|
220
|
+
if (!session?.userId || !config.superAdmins.includes(session.userId)) {
|
|
221
|
+
ctx.logger.warn(`用户 ${userId} 尝试修改站点地址,但不是超级管理员`);
|
|
222
|
+
return '你没有权限执行此命令';
|
|
223
|
+
}
|
|
224
|
+
// 修改站点地址
|
|
225
|
+
config.wordpressUrl = url;
|
|
226
|
+
ctx.logger.info(`站点地址已修改为:${url}`);
|
|
227
|
+
return `WordPress 站点地址已修改为:${url}`;
|
|
228
|
+
});
|
|
229
|
+
ctx.command('wordpress.pushed', '查看已推送的文章列表')
|
|
230
|
+
.action(async () => {
|
|
231
|
+
ctx.logger.info('命令 wordpress.pushed 被调用');
|
|
232
|
+
// 获取已推送的文章记录
|
|
233
|
+
const records = await ctx.database.get('wordpress_posts', {}, {
|
|
234
|
+
sort: {
|
|
235
|
+
pushedAt: 'desc'
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
if (records.length === 0) {
|
|
239
|
+
return '暂无已推送文章记录';
|
|
240
|
+
}
|
|
241
|
+
let message = '📋 已推送文章列表(按时间倒序):\n\n';
|
|
242
|
+
for (const record of records) {
|
|
243
|
+
message += `${record.id}. 文章 ID: ${record.postId}\n`;
|
|
244
|
+
message += `📅 推送时间: ${new Date(record.pushedAt).toLocaleString('zh-CN')}\n\n`;
|
|
245
|
+
}
|
|
246
|
+
return message;
|
|
247
|
+
});
|
|
248
|
+
ctx.command('wordpress.clean [days]', '清理指定天数前的推送记录(默认 30 天)')
|
|
249
|
+
.action(async ({ session }, days) => {
|
|
250
|
+
ctx.logger.info(`命令 wordpress.clean 被调用,天数:${days || '默认'}`);
|
|
251
|
+
// 检查是否为超级管理员
|
|
252
|
+
const userId = session?.userId || 'unknown';
|
|
253
|
+
if (!session?.userId || !config.superAdmins.includes(session.userId)) {
|
|
254
|
+
ctx.logger.warn(`用户 ${userId} 尝试清理记录,但不是超级管理员`);
|
|
255
|
+
return '你没有权限执行此命令';
|
|
256
|
+
}
|
|
257
|
+
// 设置默认天数
|
|
258
|
+
const daysToKeep = days ? parseInt(days) : 30;
|
|
259
|
+
if (isNaN(daysToKeep) || daysToKeep <= 0) {
|
|
260
|
+
return '请输入有效的天数';
|
|
261
|
+
}
|
|
262
|
+
// 计算清理时间点
|
|
263
|
+
const cutoffDate = new Date();
|
|
264
|
+
cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
|
|
265
|
+
// 获取所有记录
|
|
266
|
+
const allRecords = await ctx.database.get('wordpress_posts', {});
|
|
267
|
+
// 筛选需要删除的记录
|
|
268
|
+
const recordsToRemove = allRecords.filter(record => {
|
|
269
|
+
return new Date(record.pushedAt) < cutoffDate;
|
|
270
|
+
});
|
|
271
|
+
// 删除旧记录
|
|
272
|
+
let result = 0;
|
|
273
|
+
for (const record of recordsToRemove) {
|
|
274
|
+
await ctx.database.remove('wordpress_posts', { id: record.id });
|
|
275
|
+
result++;
|
|
276
|
+
}
|
|
277
|
+
ctx.logger.info(`已清理 ${result} 条 ${daysToKeep} 天前的推送记录`);
|
|
278
|
+
return `已清理 ${result} 条 ${daysToKeep} 天前的推送记录`;
|
|
279
|
+
});
|
|
210
280
|
ctx.command('wordpress', 'WordPress 推送插件菜单')
|
|
211
281
|
.action(() => {
|
|
212
282
|
ctx.logger.info('命令 wordpress 被调用');
|
|
213
|
-
return `📚 WordPress 推送插件菜单:
|
|
214
|
-
|
|
215
|
-
🔹 /wordpress.status - 查看插件状态
|
|
216
|
-
🔹 /wordpress.latest - 查看最新文章
|
|
217
|
-
🔹 /wordpress.list - 查看文章列表
|
|
218
|
-
🔹 /wordpress.users - 查看站点用户列表
|
|
219
|
-
🔹 /wordpress.user <id> - 查看特定用户信息
|
|
220
|
-
🔹 /wordpress.push - 手动推送最新文章
|
|
221
|
-
🔹 /wordpress.
|
|
222
|
-
🔹 /wordpress.
|
|
223
|
-
|
|
283
|
+
return `📚 WordPress 推送插件菜单:
|
|
284
|
+
|
|
285
|
+
🔹 /wordpress.status - 查看插件状态
|
|
286
|
+
🔹 /wordpress.latest - 查看最新文章
|
|
287
|
+
🔹 /wordpress.list - 查看文章列表
|
|
288
|
+
🔹 /wordpress.users - 查看站点用户列表
|
|
289
|
+
🔹 /wordpress.user <id> - 查看特定用户信息
|
|
290
|
+
🔹 /wordpress.push - 手动推送最新文章
|
|
291
|
+
🔹 /wordpress.set-url <url> - 修改 WordPress 站点地址
|
|
292
|
+
🔹 /wordpress.pushed - 查看已推送文章列表
|
|
293
|
+
🔹 /wordpress.clean [days] - 清理旧推送记录
|
|
294
|
+
🔹 /wordpress.toggle - 切换自动推送开关
|
|
295
|
+
🔹 /wordpress.mention - 切换 @全体成员 开关
|
|
296
|
+
|
|
224
297
|
💡 提示:所有命令都需要加 / 前缀`;
|
|
225
298
|
});
|
|
226
299
|
ctx.on('ready', async () => {
|