koishi-plugin-wordpress-notifier 1.6.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 +72 -9
- 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;
|
|
@@ -117,6 +142,42 @@ function apply(ctx, config) {
|
|
|
117
142
|
}
|
|
118
143
|
return message;
|
|
119
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
|
+
});
|
|
120
181
|
ctx.command('wordpress.push', '手动推送最新文章')
|
|
121
182
|
.action(async () => {
|
|
122
183
|
ctx.logger.info('命令 wordpress.push 被调用');
|
|
@@ -149,15 +210,17 @@ function apply(ctx, config) {
|
|
|
149
210
|
ctx.command('wordpress', 'WordPress 推送插件菜单')
|
|
150
211
|
.action(() => {
|
|
151
212
|
ctx.logger.info('命令 wordpress 被调用');
|
|
152
|
-
return `📚 WordPress 推送插件菜单:
|
|
153
|
-
|
|
154
|
-
🔹 /wordpress.status - 查看插件状态
|
|
155
|
-
🔹 /wordpress.latest - 查看最新文章
|
|
156
|
-
🔹 /wordpress.list - 查看文章列表
|
|
157
|
-
🔹 /wordpress.
|
|
158
|
-
🔹 /wordpress.
|
|
159
|
-
🔹 /wordpress.
|
|
160
|
-
|
|
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
|
+
|
|
161
224
|
💡 提示:所有命令都需要加 / 前缀`;
|
|
162
225
|
});
|
|
163
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"
|