koishi-plugin-share-links-analysis 0.2.4 → 0.3.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.js +10 -20
- package/lib/parsers/bilibili.js +2 -2
- package/lib/parsers/xiaohongshu.js +23 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function apply(ctx, config) {
|
|
|
81
81
|
ctx.middleware(async (session, next) => {
|
|
82
82
|
if (!session.content || !session.channelId)
|
|
83
83
|
return next();
|
|
84
|
-
const content = session.content.replace(/\\/g, '');
|
|
84
|
+
const content = session.content.replace(/\\/g, '').replace(/&/g, '&');
|
|
85
85
|
const channelId = session.channelId;
|
|
86
86
|
const links = (0, core_1.resolveLinks)(content);
|
|
87
87
|
if (links.length === 0)
|
|
@@ -131,8 +131,7 @@ async function sendResult(session, config, result, logger) {
|
|
|
131
131
|
return; // 成功,结束
|
|
132
132
|
}
|
|
133
133
|
catch (err) {
|
|
134
|
-
logger.warn('
|
|
135
|
-
await sendResult_plain(session, config, result, logger);
|
|
134
|
+
logger.warn('合并转发失败:', err);
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
137
|
}
|
|
@@ -298,21 +297,12 @@ async function sendResult_forward(session, config, result, logger) {
|
|
|
298
297
|
// Step 6: 发送合并转发
|
|
299
298
|
if (!(session.onebot && session.onebot._request))
|
|
300
299
|
throw new Error("Onebot is not defined");
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
catch (e) {
|
|
312
|
-
if (e.name === 'TimeoutError') {
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
throw e;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
300
|
+
await session.onebot._request('send_group_forward_msg', {
|
|
301
|
+
group_id: session.guildId,
|
|
302
|
+
messages: forwardNodes,
|
|
303
|
+
news: [{ text: result.description || '-' }, { text: '点击查看详情 | Powered by furryaxw' }],
|
|
304
|
+
prompt: result.title || '',
|
|
305
|
+
summary: '分享解析',
|
|
306
|
+
source: result.title || ''
|
|
307
|
+
});
|
|
318
308
|
}
|
package/lib/parsers/bilibili.js
CHANGED
|
@@ -13,8 +13,8 @@ function match(content) {
|
|
|
13
13
|
const results = [];
|
|
14
14
|
// 匹配标准长链接和短链接
|
|
15
15
|
const linkRegex = [
|
|
16
|
-
{ pattern: /(https?:\/\/)?(www\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+))/
|
|
17
|
-
{ pattern: /(https?:\/\/)?(b23\.tv\/[0-9a-zA-Z]+)/
|
|
16
|
+
{ pattern: /(https?:\/\/)?(www\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+))/g, type: "video" },
|
|
17
|
+
{ pattern: /(https?:\/\/)?(b23\.tv\/[0-9a-zA-Z]+)/g, type: "short" },
|
|
18
18
|
];
|
|
19
19
|
for (const rule of linkRegex) {
|
|
20
20
|
const matches = [...content.matchAll(new RegExp(rule.pattern, 'gi'))];
|
|
@@ -12,16 +12,29 @@ const utils_1 = require("../utils");
|
|
|
12
12
|
* @returns 匹配到的链接对象数组
|
|
13
13
|
*/
|
|
14
14
|
function match(content) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const results = [];
|
|
16
|
+
// 匹配标准长链接和短链接
|
|
17
|
+
const linkRegex = [
|
|
18
|
+
{ pattern: /(https?:\/\/)?(www\.xiaohongshu\.com\/discovery\/item\/([\w?=\-&\.%]+))/g, type: "discovery" },
|
|
19
|
+
{ pattern: /(https?:\/\/)?(www\.xiaohongshu\.com\/explore\/([\w?=\-&\.%]+))/g, type: "explore" },
|
|
20
|
+
{ pattern: /(https?:\/\/)?(xhslink\.com\/(m\/)?[0-9a-zA-Z]+)/g, type: "short" },
|
|
21
|
+
];
|
|
22
|
+
for (const rule of linkRegex) {
|
|
23
|
+
const matches = [...content.matchAll(new RegExp(rule.pattern, 'gi'))];
|
|
24
|
+
for (const matchArr of matches) {
|
|
25
|
+
if (matchArr[2]) {
|
|
26
|
+
// 强制将所有链接格式化为 https 开头
|
|
27
|
+
const formattedUrl = `https://${matchArr[2]}`;
|
|
28
|
+
results.push({
|
|
29
|
+
platform: 'xiaohongshu',
|
|
30
|
+
type: rule.type,
|
|
31
|
+
id: formattedUrl.split('/').pop().split('?')[0],
|
|
32
|
+
url: formattedUrl
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
25
38
|
}
|
|
26
39
|
/**
|
|
27
40
|
* 使用 Puppeteer 刷新小红书 Cookie 并存入数据库
|