koishi-plugin-bilibili-videolink-analysis 1.1.8 → 1.1.10

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.
Files changed (3) hide show
  1. package/lib/index.js +30 -23
  2. package/package.json +2 -2
  3. package/readme.md +5 -0
package/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.apply = exports.usage = exports.Config = exports.name = exports.inject = void 0;
4
- const koishi_1 = require("koishi");
5
4
  const { Schema, Logger, h } = require("koishi");
6
5
  const logger = new Logger('bilibili-videolink-analysis');
7
6
  exports.name = 'bilibili-videolink-analysis';
@@ -73,10 +72,6 @@ exports.Config = Schema.intersect([
73
72
  Schema.const('4').description('返回视频和视频直链'),
74
73
  Schema.const('5').description('返回视频,仅在日志记录视频直链'),
75
74
  ]).role('radio').default('2').description("是否返回` 视频/视频直链 `"),
76
- //Video_ClarityPriority: Schema.union([
77
- // Schema.const('1').description('低清晰度优先(低清晰度的视频发得快一点)'),
78
- // Schema.const('2').description('高清晰度优先(清晰的还是去B站看吧)'),
79
- //]).role('radio').default('1').description("发送的视频清晰度优先策略"),
80
75
  BVnumberParsing: Schema.boolean().default(true).description("是否允许根据`独立的BV号`解析视频 `开启后,可以通过视频的BV号解析视频。` <br> [触发说明见README](https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis)"),
81
76
  Maximumduration: Schema.number().default(25).description("允许解析的视频最大时长(分钟)`超过这个时长 就不会发视频`").min(1),
82
77
  Maximumduration_tip: Schema.union([
@@ -94,14 +89,11 @@ exports.Config = Schema.intersect([
94
89
  Schema.const("bv").description("BV 号"),
95
90
  Schema.const("av").description("AV 号"),
96
91
  ]).default("bv").description("ID 偏好").hidden(),
97
- //bVideoImage: Schema.boolean().default(true).description("显示封面"),
98
- //bVideoOwner: Schema.boolean().default(true).description("显示 UP "),
99
- //bVideoDesc: Schema.boolean().default(false).description("显示简介`有的简介真的很长`"),
100
- //bVideoStat: Schema.boolean().default(true).description("显示状态(*三连数据*)"),
101
- //bVideoExtraStat: Schema.boolean().default(true).description("显示额外状态(*弹幕&观看*)"),
102
- bVideo_area: Schema.string().role('textarea', { rows: [8, 16] }).description("图文解析的返回格式<br>注意变量格式,以及变量名称<br>比如 `${标题}` 不可以变成`${标题123}`,你可以直接删掉但是不能修改变量名称哦<br>当然变量也不能无中生有,下面的默认值内容 就是所有变量了,你仅可以删去变量 或者修改变量之外的格式。")
92
+
93
+ bVideo_area: Schema.string().role('textarea', { rows: [8, 16] }).description("图文解析的返回格式<br>注意变量格式,以及变量名称。<br>比如 `${标题}` 不可以变成`${标题123}`,你可以直接删掉但是不能修改变量名称哦<br>当然变量也不能无中生有,下面的默认值内容 就是所有变量了,你仅可以删去变量 或者修改变量之外的格式。<br>· 特殊变量`${~~~}`表示分割线,会把上下内容分为两个信息单独发送。")
103
94
  .default("${标题} --- ${UP主}\n---\n${封面}\n---\n${简介}\n---\n${点赞} --- ${投币}\n${收藏} --- ${转发}\n${观看} --- ${弹幕}"),
104
95
  bVideoShowLink: Schema.boolean().default(false).description("在末尾显示视频的链接地址 `开启可能会导致其他bot循环解析`"),
96
+ bVideoShowIntroductionTofixed: Schema.number().default(50).description("视频的`简介`最大的字符长度<br>超出部分会使用 `...` 代替"),
105
97
  }).description("链接的图文解析设置"),
106
98
 
107
99
  Schema.object({
@@ -114,7 +106,6 @@ exports.Config = Schema.intersect([
114
106
  function apply(ctx, config) {
115
107
 
116
108
  ctx.middleware(async (session, next) => {
117
-
118
109
  let sessioncontent = session.content;
119
110
  // 如果允许解析 BV 号,则进行解析
120
111
  if (config.BVnumberParsing) {
@@ -132,6 +123,7 @@ function apply(ctx, config) {
132
123
  }
133
124
  return next();
134
125
  }, config.middleware);
126
+
135
127
  if (config.demand) {
136
128
  ctx.command('B站点播/退出登录', '退出B站账号')
137
129
  .action(async ({ session }) => {
@@ -349,7 +341,7 @@ display: none !important;
349
341
  }
350
342
 
351
343
  if (config.enable) { // 开启自动解析了
352
-
344
+
353
345
  const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger); // 提取链接
354
346
  if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
355
347
  await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options); // 解析视频并返回
@@ -357,6 +349,7 @@ display: none !important;
357
349
  }
358
350
  })
359
351
  }
352
+
360
353
  if (config.loggerinfo) {
361
354
  ctx.command('B站点播/调试点播 [keyword]', '调试时点播B站视频')
362
355
  .option('video', '-v 解析返回视频')
@@ -456,7 +449,7 @@ display: none !important;
456
449
 
457
450
  if (config.enable) {
458
451
  // 开启自动解析了
459
-
452
+
460
453
  const ret = await extractLinks(session, config, ctx, [{ type: 'Video', id: chosenVideo.id }], logger);
461
454
  if (ret && !isLinkProcessedRecently(ret, lastProcessedUrls, config, logger)) {
462
455
  await processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options);
@@ -471,7 +464,6 @@ display: none !important;
471
464
  if (links.length === 0) {
472
465
  return false; // 如果没有找到链接,返回 false
473
466
  }
474
-
475
467
  return links; // 返回解析出的链接
476
468
  }
477
469
 
@@ -524,22 +516,32 @@ display: none !important;
524
516
  async function processVideoFromLink(session, config, ctx, lastProcessedUrls, logger, ret, options = { video: true }) {
525
517
  const lastretUrl = extractLastUrl(ret);
526
518
 
527
- let mediaData = '';
528
-
529
519
  if (config.waitTip_Switch) {
530
520
  // 等候的提示文字
531
521
  await session.send(config.waitTip_Switch);
532
522
  }
533
523
 
524
+ let textParts = []; // 用于存储分割后的文本部分
534
525
  if (config.linktextParsing) {
526
+ let fullText;
535
527
  if (config.bVideoShowLink) {
536
- await session.send(ret); // 发送完整信息
528
+ fullText = ret; // 发送完整信息
537
529
  } else {
538
530
  // 去掉最后一个链接
539
- const retWithoutLastLink = ret.replace(lastretUrl, '');
540
- await session.send(retWithoutLastLink);
531
+ fullText = ret.replace(lastretUrl, '');
532
+ }
533
+
534
+ // 分割文本
535
+ textParts = fullText.split('${~~~}');
536
+ }
537
+ // 发送分割后的文本部分
538
+ for (const part of textParts) {
539
+ const trimmedPart = part.trim(); // 去除首尾空格
540
+ if (trimmedPart) { // 确保不是空字符串
541
+ await session.send(trimmedPart);
541
542
  }
542
543
  }
544
+
543
545
  if (config.VideoParsing_ToLink) {
544
546
  const fullAPIurl = `https://api.xingzhige.com/API/b_parse/?url=${encodeURIComponent(lastretUrl)}`;
545
547
 
@@ -613,15 +615,14 @@ display: none !important;
613
615
  }
614
616
  }
615
617
 
616
-
617
618
  if (config.loggerinfo) {
618
- //logger.info(`视频信息内容:\n ${JSON.stringify(mediaData)}`);
619
619
  logger.info(`机器人发送完整消息为:\n ${ret}`);
620
620
  }
621
621
  return;
622
622
  }
623
623
 
624
624
 
625
+
625
626
  // 提取最后一个URL
626
627
  function extractLastUrl(text) {
627
628
  const urlPattern = /https?:\/\/[^\s]+/g;
@@ -738,12 +739,18 @@ display: none !important;
738
739
  if (!info || !info["data"])
739
740
  return null;
740
741
 
742
+ let description = info["data"]["desc"];
743
+ // 根据配置处理简介
744
+ const maxLength = config.bVideoShowIntroductionTofixed;
745
+ if (description.length > maxLength) {
746
+ description = description.substring(0, maxLength) + '...';
747
+ }
741
748
  // 定义占位符对应的数据
742
749
  const placeholders = {
743
750
  '${标题}': info["data"]["title"],
744
751
  '${UP主}': info["data"]["owner"]["name"],
745
752
  '${封面}': `<img src="${info["data"]["pic"]}"/>`,
746
- '${简介}': info["data"]["desc"],
753
+ '${简介}': description, // 使用处理后的简介
747
754
  '${点赞}': `点赞:${(0, numeral)(info["data"]["stat"]["like"], this.config)}`,
748
755
  '${投币}': `投币:${(0, numeral)(info["data"]["stat"]["coin"], this.config)}`,
749
756
  '${收藏}': `收藏:${(0, numeral)(info["data"]["stat"]["favorite"], this.config)}`,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "koishi-plugin-bilibili-videolink-analysis",
3
3
  "description": "[<ruby>Bilibili视频解析<rp>(</rp><rt>点我查看食用方法</rt><rp>)</rp></ruby>](https://www.npmjs.com/package/koishi-plugin-bilibili-videolink-analysis)解析B站链接(支持小程序卡片)支持搜索点播功能!灵感来自完美的 [bili-parser](/market?keyword=bili-parser) !",
4
4
  "license": "MIT",
5
- "version": "1.1.8",
5
+ "version": "1.1.10",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [
@@ -24,4 +24,4 @@
24
24
  "peerDependencies": {
25
25
  "koishi": "^4.16.8"
26
26
  }
27
- }
27
+ }
package/readme.md CHANGED
@@ -178,6 +178,11 @@ https://www.bilibili.com/video/BV1ii421Q7oj
178
178
  <details>
179
179
  <summary>点击此处 可查看更新日志</summary>
180
180
 
181
+ - **1.1.10**
182
+ - 又想写了(指readme)
183
+ - 新增解析格式的的变量分割线
184
+ - 期间还写了什么,忘了
185
+
181
186
  - **1.0.0**
182
187
  - 不想写了
183
188