koishi-plugin-bilibili-notify 3.2.0-alpha.7 → 3.2.1-alpha.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.
@@ -1,19 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@satorijs/element/jsx-runtime";
7
2
  // Koishi核心依赖
8
- const koishi_1 = require("koishi");
9
- // 外部依赖:qrcode
10
- const qrcode_1 = __importDefault(require("qrcode"));
11
- const cron_1 = require("cron");
3
+ import { Schema, h, } from "koishi";
4
+ import QRCode from "qrcode";
5
+ import { CronJob } from "cron";
12
6
  // Utils
13
- const utils_1 = require("./utils");
7
+ import { withLock, withRetry } from "./utils";
14
8
  // Types
15
- const type_1 = require("./type");
16
- const luxon_1 = require("luxon");
9
+ import { LiveType, PushType, } from "./type";
10
+ import { DateTime } from "luxon";
17
11
  class ComRegister {
18
12
  // 必须服务
19
13
  static inject = ["ba", "gi", "database", "bl", "sm"];
@@ -124,7 +118,7 @@ class ComRegister {
124
118
  if (content.code !== 0)
125
119
  return await session.send("出问题咯,请联系管理员解决");
126
120
  // 生成二维码
127
- qrcode_1.default.toBuffer(content.data.url, {
121
+ QRCode.toBuffer(content.data.url, {
128
122
  errorCorrectionLevel: "H", // 错误更正水平
129
123
  type: "png", // 输出类型
130
124
  margin: 1, // 边距大小
@@ -135,7 +129,7 @@ class ComRegister {
135
129
  }, async (err, buffer) => {
136
130
  if (err)
137
131
  return await session.send("二维码生成出错,请重新尝试");
138
- await session.send(koishi_1.h.image(buffer, "image/jpeg"));
132
+ await session.send(h.image(buffer, "image/jpeg"));
139
133
  });
140
134
  // 检查之前是否存在登录定时器
141
135
  if (this.loginTimer)
@@ -273,7 +267,7 @@ class ComRegister {
273
267
  // 获取动态内容
274
268
  const item = content.data.items[i];
275
269
  // 生成图片
276
- const buffer = await (0, utils_1.withRetry)(async () => {
270
+ const buffer = await withRetry(async () => {
277
271
  // 渲染图片
278
272
  return await this.ctx.gi.generateDynamicImg(item);
279
273
  }, 1).catch(async (e) => {
@@ -298,7 +292,7 @@ class ComRegister {
298
292
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
299
293
  });
300
294
  // 发送图片
301
- buffer && (await session.send(koishi_1.h.image(buffer, "image/jpeg")));
295
+ buffer && (await session.send(h.image(buffer, "image/jpeg")));
302
296
  });
303
297
  }
304
298
  async init(config) {
@@ -363,7 +357,7 @@ class ComRegister {
363
357
  initManager() {
364
358
  for (const sub of this.subManager) {
365
359
  if (sub.dynamic) {
366
- this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon_1.DateTime.now().toSeconds()));
360
+ this.dynamicTimelineManager.set(sub.uid, Math.floor(DateTime.now().toSeconds()));
367
361
  }
368
362
  if (sub.live) {
369
363
  this.liveStatusManager.set(sub.uid, {
@@ -380,8 +374,14 @@ class ComRegister {
380
374
  }
381
375
  }
382
376
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
383
- getBot(pf) {
384
- return this.ctx.bots.find((bot) => bot.platform === pf);
377
+ getBot(pf, selfId) {
378
+ // 判断是否存在selfId
379
+ if (!selfId || selfId === "") {
380
+ // 不存在则默认第一个bot
381
+ return this.ctx.bots.find((bot) => bot.platform === pf);
382
+ }
383
+ // 存在则返回对应bot
384
+ return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
385
385
  }
386
386
  async sendPrivateMsg(content) {
387
387
  if (this.config.master.enable) {
@@ -439,7 +439,7 @@ class ComRegister {
439
439
  async sendMessageWithRetry(bot, channelId,
440
440
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
441
441
  content) {
442
- (0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
442
+ withRetry(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
443
443
  if (e.message === "this._request is not a function") {
444
444
  // 2S之后重新发送消息
445
445
  this.ctx.setTimeout(async () => {
@@ -457,7 +457,7 @@ class ComRegister {
457
457
  // 定义数组
458
458
  const pushArr = [];
459
459
  // 判断类型
460
- if (type === type_1.PushType.Live || type === type_1.PushType.StartBroadcasting) {
460
+ if (type === PushType.Live || type === PushType.StartBroadcasting) {
461
461
  for (const target of targets) {
462
462
  for (const channel of target.channelArr) {
463
463
  if (channel.live) {
@@ -467,7 +467,7 @@ class ComRegister {
467
467
  }
468
468
  return pushArr;
469
469
  }
470
- if (type === type_1.PushType.Dynamic) {
470
+ if (type === PushType.Dynamic) {
471
471
  for (const target of targets) {
472
472
  for (const channel of target.channelArr) {
473
473
  if (channel.dynamic) {
@@ -477,7 +477,7 @@ class ComRegister {
477
477
  }
478
478
  return pushArr;
479
479
  }
480
- if (type === type_1.PushType.LiveGuardBuy) {
480
+ if (type === PushType.LiveGuardBuy) {
481
481
  for (const target of targets) {
482
482
  for (const channel of target.channelArr) {
483
483
  if (channel.liveGuardBuy) {
@@ -497,7 +497,7 @@ class ComRegister {
497
497
  // logger
498
498
  this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
499
499
  // 推送消息
500
- await (0, utils_1.withRetry)(async () => {
500
+ await withRetry(async () => {
501
501
  await this.ctx.broadcast(pushArr, content);
502
502
  }, 1);
503
503
  // 结束
@@ -506,31 +506,40 @@ class ComRegister {
506
506
  // 获取目标
507
507
  const targetChannel = targets[0].channelArr[0];
508
508
  // 获取机器人实例
509
- const bot = this.getBot(targets[0].platform);
509
+ const bot = this.getBot(targets[0].platform, targetChannel.bot);
510
+ // 判断bot是否存在
511
+ if (!bot) {
512
+ // 发送私聊消息
513
+ this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
514
+ // logger
515
+ this.logger.warn("未找到对应bot实例,本次消息推送取消!");
516
+ // 直接返回
517
+ return;
518
+ }
510
519
  // 模式匹配
511
520
  const pushTypePatternMatching = {
512
- [type_1.PushType.Live]: async () => {
521
+ [PushType.Live]: async () => {
513
522
  if (targetChannel.live) {
514
523
  // 直接推送
515
524
  await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
516
525
  }
517
526
  },
518
- [type_1.PushType.Dynamic]: async () => {
527
+ [PushType.Dynamic]: async () => {
519
528
  if (targetChannel.dynamic) {
520
529
  await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
521
530
  }
522
531
  },
523
- [type_1.PushType.StartBroadcasting]: async () => {
532
+ [PushType.StartBroadcasting]: async () => {
524
533
  // 判断是否需要推送直播消息
525
534
  if (targetChannel.live) {
526
535
  await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
527
536
  }
528
537
  // 判断是否需要艾特全体成员
529
538
  if (targetChannel.atAll) {
530
- await this.sendMessageWithRetry(bot, targetChannel.channelId, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
539
+ await this.sendMessageWithRetry(bot, targetChannel.channelId, _jsx("at", { type: "all" }));
531
540
  }
532
541
  },
533
- [type_1.PushType.LiveGuardBuy]: async () => {
542
+ [PushType.LiveGuardBuy]: async () => {
534
543
  // 判断是否需要推送直播消息
535
544
  if (targetChannel.liveGuardBuy) {
536
545
  await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
@@ -546,7 +555,7 @@ class ComRegister {
546
555
  // 定义本次请求推送的动态
547
556
  const currentPushDyn = {};
548
557
  // 使用withRetry函数进行重试
549
- const content = await (0, utils_1.withRetry)(async () => {
558
+ const content = await withRetry(async () => {
550
559
  // 获取动态内容
551
560
  return (await this.ctx.ba.getAllDynamic());
552
561
  }, 1).catch((e) => {
@@ -620,7 +629,7 @@ class ComRegister {
620
629
  // 获取订阅对象
621
630
  const sub = this.subManager.find((sub) => sub.uid === uid);
622
631
  // 推送该条动态
623
- const buffer = await (0, utils_1.withRetry)(async () => {
632
+ const buffer = await withRetry(async () => {
624
633
  // 渲染图片
625
634
  return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : undefined);
626
635
  }, 1).catch(async (e) => {
@@ -630,19 +639,19 @@ class ComRegister {
630
639
  if (e.message === "出现关键词,屏蔽该动态") {
631
640
  // 如果需要发送才发送
632
641
  if (this.config.filter.notify) {
633
- await this.broadcastToTargets(sub.target, `${name}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
642
+ await this.broadcastToTargets(sub.target, `${name}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
634
643
  }
635
644
  return;
636
645
  }
637
646
  if (e.message === "已屏蔽转发动态") {
638
647
  if (this.config.filter.notify) {
639
- await this.broadcastToTargets(sub.target, `${name}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
648
+ await this.broadcastToTargets(sub.target, `${name}转发了一条动态,已屏蔽`, PushType.Dynamic);
640
649
  }
641
650
  return;
642
651
  }
643
652
  if (e.message === "已屏蔽专栏动态") {
644
653
  if (this.config.filter.notify) {
645
- await this.broadcastToTargets(sub.target, `${name}投稿了一条专栏,已屏蔽`, type_1.PushType.Dynamic);
654
+ await this.broadcastToTargets(sub.target, `${name}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
646
655
  }
647
656
  return;
648
657
  }
@@ -669,17 +678,20 @@ class ComRegister {
669
678
  // logger
670
679
  this.logger.info("推送动态中...");
671
680
  // 发送推送卡片
672
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
681
+ await this.broadcastToTargets(sub.target, _jsxs(_Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
673
682
  // 判断是否需要发送动态中的图片
674
683
  if (this.config.pushImgsInDynamic) {
675
- // 获取pics
676
- const pics = item.modules.module_dynamic.major.opus?.pics;
677
- // 判断是否为图文动态,且存在pics
678
- if (item.type === "DYNAMIC_TYPE_DRAW" && pics) {
679
- for (const pic of pics) {
680
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
681
- // 随机睡眠1-3秒
682
- await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
684
+ // 判断是否为图文动态
685
+ if (item.type === "DYNAMIC_TYPE_DRAW") {
686
+ // 获取pics
687
+ const pics = item.modules?.module_dynamic?.major?.opus?.pics;
688
+ // 判断pics是否存在
689
+ if (pics) {
690
+ for (const pic of pics) {
691
+ await this.broadcastToTargets(sub.target, _jsx("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), PushType.Dynamic);
692
+ // 随机睡眠1-3秒
693
+ await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
694
+ }
683
695
  }
684
696
  }
685
697
  }
@@ -702,7 +714,7 @@ class ComRegister {
702
714
  }
703
715
  };
704
716
  // 返回一个闭包函数
705
- return (0, utils_1.withLock)(handler);
717
+ return withLock(handler);
706
718
  }
707
719
  debug_dynamicDetect() {
708
720
  // 定义handler
@@ -712,7 +724,7 @@ class ComRegister {
712
724
  // logger
713
725
  this.logger.info("开始获取动态信息...");
714
726
  // 使用withRetry函数进行重试
715
- const content = await (0, utils_1.withRetry)(async () => {
727
+ const content = await withRetry(async () => {
716
728
  // 获取动态内容
717
729
  return (await this.ctx.ba.getAllDynamic());
718
730
  }, 1).catch((e) => {
@@ -781,7 +793,7 @@ class ComRegister {
781
793
  const uid = item.modules.module_author.mid.toString();
782
794
  const name = item.modules.module_author.name;
783
795
  // logger
784
- this.logger.info(`获取到动态信息,UP主:${name},UID:${uid},动态发布时间:${luxon_1.DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
796
+ this.logger.info(`获取到动态信息,UP主:${name},UID:${uid},动态发布时间:${DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
785
797
  // 判断是否存在时间线
786
798
  if (this.dynamicTimelineManager.has(uid)) {
787
799
  // logger
@@ -789,7 +801,7 @@ class ComRegister {
789
801
  // 寻找关注的UP主
790
802
  const timeline = this.dynamicTimelineManager.get(uid);
791
803
  // logger
792
- this.logger.info(`上次推送时间线:${luxon_1.DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
804
+ this.logger.info(`上次推送时间线:${DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
793
805
  // 判断动态发布时间是否大于时间线
794
806
  if (timeline < postTime) {
795
807
  // logger
@@ -799,7 +811,7 @@ class ComRegister {
799
811
  // logger
800
812
  this.logger.info("开始渲染推送卡片...");
801
813
  // 推送该条动态
802
- const buffer = await (0, utils_1.withRetry)(async () => {
814
+ const buffer = await withRetry(async () => {
803
815
  // 渲染图片
804
816
  return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : undefined);
805
817
  }, 1).catch(async (e) => {
@@ -809,19 +821,19 @@ class ComRegister {
809
821
  if (e.message === "出现关键词,屏蔽该动态") {
810
822
  // 如果需要发送才发送
811
823
  if (this.config.filter.notify) {
812
- await this.broadcastToTargets(sub.target, `${name}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
824
+ await this.broadcastToTargets(sub.target, `${name}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
813
825
  }
814
826
  return;
815
827
  }
816
828
  if (e.message === "已屏蔽转发动态") {
817
829
  if (this.config.filter.notify) {
818
- await this.broadcastToTargets(sub.target, `${name}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
830
+ await this.broadcastToTargets(sub.target, `${name}转发了一条动态,已屏蔽`, PushType.Dynamic);
819
831
  }
820
832
  return;
821
833
  }
822
834
  if (e.message === "已屏蔽专栏动态") {
823
835
  if (this.config.filter.notify) {
824
- await this.broadcastToTargets(sub.target, `${name}投稿了一条专栏,已屏蔽`, type_1.PushType.Dynamic);
836
+ await this.broadcastToTargets(sub.target, `${name}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
825
837
  }
826
838
  return;
827
839
  }
@@ -855,19 +867,22 @@ class ComRegister {
855
867
  // logger
856
868
  this.logger.info("推送动态中...");
857
869
  // 发送推送卡片
858
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
870
+ await this.broadcastToTargets(sub.target, _jsxs(_Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
859
871
  // 判断是否需要发送动态中的图片
860
872
  if (this.config.pushImgsInDynamic) {
861
873
  // logger
862
874
  this.logger.info("需要发送动态中的图片,开始发送...");
863
- // 获取pics
864
- const pics = item.modules.module_dynamic.major.opus?.pics;
865
- // 判断是否为图文动态,且存在pics
866
- if (item.type === "DYNAMIC_TYPE_DRAW" && pics) {
867
- for (const pic of pics) {
868
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
869
- // 随机睡眠1-3秒
870
- await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
875
+ // 判断是否为图文动态
876
+ if (item.type === "DYNAMIC_TYPE_DRAW") {
877
+ // 获取pics
878
+ const pics = item.modules?.module_dynamic?.major?.opus?.pics;
879
+ // 判断pics是否存在
880
+ if (pics) {
881
+ for (const pic of pics) {
882
+ await this.broadcastToTargets(sub.target, _jsx("img", { src: pic.url, alt: "\u52A8\u6001\u56FE\u7247" }), PushType.Dynamic);
883
+ // 随机睡眠1-3秒
884
+ await this.ctx.sleep(Math.floor(Math.random() * 2000) + 1000);
885
+ }
871
886
  }
872
887
  }
873
888
  // logger
@@ -892,13 +907,13 @@ class ComRegister {
892
907
  // 更新当前时间线
893
908
  this.dynamicTimelineManager.set(uid, postTime);
894
909
  // logger
895
- this.logger.info(`更新时间线成功,UP主:${uid},时间线:${luxon_1.DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
910
+ this.logger.info(`更新时间线成功,UP主:${uid},时间线:${DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
896
911
  }
897
912
  // logger
898
913
  this.logger.info(`本次推送动态数量:${Object.keys(currentPushDyn).length}`);
899
914
  };
900
915
  // 返回一个闭包函数
901
- return (0, utils_1.withLock)(handler);
916
+ return withLock(handler);
902
917
  }
903
918
  // 定义获取主播信息方法
904
919
  async useMasterInfo(uid, masterInfo, liveType) {
@@ -909,8 +924,8 @@ class ComRegister {
909
924
  let liveEndFollowerNum;
910
925
  let liveFollowerChange;
911
926
  // 判断直播状态
912
- if (liveType === type_1.LiveType.StartBroadcasting ||
913
- liveType === type_1.LiveType.FirstLiveBroadcast) {
927
+ if (liveType === LiveType.StartBroadcasting ||
928
+ liveType === LiveType.FirstLiveBroadcast) {
914
929
  // 第一次启动或刚开播
915
930
  // 将当前粉丝数赋值给liveOpenFollowerNum、liveEndFollowerNum
916
931
  liveOpenFollowerNum = data.follower_num;
@@ -918,8 +933,8 @@ class ComRegister {
918
933
  // 将粉丝数变化赋值为0
919
934
  liveFollowerChange = 0;
920
935
  }
921
- if (liveType === type_1.LiveType.StopBroadcast ||
922
- liveType === type_1.LiveType.LiveBroadcast) {
936
+ if (liveType === LiveType.StopBroadcast ||
937
+ liveType === LiveType.LiveBroadcast) {
923
938
  // 将上一次的liveOpenFollowerNum赋值给本次的liveOpenFollowerNum
924
939
  liveOpenFollowerNum = masterInfo.liveOpenFollowerNum;
925
940
  // 将当前粉丝数赋值给liveEndFollowerNum
@@ -939,7 +954,7 @@ class ComRegister {
939
954
  }
940
955
  async useLiveRoomInfo(roomId) {
941
956
  // 发送请求获取直播间信息
942
- const data = await (0, utils_1.withRetry)(async () => await this.ctx.ba.getLiveRoomInfo(roomId))
957
+ const data = await withRetry(async () => await this.ctx.ba.getLiveRoomInfo(roomId))
943
958
  .then((content) => content.data)
944
959
  .catch((e) => {
945
960
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
@@ -954,7 +969,7 @@ class ComRegister {
954
969
  }
955
970
  async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
956
971
  // 生成图片
957
- const buffer = await (0, utils_1.withRetry)(async () => {
972
+ const buffer = await withRetry(async () => {
958
973
  // 获取直播通知卡片
959
974
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : undefined);
960
975
  }, 1).catch((e) => {
@@ -964,11 +979,11 @@ class ComRegister {
964
979
  if (!buffer)
965
980
  return await this.sendPrivateMsgAndStopService();
966
981
  // 推送直播信息
967
- const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
982
+ const msg = (_jsxs(_Fragment, { children: [h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
968
983
  // 只有在开播时才艾特全体成员
969
- return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting
970
- ? type_1.PushType.StartBroadcasting
971
- : type_1.PushType.Live);
984
+ return await this.broadcastToTargets(target, msg, liveType === LiveType.StartBroadcasting
985
+ ? PushType.StartBroadcasting
986
+ : PushType.Live);
972
987
  }
973
988
  async liveDetectWithListener(roomId, target, cardStyle) {
974
989
  // 定义开播时间
@@ -977,9 +992,12 @@ class ComRegister {
977
992
  let pushAtTimeTimer;
978
993
  // 定义弹幕存放数组
979
994
  const currentLiveDanmakuArr = [];
995
+ // init flag
996
+ let initFlag = false;
997
+ // 连接中断flag
998
+ let connFlag = false;
980
999
  // 定义开播状态
981
1000
  let liveStatus = false;
982
- // 处理target
983
1001
  // 定义channelIdArr总长度
984
1002
  let channelArrLen = 0;
985
1003
  // 定义数据
@@ -1003,20 +1021,22 @@ class ComRegister {
1003
1021
  // 定义定时推送函数
1004
1022
  const pushAtTimeFunc = async () => {
1005
1023
  // 判断是否信息是否获取成功
1006
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.LiveBroadcast))) {
1024
+ if (!(await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast))) {
1007
1025
  // 未获取成功,直接返回
1008
1026
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1009
1027
  // 停止服务
1010
1028
  return await this.sendPrivateMsgAndStopService();
1011
1029
  }
1012
1030
  // 判断是否已经下播
1013
- if (liveRoomInfo.live_status === 0) {
1031
+ if (liveRoomInfo.live_status === 0 || liveRoomInfo.live_status === 2) {
1014
1032
  // 设置开播状态为false
1015
1033
  liveStatus = false;
1016
1034
  // 清除定时器
1017
1035
  pushAtTimeTimer?.();
1018
1036
  // 发送私聊消息
1019
- await this.sendPrivateMsg("直播间已下播,定时推送已停止!与直播间的连接可能已断开,请使用指令 sys restart 重启插件");
1037
+ await this.sendPrivateMsg("直播间已下播!与直播间的连接可能已断开,请使用指令 sys restart 重启插件");
1038
+ // 返回
1039
+ return;
1020
1040
  }
1021
1041
  // 设置开播时间
1022
1042
  liveTime = liveRoomInfo.live_time;
@@ -1032,7 +1052,7 @@ class ComRegister {
1032
1052
  .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1033
1053
  : null;
1034
1054
  // 发送直播通知卡片
1035
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, watched, {
1055
+ await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
1036
1056
  liveRoomInfo,
1037
1057
  masterInfo,
1038
1058
  cardStyle,
@@ -1068,6 +1088,31 @@ class ComRegister {
1068
1088
  };
1069
1089
  // 构建消息处理函数
1070
1090
  const handler = {
1091
+ onOpen: () => {
1092
+ if (!initFlag) {
1093
+ // init flag设置为true
1094
+ initFlag = true;
1095
+ // connFlag设置为false
1096
+ connFlag = false;
1097
+ // logger
1098
+ this.logger.info(`${roomId}直播间连接已建立!`);
1099
+ }
1100
+ },
1101
+ onClose: async () => {
1102
+ if (!connFlag) {
1103
+ // 更直播状态
1104
+ liveStatus = false;
1105
+ // 关闭定时推送
1106
+ pushAtTimeTimer?.();
1107
+ // 停止服务
1108
+ this.ctx.bl.closeListener(roomId);
1109
+ // 更改connFlag
1110
+ connFlag = true;
1111
+ // 发送消息
1112
+ await this.sendPrivateMsg(`${roomId}直播间连接已中断!`);
1113
+ this.logger.error(`${roomId}直播间连接已中断!`);
1114
+ }
1115
+ },
1071
1116
  onIncomeDanmu: ({ body }) => {
1072
1117
  // 保存消息到数组
1073
1118
  currentLiveDanmakuArr.push(body.content);
@@ -1085,7 +1130,7 @@ class ComRegister {
1085
1130
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1086
1131
  // 直接发送消息
1087
1132
  channelArrLen > 0 &&
1088
- this.broadcastToTargets(liveGuardBuyPushTargetArr, content, type_1.PushType.LiveGuardBuy);
1133
+ this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1089
1134
  },
1090
1135
  onLiveStart: async () => {
1091
1136
  // 判断是否已经开播
@@ -1094,7 +1139,7 @@ class ComRegister {
1094
1139
  // 设置开播状态为true
1095
1140
  liveStatus = true;
1096
1141
  // 判断是否信息是否获取成功
1097
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StartBroadcasting))) {
1142
+ if (!(await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting))) {
1098
1143
  // 设置开播状态为false
1099
1144
  liveStatus = false;
1100
1145
  // 未获取成功,直接返回
@@ -1118,7 +1163,7 @@ class ComRegister {
1118
1163
  .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1119
1164
  : null;
1120
1165
  // 推送开播通知
1121
- await this.sendLiveNotifyCard(type_1.LiveType.StartBroadcasting, follower, {
1166
+ await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
1122
1167
  liveRoomInfo,
1123
1168
  masterInfo,
1124
1169
  cardStyle,
@@ -1133,7 +1178,7 @@ class ComRegister {
1133
1178
  // 将直播状态设置为false
1134
1179
  liveStatus = false;
1135
1180
  // 判断是否信息是否获取成功
1136
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast))) {
1181
+ if (!(await useMasterAndLiveRoomInfo(LiveType.StopBroadcast))) {
1137
1182
  // 未获取成功,直接返回
1138
1183
  await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1139
1184
  // 停止服务
@@ -1166,7 +1211,7 @@ class ComRegister {
1166
1211
  .replace("\\n", "\n")
1167
1212
  : null;
1168
1213
  // 推送通知卡片
1169
- await this.sendLiveNotifyCard(type_1.LiveType.StopBroadcast, followerChange, {
1214
+ await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
1170
1215
  liveRoomInfo,
1171
1216
  masterInfo,
1172
1217
  cardStyle,
@@ -1180,7 +1225,7 @@ class ComRegister {
1180
1225
  // 启动直播间弹幕监测
1181
1226
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
1182
1227
  // 第一次启动获取信息并判信息是否获取成功
1183
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.FirstLiveBroadcast))) {
1228
+ if (!(await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast))) {
1184
1229
  // 未获取成功,直接返回
1185
1230
  return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1186
1231
  }
@@ -1201,7 +1246,7 @@ class ComRegister {
1201
1246
  : null;
1202
1247
  // 发送直播通知卡片
1203
1248
  if (this.config.restartPush) {
1204
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, watched, {
1249
+ await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
1205
1250
  liveRoomInfo,
1206
1251
  masterInfo,
1207
1252
  cardStyle,
@@ -1251,7 +1296,7 @@ class ComRegister {
1251
1296
  }
1252
1297
  const useLiveInfo = async () => {
1253
1298
  // 发送请求
1254
- const { data } = await (0, utils_1.withRetry)(async () => (await this.ctx.ba.getLiveRoomInfoByUids(uids)), 3).catch(async () => {
1299
+ const { data } = await withRetry(async () => (await this.ctx.ba.getLiveRoomInfoByUids(uids)), 3).catch(async () => {
1255
1300
  // 返回undefined
1256
1301
  return undefined;
1257
1302
  });
@@ -1278,7 +1323,7 @@ class ComRegister {
1278
1323
  // 将直播状态改为true
1279
1324
  liveStatus.live = true;
1280
1325
  // 初始化主播和直播间信息
1281
- await useMasterAndLiveRoomInfo(type_1.LiveType.FirstLiveBroadcast, liveStatus);
1326
+ await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, liveStatus);
1282
1327
  // 判断是否需要设置开播时间
1283
1328
  if (!liveStatus.liveStartTimeInit) {
1284
1329
  // 设置开播时间
@@ -1296,7 +1341,7 @@ class ComRegister {
1296
1341
  .replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
1297
1342
  : null;
1298
1343
  // 发送直播通知卡片
1299
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, "API", {
1344
+ await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
1300
1345
  liveRoomInfo: liveStatus.liveRoomInfo,
1301
1346
  masterInfo: liveStatus.masterInfo,
1302
1347
  cardStyle: sub.card,
@@ -1326,7 +1371,7 @@ class ComRegister {
1326
1371
  if (liveStatus.live === true) {
1327
1372
  // 现在下播了,发送下播通知
1328
1373
  // 判断信息是否获取成功
1329
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast, liveStatus))) {
1374
+ if (!(await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, liveStatus))) {
1330
1375
  // 未获取成功,直接返回
1331
1376
  await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1332
1377
  // 停止服务
@@ -1364,7 +1409,7 @@ class ComRegister {
1364
1409
  .replace("\\n", "\n")
1365
1410
  : null;
1366
1411
  // 推送通知卡片
1367
- await this.sendLiveNotifyCard(type_1.LiveType.StopBroadcast, followerChange, {
1412
+ await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
1368
1413
  liveRoomInfo: liveStatus.liveRoomInfo,
1369
1414
  masterInfo: liveStatus.masterInfo,
1370
1415
  cardStyle: sub.card,
@@ -1380,7 +1425,7 @@ class ComRegister {
1380
1425
  if (liveStatus.live === false) {
1381
1426
  // 开播了
1382
1427
  // 判断信息是否获取成功
1383
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast, liveStatus))) {
1428
+ if (!(await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, liveStatus))) {
1384
1429
  // 未获取成功,直接返回
1385
1430
  await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1386
1431
  // 停止服务
@@ -1404,7 +1449,7 @@ class ComRegister {
1404
1449
  .replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
1405
1450
  : null;
1406
1451
  // 推送开播通知
1407
- await this.sendLiveNotifyCard(type_1.LiveType.StartBroadcasting, follower, {
1452
+ await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
1408
1453
  liveRoomInfo: liveStatus.liveRoomInfo,
1409
1454
  masterInfo: liveStatus.masterInfo,
1410
1455
  cardStyle: sub.card,
@@ -1421,7 +1466,7 @@ class ComRegister {
1421
1466
  break;
1422
1467
  }
1423
1468
  // 判断是否信息是否获取成功
1424
- if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.LiveBroadcast, liveStatus))) {
1469
+ if (!(await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast, liveStatus))) {
1425
1470
  // 未获取成功,直接返回
1426
1471
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1427
1472
  // 停止服务
@@ -1444,7 +1489,7 @@ class ComRegister {
1444
1489
  .replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
1445
1490
  : null;
1446
1491
  // 发送直播通知卡片
1447
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, "API", {
1492
+ await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
1448
1493
  liveRoomInfo: liveStatus.liveRoomInfo,
1449
1494
  masterInfo: liveStatus.masterInfo,
1450
1495
  cardStyle: sub.card,
@@ -1461,7 +1506,7 @@ class ComRegister {
1461
1506
  }
1462
1507
  };
1463
1508
  // 返回一个闭包函数
1464
- return (0, utils_1.withLock)(handler);
1509
+ return withLock(handler);
1465
1510
  }
1466
1511
  subShow() {
1467
1512
  // 在控制台中显示订阅对象
@@ -1487,9 +1532,9 @@ class ComRegister {
1487
1532
  const subTableArray = subInfo.split("\n");
1488
1533
  subTableArray.splice(subTableArray.length - 1, 1);
1489
1534
  // 定义Table
1490
- table = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map((str) => (
1535
+ table = (_jsxs(_Fragment, { children: [_jsx("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), _jsx("ul", { children: subTableArray.map((str) => (
1491
1536
  // biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
1492
- (0, jsx_runtime_1.jsx)("li", { children: str }))) })] }));
1537
+ _jsx("li", { children: str }))) })] }));
1493
1538
  }
1494
1539
  // 设置更新后的提示
1495
1540
  this.subNotifier = this.ctx.notifier.create(table);
@@ -1679,7 +1724,7 @@ class ComRegister {
1679
1724
  // logger
1680
1725
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1681
1726
  // 定义Data
1682
- const { code: userInfoCode, msg: userInfoMsg, data: userInfoData, } = await (0, utils_1.withRetry)(async () => {
1727
+ const { code: userInfoCode, msg: userInfoMsg, data: userInfoData, } = await withRetry(async () => {
1683
1728
  // 获取用户信息
1684
1729
  const data = await this.ctx.ba.getUserInfo(sub.uid);
1685
1730
  // 返回用户信息
@@ -1756,7 +1801,7 @@ class ComRegister {
1756
1801
  }
1757
1802
  enableDynamicDetect() {
1758
1803
  // 定义Job
1759
- this.dynamicJob = new cron_1.CronJob("*/2 * * * *", this.config.dynamicDebugMode
1804
+ this.dynamicJob = new CronJob("*/2 * * * *", this.config.dynamicDebugMode
1760
1805
  ? this.debug_dynamicDetect()
1761
1806
  : this.dynamicDetect());
1762
1807
  // logger
@@ -1766,7 +1811,7 @@ class ComRegister {
1766
1811
  }
1767
1812
  async enableLiveDetect() {
1768
1813
  // 定义Job
1769
- this.liveJob = new cron_1.CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
1814
+ this.liveJob = new CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
1770
1815
  // logger
1771
1816
  this.logger.info("直播监测已开启");
1772
1817
  // 开始直播监测
@@ -1785,53 +1830,54 @@ class ComRegister {
1785
1830
  }
1786
1831
  }
1787
1832
  (function (ComRegister) {
1788
- ComRegister.Config = koishi_1.Schema.object({
1789
- sub: koishi_1.Schema.array(koishi_1.Schema.object({
1790
- uid: koishi_1.Schema.string().description("订阅用户UID"),
1791
- dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
1792
- live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
1793
- target: koishi_1.Schema.array(koishi_1.Schema.object({
1794
- channelArr: koishi_1.Schema.array(koishi_1.Schema.object({
1795
- channelId: koishi_1.Schema.string().description("频道/群组号"),
1796
- dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
1797
- live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
1798
- liveGuardBuy: koishi_1.Schema.boolean().description("该频道/群组是否推送弹幕消息"),
1799
- atAll: koishi_1.Schema.boolean().description("推送开播通知时是否艾特全体成员"),
1833
+ ComRegister.Config = Schema.object({
1834
+ sub: Schema.array(Schema.object({
1835
+ uid: Schema.string().description("订阅用户UID"),
1836
+ dynamic: Schema.boolean().description("是否订阅用户动态"),
1837
+ live: Schema.boolean().description("是否订阅用户直播"),
1838
+ target: Schema.array(Schema.object({
1839
+ channelArr: Schema.array(Schema.object({
1840
+ channelId: Schema.string().description("频道/群组号"),
1841
+ dynamic: Schema.boolean().description("该频道/群组是否推送动态信息"),
1842
+ live: Schema.boolean().description("该频道/群组是否推送直播通知"),
1843
+ liveGuardBuy: Schema.boolean().description("该频道/群组是否推送弹幕消息"),
1844
+ atAll: Schema.boolean().description("推送开播通知时是否艾特全体成员"),
1845
+ bot: Schema.string().description("若您有多个相同平台机器人,可在此填写当前群聊执行推送的机器人账号。不填则默认第一个"),
1800
1846
  })).description("频道/群组信息"),
1801
- platform: koishi_1.Schema.string().description("推送平台"),
1847
+ platform: Schema.string().description("推送平台"),
1802
1848
  })).description("订阅用户需要发送的频道/群组信息"),
1803
- card: koishi_1.Schema.object({
1804
- enable: koishi_1.Schema.boolean(),
1805
- cardColorStart: koishi_1.Schema.string(),
1806
- cardColorEnd: koishi_1.Schema.string(),
1807
- cardBasePlateColor: koishi_1.Schema.string(),
1808
- cardBasePlateBorder: koishi_1.Schema.string(),
1849
+ card: Schema.object({
1850
+ enable: Schema.boolean(),
1851
+ cardColorStart: Schema.string(),
1852
+ cardColorEnd: Schema.string(),
1853
+ cardBasePlateColor: Schema.string(),
1854
+ cardBasePlateBorder: Schema.string(),
1809
1855
  }).description("自定义推送卡片颜色,默认使用插件内置的颜色,设置后会覆盖插件内置的颜色"),
1810
1856
  }))
1811
1857
  .role("table")
1812
1858
  .description("手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
1813
- master: koishi_1.Schema.object({
1814
- enable: koishi_1.Schema.boolean(),
1815
- platform: koishi_1.Schema.string(),
1816
- masterAccount: koishi_1.Schema.string(),
1817
- masterAccountGuildId: koishi_1.Schema.string(),
1859
+ master: Schema.object({
1860
+ enable: Schema.boolean(),
1861
+ platform: Schema.string(),
1862
+ masterAccount: Schema.string(),
1863
+ masterAccountGuildId: Schema.string(),
1818
1864
  }),
1819
- liveDetectType: koishi_1.Schema.string(),
1820
- restartPush: koishi_1.Schema.boolean().required(),
1821
- pushTime: koishi_1.Schema.number().required(),
1822
- pushImgsInDynamic: koishi_1.Schema.boolean().required(),
1823
- liveLoopTime: koishi_1.Schema.number().default(10),
1824
- customLiveStart: koishi_1.Schema.string().required(),
1825
- customLive: koishi_1.Schema.string(),
1826
- customLiveEnd: koishi_1.Schema.string().required(),
1827
- dynamicUrl: koishi_1.Schema.boolean().required(),
1828
- filter: koishi_1.Schema.object({
1829
- enable: koishi_1.Schema.boolean(),
1830
- notify: koishi_1.Schema.boolean(),
1831
- regex: koishi_1.Schema.string(),
1832
- keywords: koishi_1.Schema.array(String),
1865
+ liveDetectType: Schema.string(),
1866
+ restartPush: Schema.boolean().required(),
1867
+ pushTime: Schema.number().required(),
1868
+ pushImgsInDynamic: Schema.boolean().required(),
1869
+ liveLoopTime: Schema.number().default(10),
1870
+ customLiveStart: Schema.string().required(),
1871
+ customLive: Schema.string(),
1872
+ customLiveEnd: Schema.string().required(),
1873
+ dynamicUrl: Schema.boolean().required(),
1874
+ filter: Schema.object({
1875
+ enable: Schema.boolean(),
1876
+ notify: Schema.boolean(),
1877
+ regex: Schema.string(),
1878
+ keywords: Schema.array(String),
1833
1879
  }),
1834
- dynamicDebugMode: koishi_1.Schema.boolean().required(),
1880
+ dynamicDebugMode: Schema.boolean().required(),
1835
1881
  });
1836
1882
  })(ComRegister || (ComRegister = {}));
1837
- exports.default = ComRegister;
1883
+ export default ComRegister;