koishi-plugin-share-links-analysis 0.7.0 → 0.7.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/README.md CHANGED
@@ -10,8 +10,7 @@
10
10
 
11
11
  特别鸣谢以下项目的支持:
12
12
 
13
- - [@summonhim/koishi-plugin-bili-parser](https://www.npmjs.com/package/@summonhim/koishi-plugin-bili-parser)
14
- - [koishi-plugin-iirose-media-request](https://www.npmjs.com/package/koishi-plugin-iirose-media-request)
15
-
16
- 原项目:[koishi-plugin-bilibili-videolink-analysis](https://github.com/shangxueink/koishi-shangxue-apps/tree/main/plugins/bilibili-videolink-analysis)
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.match(link.url).length > 0) {
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("已达到单次解析上限…");
@@ -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
- await session.send('潜在的不合规内容,已停止发送');
86
+ if (config.showError)
87
+ await session.send(`潜在的不合规内容,根据策略已停止发送`);
87
88
  return null;
88
89
  }
89
90
  // 解析媒体
@@ -80,8 +80,8 @@ async function process(ctx, config, link, session) {
80
80
  page.waitForFunction(() => {
81
81
  return document.querySelector('.hb-bbs-image-text') ||
82
82
  document.querySelector('.hb-bbs-post');
83
- }, { timeout: 10000 }),
84
- new Promise((_, reject) => setTimeout(() => reject(new Error('核心内容容器未找到')), 10000))
83
+ }, { timeout: 30000 }),
84
+ new Promise((_, reject) => setTimeout(() => reject(new Error('核心内容容器未找到')), 30000))
85
85
  ]);
86
86
  // 全面解析页面内容
87
87
  const postData = await page.evaluate(() => {
@@ -215,6 +215,7 @@ async function process(ctx, config, link, session) {
215
215
  }
216
216
  }
217
217
  return {
218
+ // @ts-ignore
218
219
  isImageTextType,
219
220
  isPostType,
220
221
  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, '&quot;')
79
80
  .replace(/'/g, '&#39;');
80
81
  }
82
+ function unescapeHtml(str) {
83
+ if (!str)
84
+ return '';
85
+ return str.replace(/&quot;/g, '"')
86
+ .replace(/&#39;/g, "'")
87
+ .replace(/&lt;/g, '<')
88
+ .replace(/&gt;/g, '>')
89
+ .replace(/&amp;/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;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "koishi-plugin-share-links-analysis",
3
3
  "description": "自用插件",
4
4
  "license": "MIT",
5
- "version": "0.7.0",
5
+ "version": "0.7.1",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [