koishi-plugin-wordpress-notifier 1.8.0 → 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/lib/index.d.ts +0 -1
- package/lib/index.js +18 -19
- package/package.json +5 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -11,8 +11,7 @@ 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('每次最多推送的文章数量')
|
|
15
|
-
superAdmins: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description('超级管理员列表(QQ 号)')
|
|
14
|
+
maxArticles: koishi_1.Schema.number().default(5).description('每次最多推送的文章数量')
|
|
16
15
|
});
|
|
17
16
|
function apply(ctx, config) {
|
|
18
17
|
ctx.logger.info('WordPress 推送插件已加载');
|
|
@@ -68,7 +67,6 @@ function apply(ctx, config) {
|
|
|
68
67
|
}
|
|
69
68
|
async function markPostAsPushed(postId) {
|
|
70
69
|
await ctx.database.create('wordpress_posts', {
|
|
71
|
-
id: postId,
|
|
72
70
|
postId,
|
|
73
71
|
pushedAt: new Date()
|
|
74
72
|
});
|
|
@@ -88,27 +86,38 @@ function apply(ctx, config) {
|
|
|
88
86
|
return message;
|
|
89
87
|
}
|
|
90
88
|
async function pushNewPosts() {
|
|
91
|
-
if (!config.enableAutoPush)
|
|
89
|
+
if (!config.enableAutoPush) {
|
|
90
|
+
ctx.logger.info('自动推送已关闭,跳过推送');
|
|
92
91
|
return;
|
|
92
|
+
}
|
|
93
93
|
const posts = await fetchLatestPosts();
|
|
94
|
-
if (posts.length === 0)
|
|
94
|
+
if (posts.length === 0) {
|
|
95
|
+
ctx.logger.info('没有获取到新文章,跳过推送');
|
|
95
96
|
return;
|
|
97
|
+
}
|
|
98
|
+
// 调试日志:检查 bots 列表
|
|
99
|
+
ctx.logger.info(`当前 bots 数量: ${ctx.bots.length}`);
|
|
100
|
+
ctx.logger.info(`Bots 信息: ${JSON.stringify(Object.keys(ctx.bots))}`);
|
|
96
101
|
for (const post of posts) {
|
|
97
102
|
if (!(await isPostPushed(post.id))) {
|
|
98
103
|
const message = formatPostMessage(post, true);
|
|
99
104
|
for (const target of config.targets) {
|
|
100
105
|
try {
|
|
106
|
+
ctx.logger.info(`准备推送文章到目标: ${target}`);
|
|
101
107
|
const bot = ctx.bots[0];
|
|
102
108
|
if (bot) {
|
|
109
|
+
ctx.logger.info(`使用 bot ${bot.platform}:${bot.selfId} 发送消息`);
|
|
110
|
+
ctx.logger.info(`消息内容: ${message.substring(0, 50)}...`);
|
|
103
111
|
await bot.sendMessage(target, message);
|
|
104
112
|
ctx.logger.info(`已推送文章到 ${target}: ${post.title.rendered}`);
|
|
105
113
|
}
|
|
106
114
|
else {
|
|
107
|
-
ctx.logger.error(`没有可用的 bot
|
|
115
|
+
ctx.logger.error(`没有可用的 bot 实例,当前 bots 列表: ${JSON.stringify(ctx.bots)}`);
|
|
108
116
|
}
|
|
109
117
|
}
|
|
110
118
|
catch (error) {
|
|
111
119
|
ctx.logger.error(`推送文章到 ${target} 失败: ${error}`);
|
|
120
|
+
ctx.logger.error(`错误详情: ${JSON.stringify(error)}`);
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
await markPostAsPushed(post.id);
|
|
@@ -155,7 +164,8 @@ function apply(ctx, config) {
|
|
|
155
164
|
}
|
|
156
165
|
let message = '👥 WordPress 站点用户列表:\n\n';
|
|
157
166
|
for (const user of users) {
|
|
158
|
-
|
|
167
|
+
const roles = user.roles || [];
|
|
168
|
+
message += `${user.id}. ${user.name}(${roles.join(', ') || '普通用户'})\n`;
|
|
159
169
|
message += `🔗 ${user.link}\n\n`;
|
|
160
170
|
}
|
|
161
171
|
return message;
|
|
@@ -212,15 +222,10 @@ function apply(ctx, config) {
|
|
|
212
222
|
config.mentionAll = !config.mentionAll;
|
|
213
223
|
return `@全体成员 已${config.mentionAll ? '开启' : '关闭'}`;
|
|
214
224
|
});
|
|
215
|
-
ctx.command('wordpress.set-url <url>', '修改 WordPress
|
|
225
|
+
ctx.command('wordpress.set-url <url>', '修改 WordPress 站点地址')
|
|
216
226
|
.action(async ({ session }, url) => {
|
|
217
227
|
const userId = session?.userId || 'unknown';
|
|
218
228
|
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
229
|
// 修改站点地址
|
|
225
230
|
config.wordpressUrl = url;
|
|
226
231
|
ctx.logger.info(`站点地址已修改为:${url}`);
|
|
@@ -248,12 +253,6 @@ function apply(ctx, config) {
|
|
|
248
253
|
ctx.command('wordpress.clean [days]', '清理指定天数前的推送记录(默认 30 天)')
|
|
249
254
|
.action(async ({ session }, days) => {
|
|
250
255
|
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
256
|
// 设置默认天数
|
|
258
257
|
const daysToKeep = days ? parseInt(days) : 30;
|
|
259
258
|
if (isNaN(daysToKeep) || daysToKeep <= 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-wordpress-notifier",
|
|
3
|
-
"version": "1.8.
|
|
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"
|