koishi-plugin-share-links-analysis 0.7.0 → 0.7.2
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 +4 -5
- package/lib/core.js +3 -1
- package/lib/index.js +13 -3
- package/lib/parsers/twitter.js +2 -1
- package/lib/parsers/xiaoheihe.js +9 -4
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
特别鸣谢以下项目的支持:
|
|
12
12
|
|
|
13
|
-
- [
|
|
14
|
-
- [koishi-plugin-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
~~<br>本项目基于原项目0.6.3版本修改~~ 已重构大部分代码
|
|
13
|
+
- [koishi-plugin-bilibili-videolink-analysis](https://github.com/shangxueink/koishi-shangxue-apps/tree/main/plugins/bilibili-videolink-analysis)
|
|
14
|
+
- [koishi-plugin-xiaohongshu](https://www.npmjs.com/package/koishi-plugin-xiaohongshu)
|
|
15
|
+
以及解析方式原作者:[@MuJie](https://mu-jie.cc/)
|
|
16
|
+
- [BetterTwitFix](https://github.com/dylanpdx/BetterTwitFix)
|
package/lib/core.js
CHANGED
|
@@ -68,7 +68,9 @@ function resolveLinks(content) {
|
|
|
68
68
|
*/
|
|
69
69
|
async function processLink(ctx, config, link, session) {
|
|
70
70
|
for (const parser of parsers) {
|
|
71
|
-
if (parser.
|
|
71
|
+
if (parser.name == link.platform) {
|
|
72
|
+
if (config.logLevel == "full")
|
|
73
|
+
ctx.logger('share-links-analysis').info(`解析平台:${parser.name},链接:${link.url}`);
|
|
72
74
|
return await parser.process(ctx, config, link, session);
|
|
73
75
|
}
|
|
74
76
|
}
|
package/lib/index.js
CHANGED
|
@@ -52,7 +52,7 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
52
52
|
koishi_1.Schema.object({
|
|
53
53
|
parseLimit: koishi_1.Schema.number().default(3).description("单对话多链接解析上限"),
|
|
54
54
|
useNumeral: koishi_1.Schema.boolean().default(true).description("使用格式化数字 (如 10000 -> 1万)"),
|
|
55
|
-
showError: koishi_1.Schema.boolean().default(false).description("
|
|
55
|
+
showError: koishi_1.Schema.boolean().default(false).description("当链接被阻止时提醒发送者"),
|
|
56
56
|
}).description("高级解析设置"),
|
|
57
57
|
koishi_1.Schema.object({
|
|
58
58
|
proxy: koishi_1.Schema.string().description("代理设置"),
|
|
@@ -167,12 +167,22 @@ function apply(ctx, config) {
|
|
|
167
167
|
for (const link of links) {
|
|
168
168
|
if (session.guildId) {
|
|
169
169
|
const settings = await (0, utils_1.getEffectiveSettings)(ctx, session.guildId, config);
|
|
170
|
-
if (!settings.parsers[link.platform])
|
|
170
|
+
if (!settings.parsers[link.platform]) {
|
|
171
|
+
if (config.logLevel == "full")
|
|
172
|
+
ctx.logger('share-links-analysis').info(`根据策略,该链接已被阻止解析:平台:${link.platform},链接:${link.url}`);
|
|
173
|
+
if (config.showError)
|
|
174
|
+
await session.send(`根据策略,该链接已被阻止解析:平台:${link.platform}`);
|
|
171
175
|
continue;
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
178
|
else {
|
|
174
|
-
if (!config.default_parsers[link.platform])
|
|
179
|
+
if (!config.default_parsers[link.platform]) {
|
|
180
|
+
if (config.logLevel == "full")
|
|
181
|
+
ctx.logger('share-links-analysis').info(`根据策略,该链接已被阻止解析:平台:${link.platform},链接:${link.url}`);
|
|
182
|
+
if (config.showError)
|
|
183
|
+
await session.send(`根据策略,该链接已被阻止解析:平台:${link.platform}`);
|
|
175
184
|
continue;
|
|
185
|
+
}
|
|
176
186
|
}
|
|
177
187
|
if (linkCount >= config.parseLimit) {
|
|
178
188
|
await session.send("已达到单次解析上限…");
|
package/lib/parsers/twitter.js
CHANGED
|
@@ -83,7 +83,8 @@ async function process(ctx, config, link, session) {
|
|
|
83
83
|
}
|
|
84
84
|
const enable_nsfw = await (0, utils_1.getEffectiveSettings)(ctx, session.guildId, config);
|
|
85
85
|
if (tweetData.possibly_sensitive && !enable_nsfw) {
|
|
86
|
-
|
|
86
|
+
if (config.showError)
|
|
87
|
+
await session.send(`潜在的不合规内容,根据策略已停止发送`);
|
|
87
88
|
return null;
|
|
88
89
|
}
|
|
89
90
|
// 解析媒体
|
package/lib/parsers/xiaoheihe.js
CHANGED
|
@@ -9,7 +9,7 @@ const utils_1 = require("../utils");
|
|
|
9
9
|
exports.name = "xiaoheihe";
|
|
10
10
|
const linkRules = [
|
|
11
11
|
{
|
|
12
|
-
pattern: /https?:\/\/api.xiaoheihe\.cn\/v3\/bbs\/app\/api\/web\/share\?
|
|
12
|
+
pattern: /https?:\/\/api.xiaoheihe\.cn\/v3\/bbs\/app\/api\/web\/share\?[\w=&]+/gi,
|
|
13
13
|
type: "bbs_api",
|
|
14
14
|
},
|
|
15
15
|
{
|
|
@@ -23,7 +23,11 @@ function match(content) {
|
|
|
23
23
|
const match = content.match(rule.pattern);
|
|
24
24
|
if (match) {
|
|
25
25
|
for (const fullUrl of match) {
|
|
26
|
-
|
|
26
|
+
let id;
|
|
27
|
+
if (rule.type == "bbs")
|
|
28
|
+
id = fullUrl.match(/\w+$/)?.[0];
|
|
29
|
+
else if (rule.type == "bbs_api")
|
|
30
|
+
id = fullUrl.match(/link_id=\w+/gi)?.[0].slice(8);
|
|
27
31
|
if (id) {
|
|
28
32
|
results.push({
|
|
29
33
|
platform: exports.name,
|
|
@@ -80,8 +84,8 @@ async function process(ctx, config, link, session) {
|
|
|
80
84
|
page.waitForFunction(() => {
|
|
81
85
|
return document.querySelector('.hb-bbs-image-text') ||
|
|
82
86
|
document.querySelector('.hb-bbs-post');
|
|
83
|
-
}, { timeout:
|
|
84
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error('核心内容容器未找到')),
|
|
87
|
+
}, { timeout: 30000 }),
|
|
88
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('核心内容容器未找到')), 30000))
|
|
85
89
|
]);
|
|
86
90
|
// 全面解析页面内容
|
|
87
91
|
const postData = await page.evaluate(() => {
|
|
@@ -215,6 +219,7 @@ async function process(ctx, config, link, session) {
|
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
return {
|
|
222
|
+
// @ts-ignore
|
|
218
223
|
isImageTextType,
|
|
219
224
|
isPostType,
|
|
220
225
|
title,
|
package/lib/utils.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { Context, Logger, Session } from "koishi";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function numeral(num: number, config: PluginConfig): string;
|
|
10
10
|
export declare function escapeHtml(str: string): string;
|
|
11
|
+
export declare function unescapeHtml(str: string): string;
|
|
11
12
|
export declare function getFileSize(url: string, proxy: string | undefined, userAgent: string | undefined, logger: Logger): Promise<number | null>;
|
|
12
13
|
export declare function getEffectiveSettings(ctx: Context, guildId: string | undefined, config: PluginConfig): Promise<{
|
|
13
14
|
parsers: any;
|
package/lib/utils.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.numeral = numeral;
|
|
40
40
|
exports.escapeHtml = escapeHtml;
|
|
41
|
+
exports.unescapeHtml = unescapeHtml;
|
|
41
42
|
exports.getFileSize = getFileSize;
|
|
42
43
|
exports.getEffectiveSettings = getEffectiveSettings;
|
|
43
44
|
exports.isUserAdmin = isUserAdmin;
|
|
@@ -78,6 +79,15 @@ function escapeHtml(str) {
|
|
|
78
79
|
.replace(/"/g, '"')
|
|
79
80
|
.replace(/'/g, ''');
|
|
80
81
|
}
|
|
82
|
+
function unescapeHtml(str) {
|
|
83
|
+
if (!str)
|
|
84
|
+
return '';
|
|
85
|
+
return str.replace(/"/g, '"')
|
|
86
|
+
.replace(/'/g, "'")
|
|
87
|
+
.replace(/</g, '<')
|
|
88
|
+
.replace(/>/g, '>')
|
|
89
|
+
.replace(/&/g, '&');
|
|
90
|
+
}
|
|
81
91
|
function getProxyAgent(proxy, url) {
|
|
82
92
|
if (!proxy)
|
|
83
93
|
return undefined;
|
|
@@ -453,7 +463,7 @@ async function sendResult_forward(session, config, result, logger, mixed_sending
|
|
|
453
463
|
const localDownloadDir = config.localDownloadDir;
|
|
454
464
|
const onebotReadDir = config.onebotReadDir;
|
|
455
465
|
let mediaCoverUrl = result.coverUrl;
|
|
456
|
-
let mediaMainbody = result.mainbody;
|
|
466
|
+
let mediaMainbody = unescapeHtml(result.mainbody ?? '');
|
|
457
467
|
let proxy = undefined;
|
|
458
468
|
if (config.proxy_settings[result.platform]) {
|
|
459
469
|
proxy = config.proxy;
|