koishi-plugin-wordpress-notifier 1.7.1 → 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 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.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;
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,8 +155,7 @@ function apply(ctx, config) {
151
155
  }
152
156
  let message = '👥 WordPress 站点用户列表:\n\n';
153
157
  for (const user of users) {
154
- const roles = user.roles || [];
155
- message += `${user.id}. ${user.name}(${roles.join(', ') || '普通用户'})\n`;
158
+ message += `${user.id}. ${user.name}\n`;
156
159
  message += `🔗 ${user.link}\n\n`;
157
160
  }
158
161
  return message;
@@ -171,8 +174,6 @@ function apply(ctx, config) {
171
174
  let message = `👤 用户信息:\n\n`;
172
175
  message += `ID: ${user.id}\n`;
173
176
  message += `昵称: ${user.name}\n`;
174
- const roles = user.roles || [];
175
- message += `角色: ${roles.join(', ') || '普通用户'}\n`;
176
177
  message += `个人主页: ${user.link}\n`;
177
178
  if (user.description) {
178
179
  message += `简介: ${user.description.replace(/<[^>]*>/g, '')}\n`;
@@ -211,6 +212,71 @@ function apply(ctx, config) {
211
212
  config.mentionAll = !config.mentionAll;
212
213
  return `@全体成员 已${config.mentionAll ? '开启' : '关闭'}`;
213
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
+ });
214
280
  ctx.command('wordpress', 'WordPress 推送插件菜单')
215
281
  .action(() => {
216
282
  ctx.logger.info('命令 wordpress 被调用');
@@ -222,6 +288,9 @@ function apply(ctx, config) {
222
288
  🔹 /wordpress.users - 查看站点用户列表
223
289
  🔹 /wordpress.user <id> - 查看特定用户信息
224
290
  🔹 /wordpress.push - 手动推送最新文章
291
+ 🔹 /wordpress.set-url <url> - 修改 WordPress 站点地址
292
+ 🔹 /wordpress.pushed - 查看已推送文章列表
293
+ 🔹 /wordpress.clean [days] - 清理旧推送记录
225
294
  🔹 /wordpress.toggle - 切换自动推送开关
226
295
  🔹 /wordpress.mention - 切换 @全体成员 开关
227
296
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordpress-notifier",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "WordPress 文章自动推送到 QQ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",