koishi-plugin-bilibili-notify 3.2.2 → 3.2.4-alpha.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/blive.js CHANGED
@@ -32,13 +32,14 @@ class BLive extends koishi_1.Service {
32
32
  uid: mySelfInfo.data.mid,
33
33
  },
34
34
  });
35
+ this.logger.info(`[${roomId}]直播间连接已建立!`);
35
36
  }
36
37
  closeListener(roomId) {
37
38
  // 判断直播间监听器是否关闭
38
39
  if (!this.listenerRecord ||
39
40
  !this.listenerRecord[roomId]?.closed) {
40
41
  // 输出logger
41
- this.logger.info(`${roomId}直播间弹幕监听器无需关闭`);
42
+ this.logger.info(`${roomId}直播间连接无需关闭`);
42
43
  }
43
44
  // 关闭直播间监听器
44
45
  this.listenerRecord[roomId].close();
@@ -47,12 +48,12 @@ class BLive extends koishi_1.Service {
47
48
  // 删除直播间监听器
48
49
  delete this.listenerRecord[roomId];
49
50
  // 输出logger
50
- this.logger.info(`${roomId}直播间弹幕监听已关闭`);
51
+ this.logger.info(`${roomId}直播间连接已关闭`);
51
52
  // 直接返回
52
53
  return;
53
54
  }
54
55
  // 未关闭成功
55
- this.logger.warn(`${roomId}直播间弹幕监听未成功关闭`);
56
+ this.logger.warn(`${roomId}直播间连接未成功关闭`);
56
57
  }
57
58
  }
58
59
  exports.default = BLive;
@@ -92,6 +92,7 @@ declare namespace ComRegister {
92
92
  customLive: string;
93
93
  customLiveEnd: string;
94
94
  dynamicUrl: boolean;
95
+ dynamicVideoUrlToBV: boolean;
95
96
  filter: {
96
97
  enable: boolean;
97
98
  notify: boolean;
@@ -673,7 +673,17 @@ class ComRegister {
673
673
  // 判断是否需要发送URL
674
674
  if (this.config.dynamicUrl) {
675
675
  if (item.type === "DYNAMIC_TYPE_AV") {
676
- dUrl = `${name}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
676
+ // 判断是否开启url to bv
677
+ if (this.config.dynamicVideoUrlToBV) {
678
+ // 截取bv号
679
+ const bv = item.modules.module_dynamic.major.archive.jump_url.match(/BV[0-9A-Za-z]+/);
680
+ // 获取bv号
681
+ dUrl = bv ? bv[0] : "";
682
+ }
683
+ else {
684
+ // 生成视频链接
685
+ dUrl = `${name}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
686
+ }
677
687
  }
678
688
  else {
679
689
  // 生成动态链接
@@ -692,11 +702,10 @@ class ComRegister {
692
702
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
693
703
  // 判断pics是否存在
694
704
  if (pics) {
695
- for (const pic of pics) {
696
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
697
- // 随机睡眠1-3秒
698
- await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
699
- }
705
+ // 组合消息
706
+ const picsMsg = ((0, jsx_runtime_1.jsx)("message", { forward: true, children: pics.map((pic) => ((0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }, pic.url))) }));
707
+ // 发送消息
708
+ await this.broadcastToTargets(sub.target, picsMsg, type_1.PushType.Dynamic);
700
709
  }
701
710
  }
702
711
  }
@@ -860,7 +869,17 @@ class ComRegister {
860
869
  this.logger.info("需要发送动态链接,开始生成链接...");
861
870
  // 判断动态类型
862
871
  if (item.type === "DYNAMIC_TYPE_AV") {
863
- dUrl = `${name}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
872
+ // 判断是否开启url to bv
873
+ if (this.config.dynamicVideoUrlToBV) {
874
+ // 截取bv号
875
+ const bv = item.modules.module_dynamic.major.archive.jump_url.match(/BV[0-9A-Za-z]+/);
876
+ // 获取bv号
877
+ dUrl = bv ? bv[0] : "";
878
+ }
879
+ else {
880
+ // 生成视频链接
881
+ dUrl = `${name}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
882
+ }
864
883
  }
865
884
  else {
866
885
  // 生成动态链接
@@ -883,11 +902,10 @@ class ComRegister {
883
902
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
884
903
  // 判断pics是否存在
885
904
  if (pics) {
886
- for (const pic of pics) {
887
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
888
- // 随机睡眠1-3秒
889
- await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
890
- }
905
+ // 组合消息
906
+ const picsMsg = ((0, jsx_runtime_1.jsx)("message", { forward: true, children: pics.map((pic) => ((0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }, pic.url))) }));
907
+ // 发送消息
908
+ await this.broadcastToTargets(sub.target, picsMsg, type_1.PushType.Dynamic);
891
909
  }
892
910
  }
893
911
  // logger
@@ -997,10 +1015,6 @@ class ComRegister {
997
1015
  let pushAtTimeTimer;
998
1016
  // 定义弹幕存放数组
999
1017
  const currentLiveDanmakuArr = [];
1000
- // init flag
1001
- let initFlag = false;
1002
- // 连接中断flag
1003
- let connFlag = false;
1004
1018
  // 定义开播状态
1005
1019
  let liveStatus = false;
1006
1020
  // 定义channelIdArr总长度
@@ -1093,31 +1107,6 @@ class ComRegister {
1093
1107
  };
1094
1108
  // 构建消息处理函数
1095
1109
  const handler = {
1096
- onOpen: () => {
1097
- if (!initFlag) {
1098
- // init flag设置为true
1099
- initFlag = true;
1100
- // connFlag设置为false
1101
- connFlag = false;
1102
- // logger
1103
- this.logger.info(`[${roomId}]直播间连接已建立!`);
1104
- }
1105
- },
1106
- onClose: async () => {
1107
- if (!connFlag) {
1108
- // 更直播状态
1109
- liveStatus = false;
1110
- // 关闭定时推送
1111
- pushAtTimeTimer?.();
1112
- // 停止服务
1113
- this.ctx.bl.closeListener(roomId);
1114
- // 更改connFlag
1115
- connFlag = true;
1116
- // 发送消息
1117
- await this.sendPrivateMsg(`[${roomId}]直播间连接已中断!`);
1118
- this.logger.error(`[${roomId}]直播间连接已中断!`);
1119
- }
1120
- },
1121
1110
  onError: async () => {
1122
1111
  // 更直播状态
1123
1112
  liveStatus = false;
@@ -1887,6 +1876,7 @@ class ComRegister {
1887
1876
  customLive: koishi_1.Schema.string(),
1888
1877
  customLiveEnd: koishi_1.Schema.string().required(),
1889
1878
  dynamicUrl: koishi_1.Schema.boolean().required(),
1879
+ dynamicVideoUrlToBV: koishi_1.Schema.boolean().required(),
1890
1880
  filter: koishi_1.Schema.object({
1891
1881
  enable: koishi_1.Schema.boolean(),
1892
1882
  notify: koishi_1.Schema.boolean(),
package/lib/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export interface Config {
42
42
  }>;
43
43
  dynamic: {};
44
44
  dynamicUrl: boolean;
45
+ dynamicVideoUrlToBV: boolean;
45
46
  pushImgsInDynamic: boolean;
46
47
  live: {};
47
48
  liveDetectType: "WS" | "API";
package/lib/index.js CHANGED
@@ -134,6 +134,7 @@ class ServerManager extends koishi_1.Service {
134
134
  customLive: globalConfig.customLive,
135
135
  customLiveEnd: globalConfig.customLiveEnd,
136
136
  dynamicUrl: globalConfig.dynamicUrl,
137
+ dynamicVideoUrlToBV: globalConfig.dynamicVideoUrlToBV,
137
138
  filter: globalConfig.filter,
138
139
  dynamicDebugMode: globalConfig.dynamicDebugMode,
139
140
  });
@@ -314,6 +315,9 @@ exports.Config = koishi_1.Schema.object({
314
315
  dynamicUrl: koishi_1.Schema.boolean()
315
316
  .default(false)
316
317
  .description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
318
+ dynamicVideoUrlToBV: koishi_1.Schema.boolean()
319
+ .default(false)
320
+ .description("如果推送的动态是视频动态,且开启了发送链接选项,开启此选项则会将链接转换为BV号以便其他用途"),
317
321
  pushImgsInDynamic: koishi_1.Schema.boolean()
318
322
  .default(false)
319
323
  .description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.2.2",
4
+ "version": "3.2.4-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -267,6 +267,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
267
267
  - ver 3.2.1-alpha.11 WARNING:测试版本;
268
268
  - ver 3.2.1 优化:移除不必要成员变量、创建自动上传npm `github actions`,添加相关开发依赖;
269
269
  - ver 3.2.2 调整:修改 `github actions`;
270
+ - ver 3.2.3 优化:移除不必要的代码;
271
+ - ver 3.2.4-alpha.0 优化:选项 `pushImagesInDynamic` 发送多图会以转发消息的格式发送; 新增:选项 `dynamicVideoUrlToBV` 开启后将链接转换为bv号以用作特殊用途;
270
272
 
271
273
  ## 交流群
272
274