koishi-plugin-wordpress-notifier 1.5.0 → 1.7.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/lib/index.d.ts +13 -0
- package/lib/index.js +80 -11
- package/package.json +2 -5
package/lib/index.d.ts
CHANGED
|
@@ -28,6 +28,19 @@ export interface WordPressPost {
|
|
|
28
28
|
categories: number[];
|
|
29
29
|
tags: number[];
|
|
30
30
|
}
|
|
31
|
+
export interface WordPressUser {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
link: string;
|
|
36
|
+
avatar_urls: {
|
|
37
|
+
'24': string;
|
|
38
|
+
'48': string;
|
|
39
|
+
'96': string;
|
|
40
|
+
};
|
|
41
|
+
registered_date: string;
|
|
42
|
+
roles: string[];
|
|
43
|
+
}
|
|
31
44
|
export interface WordPressPostRecord {
|
|
32
45
|
id: number;
|
|
33
46
|
postId: number;
|
package/lib/index.js
CHANGED
|
@@ -33,6 +33,31 @@ function apply(ctx, config) {
|
|
|
33
33
|
return [];
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
async function fetchUsers() {
|
|
37
|
+
try {
|
|
38
|
+
const url = `${config.wordpressUrl}/wp-json/wp/v2/users`;
|
|
39
|
+
ctx.logger.info(`正在获取用户信息: ${url}`);
|
|
40
|
+
const response = await ctx.http.get(url);
|
|
41
|
+
ctx.logger.info(`成功获取 ${response.length} 个用户`);
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
ctx.logger.error(`获取 WordPress 用户信息失败: ${error}`);
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function fetchUserById(userId) {
|
|
50
|
+
try {
|
|
51
|
+
const url = `${config.wordpressUrl}/wp-json/wp/v2/users/${userId}`;
|
|
52
|
+
ctx.logger.info(`正在获取用户信息: ${url}`);
|
|
53
|
+
const response = await ctx.http.get(url);
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
ctx.logger.error(`获取 WordPress 用户信息失败: ${error}`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
36
61
|
async function isPostPushed(postId) {
|
|
37
62
|
const record = await ctx.database.get('wordpress_posts', { postId });
|
|
38
63
|
return record.length > 0;
|
|
@@ -69,8 +94,14 @@ function apply(ctx, config) {
|
|
|
69
94
|
const message = formatPostMessage(post, true);
|
|
70
95
|
for (const target of config.targets) {
|
|
71
96
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
const bot = ctx.bots[0];
|
|
98
|
+
if (bot) {
|
|
99
|
+
await bot.sendMessage(target, message);
|
|
100
|
+
ctx.logger.info(`已推送文章到 ${target}: ${post.title.rendered}`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
ctx.logger.error(`没有可用的 bot 实例`);
|
|
104
|
+
}
|
|
74
105
|
}
|
|
75
106
|
catch (error) {
|
|
76
107
|
ctx.logger.error(`推送文章到 ${target} 失败: ${error}`);
|
|
@@ -111,6 +142,42 @@ function apply(ctx, config) {
|
|
|
111
142
|
}
|
|
112
143
|
return message;
|
|
113
144
|
});
|
|
145
|
+
ctx.command('wordpress.users', '查看站点用户列表')
|
|
146
|
+
.action(async () => {
|
|
147
|
+
ctx.logger.info('命令 wordpress.users 被调用');
|
|
148
|
+
const users = await fetchUsers();
|
|
149
|
+
if (users.length === 0) {
|
|
150
|
+
return '暂无用户信息';
|
|
151
|
+
}
|
|
152
|
+
let message = '👥 WordPress 站点用户列表:\n\n';
|
|
153
|
+
for (const user of users) {
|
|
154
|
+
message += `${user.id}. ${user.name}(${user.roles.join(', ')})\n`;
|
|
155
|
+
message += `🔗 ${user.link}\n\n`;
|
|
156
|
+
}
|
|
157
|
+
return message;
|
|
158
|
+
});
|
|
159
|
+
ctx.command('wordpress.user <id>', '查看特定用户信息')
|
|
160
|
+
.action(async ({}, userId) => {
|
|
161
|
+
ctx.logger.info(`命令 wordpress.user 被调用,用户 ID:${userId}`);
|
|
162
|
+
const id = parseInt(userId);
|
|
163
|
+
if (isNaN(id)) {
|
|
164
|
+
return '请输入有效的用户 ID';
|
|
165
|
+
}
|
|
166
|
+
const user = await fetchUserById(id);
|
|
167
|
+
if (!user) {
|
|
168
|
+
return `未找到 ID 为 ${id} 的用户`;
|
|
169
|
+
}
|
|
170
|
+
let message = `👤 用户信息:\n\n`;
|
|
171
|
+
message += `ID: ${user.id}\n`;
|
|
172
|
+
message += `昵称: ${user.name}\n`;
|
|
173
|
+
message += `角色: ${user.roles.join(', ')}\n`;
|
|
174
|
+
message += `个人主页: ${user.link}\n`;
|
|
175
|
+
if (user.description) {
|
|
176
|
+
message += `简介: ${user.description.replace(/<[^>]*>/g, '')}\n`;
|
|
177
|
+
}
|
|
178
|
+
message += `注册时间: ${new Date(user.registered_date).toLocaleString('zh-CN')}\n`;
|
|
179
|
+
return message;
|
|
180
|
+
});
|
|
114
181
|
ctx.command('wordpress.push', '手动推送最新文章')
|
|
115
182
|
.action(async () => {
|
|
116
183
|
ctx.logger.info('命令 wordpress.push 被调用');
|
|
@@ -143,15 +210,17 @@ function apply(ctx, config) {
|
|
|
143
210
|
ctx.command('wordpress', 'WordPress 推送插件菜单')
|
|
144
211
|
.action(() => {
|
|
145
212
|
ctx.logger.info('命令 wordpress 被调用');
|
|
146
|
-
return `📚 WordPress 推送插件菜单:
|
|
147
|
-
|
|
148
|
-
🔹 /wordpress.status - 查看插件状态
|
|
149
|
-
🔹 /wordpress.latest - 查看最新文章
|
|
150
|
-
🔹 /wordpress.list - 查看文章列表
|
|
151
|
-
🔹 /wordpress.
|
|
152
|
-
🔹 /wordpress.
|
|
153
|
-
🔹 /wordpress.
|
|
154
|
-
|
|
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.toggle - 切换自动推送开关
|
|
222
|
+
🔹 /wordpress.mention - 切换 @全体成员 开关
|
|
223
|
+
|
|
155
224
|
💡 提示:所有命令都需要加 / 前缀`;
|
|
156
225
|
});
|
|
157
226
|
ctx.on('ready', async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-wordpress-notifier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "WordPress 文章自动推送到 QQ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,10 +32,7 @@
|
|
|
32
32
|
"notifier",
|
|
33
33
|
"qq"
|
|
34
34
|
],
|
|
35
|
-
"repository":
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "https://github.com/Lexo0522/koishi-plugin-wordpress-notifier.git"
|
|
38
|
-
},
|
|
35
|
+
"repository": "git+https://github.com/Lexo0522/koishi-plugin-wordpress-notifier.git",
|
|
39
36
|
"homepage": "https://github.com/Lexo0522/koishi-plugin-wordpress-notifier#readme",
|
|
40
37
|
"bugs": {
|
|
41
38
|
"url": "https://github.com/Lexo0522/koishi-plugin-wordpress-notifier/issues"
|