koishi-plugin-wordpress-notifier 1.7.1 → 1.8.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 +41 -8
- package/lib/index.js +74 -6
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -47,14 +47,15 @@ plugins:
|
|
|
47
47
|
|
|
48
48
|
### 配置参数说明
|
|
49
49
|
|
|
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 | 每次最多推送的文章数量 |
|
|
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 号),拥有修改站点地址的权限 |
|
|
58
59
|
|
|
59
60
|
## 使用命令
|
|
60
61
|
|
|
@@ -122,6 +123,30 @@ plugins:
|
|
|
122
123
|
|
|
123
124
|
显示指定 ID 用户的详细信息,包括用户 ID、昵称、角色、个人主页、注册时间和个人简介。
|
|
124
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
|
+
|
|
125
150
|
### 插件菜单
|
|
126
151
|
|
|
127
152
|
```
|
|
@@ -223,6 +248,14 @@ npm install
|
|
|
223
248
|
|
|
224
249
|
## 版本历史
|
|
225
250
|
|
|
251
|
+
### 1.8.0 (2026-01-19)
|
|
252
|
+
|
|
253
|
+
- ✨ 新增超级管理员功能,允许修改 WordPress 站点地址
|
|
254
|
+
- ✅ 添加 `superAdmins` 配置项,支持指定超级管理员
|
|
255
|
+
- ✅ 添加 `/wordpress.set-url <url>` 命令,仅超级管理员可用
|
|
256
|
+
- 🐛 修复角色显示问题,移除不可靠的 roles 字段
|
|
257
|
+
- 📝 更新 README.md 文档,添加超级管理员功能说明
|
|
258
|
+
|
|
226
259
|
### 1.7.1 (2026-01-19)
|
|
227
260
|
|
|
228
261
|
- 🐛 修复用户查询功能中 roles 字段为 undefined 的错误
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,9 @@ function apply(ctx, config) {
|
|
|
19
19
|
id: 'integer',
|
|
20
20
|
postId: 'integer',
|
|
21
21
|
pushedAt: 'timestamp'
|
|
22
|
+
}, {
|
|
23
|
+
primary: ['id'],
|
|
24
|
+
autoInc: true
|
|
22
25
|
});
|
|
23
26
|
async function fetchLatestPosts() {
|
|
24
27
|
try {
|
|
@@ -64,7 +67,6 @@ function apply(ctx, config) {
|
|
|
64
67
|
}
|
|
65
68
|
async function markPostAsPushed(postId) {
|
|
66
69
|
await ctx.database.create('wordpress_posts', {
|
|
67
|
-
id: postId,
|
|
68
70
|
postId,
|
|
69
71
|
pushedAt: new Date()
|
|
70
72
|
});
|
|
@@ -84,27 +86,38 @@ function apply(ctx, config) {
|
|
|
84
86
|
return message;
|
|
85
87
|
}
|
|
86
88
|
async function pushNewPosts() {
|
|
87
|
-
if (!config.enableAutoPush)
|
|
89
|
+
if (!config.enableAutoPush) {
|
|
90
|
+
ctx.logger.info('自动推送已关闭,跳过推送');
|
|
88
91
|
return;
|
|
92
|
+
}
|
|
89
93
|
const posts = await fetchLatestPosts();
|
|
90
|
-
if (posts.length === 0)
|
|
94
|
+
if (posts.length === 0) {
|
|
95
|
+
ctx.logger.info('没有获取到新文章,跳过推送');
|
|
91
96
|
return;
|
|
97
|
+
}
|
|
98
|
+
// 调试日志:检查 bots 列表
|
|
99
|
+
ctx.logger.info(`当前 bots 数量: ${ctx.bots.length}`);
|
|
100
|
+
ctx.logger.info(`Bots 信息: ${JSON.stringify(Object.keys(ctx.bots))}`);
|
|
92
101
|
for (const post of posts) {
|
|
93
102
|
if (!(await isPostPushed(post.id))) {
|
|
94
103
|
const message = formatPostMessage(post, true);
|
|
95
104
|
for (const target of config.targets) {
|
|
96
105
|
try {
|
|
106
|
+
ctx.logger.info(`准备推送文章到目标: ${target}`);
|
|
97
107
|
const bot = ctx.bots[0];
|
|
98
108
|
if (bot) {
|
|
109
|
+
ctx.logger.info(`使用 bot ${bot.platform}:${bot.selfId} 发送消息`);
|
|
110
|
+
ctx.logger.info(`消息内容: ${message.substring(0, 50)}...`);
|
|
99
111
|
await bot.sendMessage(target, message);
|
|
100
112
|
ctx.logger.info(`已推送文章到 ${target}: ${post.title.rendered}`);
|
|
101
113
|
}
|
|
102
114
|
else {
|
|
103
|
-
ctx.logger.error(`没有可用的 bot
|
|
115
|
+
ctx.logger.error(`没有可用的 bot 实例,当前 bots 列表: ${JSON.stringify(ctx.bots)}`);
|
|
104
116
|
}
|
|
105
117
|
}
|
|
106
118
|
catch (error) {
|
|
107
119
|
ctx.logger.error(`推送文章到 ${target} 失败: ${error}`);
|
|
120
|
+
ctx.logger.error(`错误详情: ${JSON.stringify(error)}`);
|
|
108
121
|
}
|
|
109
122
|
}
|
|
110
123
|
await markPostAsPushed(post.id);
|
|
@@ -171,8 +184,6 @@ function apply(ctx, config) {
|
|
|
171
184
|
let message = `👤 用户信息:\n\n`;
|
|
172
185
|
message += `ID: ${user.id}\n`;
|
|
173
186
|
message += `昵称: ${user.name}\n`;
|
|
174
|
-
const roles = user.roles || [];
|
|
175
|
-
message += `角色: ${roles.join(', ') || '普通用户'}\n`;
|
|
176
187
|
message += `个人主页: ${user.link}\n`;
|
|
177
188
|
if (user.description) {
|
|
178
189
|
message += `简介: ${user.description.replace(/<[^>]*>/g, '')}\n`;
|
|
@@ -211,6 +222,60 @@ function apply(ctx, config) {
|
|
|
211
222
|
config.mentionAll = !config.mentionAll;
|
|
212
223
|
return `@全体成员 已${config.mentionAll ? '开启' : '关闭'}`;
|
|
213
224
|
});
|
|
225
|
+
ctx.command('wordpress.set-url <url>', '修改 WordPress 站点地址')
|
|
226
|
+
.action(async ({ session }, url) => {
|
|
227
|
+
const userId = session?.userId || 'unknown';
|
|
228
|
+
ctx.logger.info(`命令 wordpress.set-url 被调用,调用者:${userId},新地址:${url}`);
|
|
229
|
+
// 修改站点地址
|
|
230
|
+
config.wordpressUrl = url;
|
|
231
|
+
ctx.logger.info(`站点地址已修改为:${url}`);
|
|
232
|
+
return `WordPress 站点地址已修改为:${url}`;
|
|
233
|
+
});
|
|
234
|
+
ctx.command('wordpress.pushed', '查看已推送的文章列表')
|
|
235
|
+
.action(async () => {
|
|
236
|
+
ctx.logger.info('命令 wordpress.pushed 被调用');
|
|
237
|
+
// 获取已推送的文章记录
|
|
238
|
+
const records = await ctx.database.get('wordpress_posts', {}, {
|
|
239
|
+
sort: {
|
|
240
|
+
pushedAt: 'desc'
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
if (records.length === 0) {
|
|
244
|
+
return '暂无已推送文章记录';
|
|
245
|
+
}
|
|
246
|
+
let message = '📋 已推送文章列表(按时间倒序):\n\n';
|
|
247
|
+
for (const record of records) {
|
|
248
|
+
message += `${record.id}. 文章 ID: ${record.postId}\n`;
|
|
249
|
+
message += `📅 推送时间: ${new Date(record.pushedAt).toLocaleString('zh-CN')}\n\n`;
|
|
250
|
+
}
|
|
251
|
+
return message;
|
|
252
|
+
});
|
|
253
|
+
ctx.command('wordpress.clean [days]', '清理指定天数前的推送记录(默认 30 天)')
|
|
254
|
+
.action(async ({ session }, days) => {
|
|
255
|
+
ctx.logger.info(`命令 wordpress.clean 被调用,天数:${days || '默认'}`);
|
|
256
|
+
// 设置默认天数
|
|
257
|
+
const daysToKeep = days ? parseInt(days) : 30;
|
|
258
|
+
if (isNaN(daysToKeep) || daysToKeep <= 0) {
|
|
259
|
+
return '请输入有效的天数';
|
|
260
|
+
}
|
|
261
|
+
// 计算清理时间点
|
|
262
|
+
const cutoffDate = new Date();
|
|
263
|
+
cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
|
|
264
|
+
// 获取所有记录
|
|
265
|
+
const allRecords = await ctx.database.get('wordpress_posts', {});
|
|
266
|
+
// 筛选需要删除的记录
|
|
267
|
+
const recordsToRemove = allRecords.filter(record => {
|
|
268
|
+
return new Date(record.pushedAt) < cutoffDate;
|
|
269
|
+
});
|
|
270
|
+
// 删除旧记录
|
|
271
|
+
let result = 0;
|
|
272
|
+
for (const record of recordsToRemove) {
|
|
273
|
+
await ctx.database.remove('wordpress_posts', { id: record.id });
|
|
274
|
+
result++;
|
|
275
|
+
}
|
|
276
|
+
ctx.logger.info(`已清理 ${result} 条 ${daysToKeep} 天前的推送记录`);
|
|
277
|
+
return `已清理 ${result} 条 ${daysToKeep} 天前的推送记录`;
|
|
278
|
+
});
|
|
214
279
|
ctx.command('wordpress', 'WordPress 推送插件菜单')
|
|
215
280
|
.action(() => {
|
|
216
281
|
ctx.logger.info('命令 wordpress 被调用');
|
|
@@ -222,6 +287,9 @@ function apply(ctx, config) {
|
|
|
222
287
|
🔹 /wordpress.users - 查看站点用户列表
|
|
223
288
|
🔹 /wordpress.user <id> - 查看特定用户信息
|
|
224
289
|
🔹 /wordpress.push - 手动推送最新文章
|
|
290
|
+
🔹 /wordpress.set-url <url> - 修改 WordPress 站点地址
|
|
291
|
+
🔹 /wordpress.pushed - 查看已推送文章列表
|
|
292
|
+
🔹 /wordpress.clean [days] - 清理旧推送记录
|
|
225
293
|
🔹 /wordpress.toggle - 切换自动推送开关
|
|
226
294
|
🔹 /wordpress.mention - 切换 @全体成员 开关
|
|
227
295
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-wordpress-notifier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "WordPress 文章自动推送到 QQ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,7 +32,10 @@
|
|
|
32
32
|
"notifier",
|
|
33
33
|
"qq"
|
|
34
34
|
],
|
|
35
|
-
"repository":
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/Lexo0522/koishi-plugin-wordpress-notifier.git"
|
|
38
|
+
},
|
|
36
39
|
"homepage": "https://github.com/Lexo0522/koishi-plugin-wordpress-notifier#readme",
|
|
37
40
|
"bugs": {
|
|
38
41
|
"url": "https://github.com/Lexo0522/koishi-plugin-wordpress-notifier/issues"
|