koishi-plugin-bilibili-notify 3.3.1-alpha.1 → 3.3.1-rc.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/index.js CHANGED
@@ -64,7 +64,7 @@ const BAConfigSchema = koishi.Schema.object({
64
64
  "satori",
65
65
  "chronocat",
66
66
  "lark"
67
- ]).description("请选择您的私人机器人平台,目前支持QQ、QQ群、OneBot、Discord、RedBot、Telegram、Satori、ChronoCat、Lark。从2.0版本开始,只能在一个平台下使用本插件"),
67
+ ]).description("请选择您的私人机器人平台"),
68
68
  masterAccount: koishi.Schema.string().role("secret").required().description("主人账号,在Q群使用可直接使用QQ号,若在其他平台使用,请使用inspect插件获取自身ID"),
69
69
  masterAccountGuildId: koishi.Schema.string().role("secret").description("主人账号所在的群组ID,只有在QQ频道、Discord这样的环境才需要填写,请使用inspect插件获取群组ID")
70
70
  }), koishi.Schema.object({})])]),
@@ -364,17 +364,18 @@ var ComRegister = class {
364
364
  rebootCount = 0;
365
365
  subNotifier;
366
366
  ctx;
367
- subManager = [];
368
- dynamicTimelineManager = new Map();
369
- liveStatusManager = new Map();
370
- liveMsgManager = new Map();
371
- pushArrMap = new Map();
367
+ subManager;
368
+ dynamicTimelineManager;
369
+ liveStatusManager;
370
+ liveMsgManager;
371
+ pushArrMap;
372
372
  loginDBData;
373
373
  privateBot;
374
374
  dynamicJob;
375
375
  liveJob;
376
376
  _jieba = __node_rs_jieba.Jieba.withDict(__node_rs_jieba_dict.dict);
377
377
  stopwords;
378
+ reciveSubTimes = 0;
378
379
  constructor(ctx, config) {
379
380
  this.ctx = ctx;
380
381
  this.init(config);
@@ -474,16 +475,16 @@ var ComRegister = class {
474
475
  biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
475
476
  const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
476
477
  const subLiveUsers = [];
477
- for (const sub of this.subManager) {
478
+ for (const [uid, sub] of this.subManager) {
478
479
  let onLive = false;
479
480
  if (live_users.items) {
480
- for (const user of live_users.items) if (user.mid.toString() === sub.uid && sub.live) {
481
+ for (const user of live_users.items) if (user.mid.toString() === uid && sub.live) {
481
482
  onLive = true;
482
483
  break;
483
484
  }
484
485
  }
485
486
  subLiveUsers.push({
486
- uid: Number.parseInt(sub.uid),
487
+ uid: Number.parseInt(uid),
487
488
  uname: sub.uname,
488
489
  onLive
489
490
  });
@@ -612,7 +613,7 @@ var ComRegister = class {
612
613
  ["初中", 4],
613
614
  ["毕业", 4]
614
615
  ];
615
- await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
616
+ const img = koishi.h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg");
616
617
  const top5DanmakuMaker = [
617
618
  ["张三", 60],
618
619
  ["李四", 48],
@@ -620,8 +621,8 @@ var ComRegister = class {
620
621
  ["赵六", 27],
621
622
  ["田七", 25]
622
623
  ];
623
- const danmakerRankMsg = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
624
- await session.send(danmakerRankMsg);
624
+ const summary = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
625
+ await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [img, summary] }));
625
626
  });
626
627
  biliCom.subcommand(".cap").action(async ({ session }) => {
627
628
  const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
@@ -643,7 +644,9 @@ var ComRegister = class {
643
644
  const seccode = `${validate}|jordan`;
644
645
  const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
645
646
  if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
646
- await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
647
+ await this.ctx.sleep(10 * 1e3);
648
+ const { code: validCode, data: validData } = await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
649
+ if (validCode === -352 && validData.v_voucher) return "验证不成功!";
647
650
  await session.send("验证成功!请重启插件");
648
651
  });
649
652
  }
@@ -660,25 +663,30 @@ var ComRegister = class {
660
663
  return;
661
664
  }
662
665
  this.mergeStopWords(config.wordcloudStopWords);
663
- if (config.advancedSub) {
664
- this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
665
- await this.initAsyncPart(subs);
666
- });
667
- this.ctx.emit("bilibili-notify/ready-to-recive");
668
- } else if (config.subs && config.subs.length > 0) {
666
+ this.registeringForEvents();
667
+ if (config.advancedSub) this.ctx.emit("bilibili-notify/ready-to-recive");
668
+ else if (config.subs && config.subs.length > 0) {
669
669
  const subs = this.configSubsToSubscription(config.subs);
670
670
  await this.initAsyncPart(subs);
671
671
  }
672
+ }
673
+ registeringForEvents() {
672
674
  this.ctx.on("dispose", () => {
673
675
  if (this.loginTimer) this.loginTimer();
674
676
  if (this.dynamicJob) this.dynamicJob.stop();
675
677
  if (this.liveJob) this.liveJob.stop();
676
678
  });
679
+ this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
680
+ if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
681
+ else await this.initAsyncPart(subs);
682
+ this.reciveSubTimes++;
683
+ });
677
684
  }
678
685
  async initAsyncPart(subs) {
679
- const { code, msg } = await this.loadSubFromConfig(subs);
686
+ this.initAllManager();
687
+ const { code, message } = await this.loadSubFromConfig(subs);
680
688
  if (code !== 0) {
681
- this.logger.error(msg);
689
+ this.logger.error(message);
682
690
  this.logger.error("订阅对象加载失败,插件初始化失败!");
683
691
  await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
684
692
  return;
@@ -698,9 +706,9 @@ var ComRegister = class {
698
706
  this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
699
707
  }
700
708
  initManager() {
701
- for (const sub of this.subManager) {
702
- if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon.DateTime.now().toSeconds()));
703
- if (sub.live) this.liveStatusManager.set(sub.uid, {
709
+ for (const [uid, sub] of this.subManager) {
710
+ if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(luxon.DateTime.now().toSeconds()));
711
+ if (sub.live) this.liveStatusManager.set(uid, {
704
712
  roomId: sub.roomId,
705
713
  live: false,
706
714
  liveRoomInfo: void 0,
@@ -712,6 +720,13 @@ var ComRegister = class {
712
720
  });
713
721
  }
714
722
  }
723
+ initAllManager() {
724
+ this.subManager = new Map();
725
+ this.dynamicTimelineManager = new Map();
726
+ this.liveStatusManager = new Map();
727
+ this.liveMsgManager = new Map();
728
+ this.pushArrMap = new Map();
729
+ }
715
730
  configSubsToSubscription(sub) {
716
731
  const subs = {};
717
732
  sub.forEach((s) => {
@@ -958,21 +973,21 @@ var ComRegister = class {
958
973
  if (this.dynamicTimelineManager.has(uid)) {
959
974
  const timeline = this.dynamicTimelineManager.get(uid);
960
975
  if (timeline < postTime) {
961
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
976
+ const sub = this.subManager.get(uid);
962
977
  const buffer = await withRetry(async () => {
963
978
  return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
964
979
  }, 1).catch(async (e) => {
965
980
  if (e.message === "直播开播动态,不做处理") return;
966
981
  if (e.message === "出现关键词,屏蔽该动态") {
967
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
982
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
968
983
  return;
969
984
  }
970
985
  if (e.message === "已屏蔽转发动态") {
971
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
986
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
972
987
  return;
973
988
  }
974
989
  if (e.message === "已屏蔽专栏动态") {
975
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
990
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
976
991
  return;
977
992
  }
978
993
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
@@ -986,7 +1001,7 @@ var ComRegister = class {
986
1001
  } else dUrl = `${name$2}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
987
1002
  else dUrl = `${name$2}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
988
1003
  this.logger.info("推送动态中...");
989
- await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1004
+ await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
990
1005
  if (this.config.pushImgsInDynamic) {
991
1006
  if (item.type === "DYNAMIC_TYPE_DRAW") {
992
1007
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -998,7 +1013,7 @@ var ComRegister = class {
998
1013
  alt: "动态图片"
999
1014
  }, pic.url))
1000
1015
  });
1001
- await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1016
+ await this.broadcastToTargets(uid, picsMsg, PushType.Dynamic);
1002
1017
  }
1003
1018
  }
1004
1019
  }
@@ -1062,22 +1077,22 @@ var ComRegister = class {
1062
1077
  this.logger.info(`上次推送时间线:${luxon.DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
1063
1078
  if (timeline < postTime) {
1064
1079
  this.logger.info("需要推送该条动态,开始推送...");
1065
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1080
+ const sub = this.subManager.get(uid);
1066
1081
  this.logger.info("开始渲染推送卡片...");
1067
1082
  const buffer = await withRetry(async () => {
1068
1083
  return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
1069
1084
  }, 1).catch(async (e) => {
1070
1085
  if (e.message === "直播开播动态,不做处理") return;
1071
1086
  if (e.message === "出现关键词,屏蔽该动态") {
1072
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
1087
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
1073
1088
  return;
1074
1089
  }
1075
1090
  if (e.message === "已屏蔽转发动态") {
1076
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
1091
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
1077
1092
  return;
1078
1093
  }
1079
1094
  if (e.message === "已屏蔽专栏动态") {
1080
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
1095
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
1081
1096
  return;
1082
1097
  }
1083
1098
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
@@ -1096,7 +1111,7 @@ var ComRegister = class {
1096
1111
  this.logger.info("动态链接生成成功!");
1097
1112
  }
1098
1113
  this.logger.info("推送动态中...");
1099
- await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1114
+ await this.broadcastToTargets(uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1100
1115
  if (this.config.pushImgsInDynamic) {
1101
1116
  this.logger.info("需要发送动态中的图片,开始发送...");
1102
1117
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1109,7 +1124,7 @@ var ComRegister = class {
1109
1124
  alt: "动态图片"
1110
1125
  }, pic.url))
1111
1126
  });
1112
- await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1127
+ await this.broadcastToTargets(uid, picsMsg, PushType.Dynamic);
1113
1128
  }
1114
1129
  }
1115
1130
  this.logger.info("动态中的图片发送完毕!");
@@ -1198,13 +1213,12 @@ var ComRegister = class {
1198
1213
  this.logger.info(top90Words);
1199
1214
  this.logger.info("正在准备生成弹幕词云");
1200
1215
  const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1201
- const img = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(buffer, "image/jpeg") });
1216
+ const img = koishi.h.image(buffer, "image/jpeg");
1202
1217
  this.logger.info("开始构建弹幕发送排行榜消息");
1203
1218
  const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1204
1219
  const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1205
1220
  const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1206
- const danmakuMakerMsg = customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1207
- const summary = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: danmakuMakerMsg });
1221
+ const summary = customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1208
1222
  await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
1209
1223
  Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
1210
1224
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
@@ -1366,7 +1380,7 @@ var ComRegister = class {
1366
1380
  const uid = item.uid.toString();
1367
1381
  const liveStatus = this.liveStatusManager.get(uid);
1368
1382
  const liveMsgObj = this.liveMsgManager.get(uid);
1369
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1383
+ const sub = this.subManager.get(uid);
1370
1384
  if (item.live_status === 1) {
1371
1385
  liveStatus.live = true;
1372
1386
  await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, liveStatus);
@@ -1379,7 +1393,7 @@ var ComRegister = class {
1379
1393
  liveRoomInfo: liveStatus.liveRoomInfo,
1380
1394
  masterInfo: liveStatus.masterInfo,
1381
1395
  cardStyle: sub.customCardStyle
1382
- }, sub.uid, liveMsg);
1396
+ }, uid, liveMsg);
1383
1397
  }
1384
1398
  }
1385
1399
  const handler = async () => {
@@ -1388,7 +1402,7 @@ var ComRegister = class {
1388
1402
  const uid = item.uid.toString();
1389
1403
  const liveStatus = this.liveStatusManager.get(uid);
1390
1404
  const liveMsgObj = this.liveMsgManager.get(uid);
1391
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1405
+ const sub = this.subManager.get(uid);
1392
1406
  if (!sub) return;
1393
1407
  switch (item.live_status) {
1394
1408
  case 0:
@@ -1412,7 +1426,7 @@ var ComRegister = class {
1412
1426
  liveRoomInfo: liveStatus.liveRoomInfo,
1413
1427
  masterInfo: liveStatus.masterInfo,
1414
1428
  cardStyle: sub.customCardStyle
1415
- }, sub.uid, liveEndMsg);
1429
+ }, uid, liveEndMsg);
1416
1430
  liveStatus.live = false;
1417
1431
  }
1418
1432
  break;
@@ -1431,7 +1445,7 @@ var ComRegister = class {
1431
1445
  liveRoomInfo: liveStatus.liveRoomInfo,
1432
1446
  masterInfo: liveStatus.masterInfo,
1433
1447
  cardStyle: sub.customCardStyle
1434
- }, sub.uid, liveStartMsg);
1448
+ }, uid, liveStartMsg);
1435
1449
  liveStatus.live = true;
1436
1450
  }
1437
1451
  if (liveStatus.live === true) {
@@ -1452,7 +1466,7 @@ var ComRegister = class {
1452
1466
  liveRoomInfo: liveStatus.liveRoomInfo,
1453
1467
  masterInfo: liveStatus.masterInfo,
1454
1468
  cardStyle: sub.customCardStyle
1455
- }, sub.uid, liveMsg);
1469
+ }, uid, liveMsg);
1456
1470
  liveStatus.push = 0;
1457
1471
  }
1458
1472
  break;
@@ -1465,7 +1479,7 @@ var ComRegister = class {
1465
1479
  }
1466
1480
  subShow() {
1467
1481
  let table = "";
1468
- for (const sub of this.subManager) table += `UID:${sub.uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1482
+ for (const [uid, sub] of this.subManager) table += `UID:${uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1469
1483
  return table ? table : "没有订阅任何UP";
1470
1484
  }
1471
1485
  updateSubNotifier() {
@@ -1500,22 +1514,22 @@ var ComRegister = class {
1500
1514
  this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
1501
1515
  return {
1502
1516
  code: 0,
1503
- msg: "分组已存在"
1517
+ message: "分组已存在"
1504
1518
  };
1505
1519
  }
1506
1520
  } else if (createGroupData.code !== 0) return {
1507
1521
  code: createGroupData.code,
1508
- msg: createGroupData.message
1522
+ message: createGroupData.message
1509
1523
  };
1510
1524
  this.ctx.database.set("loginBili", 1, { dynamic_group_id: createGroupData.data.tagid.toString() });
1511
1525
  return {
1512
1526
  code: createGroupData.code,
1513
- msg: createGroupData.message
1527
+ message: createGroupData.message
1514
1528
  };
1515
1529
  }
1516
1530
  return {
1517
1531
  code: 0,
1518
- msg: "分组已存在"
1532
+ message: "分组已存在"
1519
1533
  };
1520
1534
  };
1521
1535
  const resp = await checkGroupIsReady();
@@ -1531,93 +1545,105 @@ var ComRegister = class {
1531
1545
  }
1532
1546
  return {
1533
1547
  code: relationGroupDetailData.code,
1534
- msg: relationGroupDetailData.message,
1548
+ message: relationGroupDetailData.message,
1535
1549
  data: void 0
1536
1550
  };
1537
1551
  }
1538
1552
  return {
1539
1553
  code: 0,
1540
- msg: "获取分组明细成功",
1554
+ message: "获取分组明细成功",
1541
1555
  data: relationGroupDetailData.data
1542
1556
  };
1543
1557
  };
1544
- const { code, msg, data } = await getGroupDetailData();
1558
+ const { code, message, data } = await getGroupDetailData();
1545
1559
  if (code !== 0) return {
1546
1560
  code,
1547
- msg
1561
+ message
1548
1562
  };
1549
1563
  for (const user of data) if (user.mid === mid) return {
1550
1564
  code: 0,
1551
- msg: "订阅对象已存在于分组中"
1565
+ message: "订阅对象已存在于分组中"
1552
1566
  };
1553
1567
  const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
1554
1568
  const subUserMatchPattern = {
1555
1569
  [-101]: () => {
1556
1570
  return {
1557
1571
  code: subUserData.code,
1558
- msg: "账号未登录,请使用指令bili login登录后再进行订阅操作"
1572
+ message: "账号未登录,请使用指令bili login登录后再进行订阅操作"
1559
1573
  };
1560
1574
  },
1561
1575
  [-102]: () => {
1562
1576
  return {
1563
1577
  code: subUserData.code,
1564
- msg: "账号被封停,无法进行订阅操作"
1578
+ message: "账号被封停,无法进行订阅操作"
1565
1579
  };
1566
1580
  },
1567
1581
  22002: () => {
1568
1582
  return {
1569
1583
  code: subUserData.code,
1570
- msg: "因对方隐私设置,无法进行订阅操作"
1584
+ message: "因对方隐私设置,无法进行订阅操作"
1571
1585
  };
1572
1586
  },
1573
1587
  22003: () => {
1574
1588
  return {
1575
1589
  code: subUserData.code,
1576
- msg: "你已将对方拉黑,无法进行订阅操作"
1590
+ message: "你已将对方拉黑,无法进行订阅操作"
1577
1591
  };
1578
1592
  },
1579
1593
  22013: () => {
1580
1594
  return {
1581
1595
  code: subUserData.code,
1582
- msg: "账号已注销,无法进行订阅操作"
1596
+ message: "账号已注销,无法进行订阅操作"
1583
1597
  };
1584
1598
  },
1585
1599
  40061: () => {
1586
1600
  return {
1587
1601
  code: subUserData.code,
1588
- msg: "账号不存在,请检查uid输入是否正确或用户是否存在"
1602
+ message: "账号不存在,请检查uid输入是否正确或用户是否存在"
1589
1603
  };
1590
1604
  },
1591
1605
  22001: () => {
1592
1606
  return {
1593
1607
  code: 0,
1594
- msg: "订阅对象为自己,无需添加到分组"
1608
+ message: "订阅对象为自己,无需添加到分组"
1595
1609
  };
1596
1610
  },
1597
1611
  22014: async () => {
1598
1612
  const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1599
1613
  if (copyUserToGroupData.code !== 0) return {
1600
1614
  code: copyUserToGroupData.code,
1601
- msg: "添加订阅对象到分组失败,请稍后重试"
1615
+ message: "添加订阅对象到分组失败,请稍后重试"
1602
1616
  };
1603
1617
  return {
1604
1618
  code: 0,
1605
- msg: "订阅对象添加成功"
1619
+ message: "订阅对象添加成功"
1620
+ };
1621
+ },
1622
+ 22015: async () => {
1623
+ return {
1624
+ code: subUserData.code,
1625
+ message: subUserData.message
1606
1626
  };
1607
1627
  },
1608
1628
  0: async () => {
1609
1629
  const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1610
1630
  if (copyUserToGroupData.code !== 0) return {
1611
1631
  code: copyUserToGroupData.code,
1612
- msg: "添加订阅对象到分组失败,请稍后重试"
1632
+ message: "添加订阅对象到分组失败,请稍后重试"
1613
1633
  };
1614
1634
  return {
1615
1635
  code: 0,
1616
- msg: "订阅对象添加成功"
1636
+ message: "订阅对象添加成功"
1617
1637
  };
1618
1638
  }
1619
1639
  };
1620
- return await subUserMatchPattern[subUserData.code]();
1640
+ const subUserExecute = subUserMatchPattern[subUserData.code] || (() => {
1641
+ return {
1642
+ code: subUserData.code,
1643
+ message: subUserData.message
1644
+ };
1645
+ });
1646
+ return await subUserExecute();
1621
1647
  }
1622
1648
  async loadSubFromConfig(subs) {
1623
1649
  this.preInitConfig(subs);
@@ -1625,11 +1651,8 @@ var ComRegister = class {
1625
1651
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1626
1652
  const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1627
1653
  const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1628
- return {
1629
- code: 0,
1630
- data
1631
- };
1632
- }).then((content) => content.data).catch((e) => {
1654
+ return data;
1655
+ }).catch((e) => {
1633
1656
  this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1634
1657
  return {
1635
1658
  code: -1,
@@ -1641,12 +1664,12 @@ var ComRegister = class {
1641
1664
  await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1642
1665
  return {
1643
1666
  code: userInfoCode,
1644
- msg: userInfoMsg
1667
+ message: userInfoMsg
1645
1668
  };
1646
1669
  }
1647
1670
  if (userInfoCode !== 0) return {
1648
1671
  code: userInfoCode,
1649
- msg: userInfoMsg
1672
+ message: userInfoMsg
1650
1673
  };
1651
1674
  if (this.config.liveDetectType === "WS" && sub.live) {
1652
1675
  if (!userInfoData.live_room) {
@@ -1657,8 +1680,7 @@ var ComRegister = class {
1657
1680
  }
1658
1681
  const subInfo = await this.subUserInBili(sub.uid);
1659
1682
  if (subInfo.code !== 0) return subInfo;
1660
- this.subManager.push({
1661
- uid: sub.uid,
1683
+ this.subManager.set(sub.uid, {
1662
1684
  uname: userInfoData.name,
1663
1685
  roomId: sub.live ? userInfoData.live_room.roomid : "",
1664
1686
  target: sub.target,
@@ -1677,7 +1699,7 @@ var ComRegister = class {
1677
1699
  }
1678
1700
  return {
1679
1701
  code: 0,
1680
- msg: "订阅加载完毕!"
1702
+ message: "订阅加载完毕!"
1681
1703
  };
1682
1704
  }
1683
1705
  checkIfDynamicDetectIsNeeded() {
package/lib/index.mjs CHANGED
@@ -45,7 +45,7 @@ const BAConfigSchema = Schema.object({
45
45
  "satori",
46
46
  "chronocat",
47
47
  "lark"
48
- ]).description("请选择您的私人机器人平台,目前支持QQ、QQ群、OneBot、Discord、RedBot、Telegram、Satori、ChronoCat、Lark。从2.0版本开始,只能在一个平台下使用本插件"),
48
+ ]).description("请选择您的私人机器人平台"),
49
49
  masterAccount: Schema.string().role("secret").required().description("主人账号,在Q群使用可直接使用QQ号,若在其他平台使用,请使用inspect插件获取自身ID"),
50
50
  masterAccountGuildId: Schema.string().role("secret").description("主人账号所在的群组ID,只有在QQ频道、Discord这样的环境才需要填写,请使用inspect插件获取群组ID")
51
51
  }), Schema.object({})])]),
@@ -345,17 +345,18 @@ var ComRegister = class {
345
345
  rebootCount = 0;
346
346
  subNotifier;
347
347
  ctx;
348
- subManager = [];
349
- dynamicTimelineManager = new Map();
350
- liveStatusManager = new Map();
351
- liveMsgManager = new Map();
352
- pushArrMap = new Map();
348
+ subManager;
349
+ dynamicTimelineManager;
350
+ liveStatusManager;
351
+ liveMsgManager;
352
+ pushArrMap;
353
353
  loginDBData;
354
354
  privateBot;
355
355
  dynamicJob;
356
356
  liveJob;
357
357
  _jieba = Jieba.withDict(dict);
358
358
  stopwords;
359
+ reciveSubTimes = 0;
359
360
  constructor(ctx, config) {
360
361
  this.ctx = ctx;
361
362
  this.init(config);
@@ -455,16 +456,16 @@ var ComRegister = class {
455
456
  biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
456
457
  const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
457
458
  const subLiveUsers = [];
458
- for (const sub of this.subManager) {
459
+ for (const [uid, sub] of this.subManager) {
459
460
  let onLive = false;
460
461
  if (live_users.items) {
461
- for (const user of live_users.items) if (user.mid.toString() === sub.uid && sub.live) {
462
+ for (const user of live_users.items) if (user.mid.toString() === uid && sub.live) {
462
463
  onLive = true;
463
464
  break;
464
465
  }
465
466
  }
466
467
  subLiveUsers.push({
467
- uid: Number.parseInt(sub.uid),
468
+ uid: Number.parseInt(uid),
468
469
  uname: sub.uname,
469
470
  onLive
470
471
  });
@@ -593,7 +594,7 @@ var ComRegister = class {
593
594
  ["初中", 4],
594
595
  ["毕业", 4]
595
596
  ];
596
- await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
597
+ const img = h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg");
597
598
  const top5DanmakuMaker = [
598
599
  ["张三", 60],
599
600
  ["李四", 48],
@@ -601,8 +602,8 @@ var ComRegister = class {
601
602
  ["赵六", 27],
602
603
  ["田七", 25]
603
604
  ];
604
- const danmakerRankMsg = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
605
- await session.send(danmakerRankMsg);
605
+ const summary = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
606
+ await session.send(/* @__PURE__ */ jsxs("message", { children: [img, summary] }));
606
607
  });
607
608
  biliCom.subcommand(".cap").action(async ({ session }) => {
608
609
  const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
@@ -624,7 +625,9 @@ var ComRegister = class {
624
625
  const seccode = `${validate}|jordan`;
625
626
  const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
626
627
  if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
627
- await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
628
+ await this.ctx.sleep(10 * 1e3);
629
+ const { code: validCode, data: validData } = await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
630
+ if (validCode === -352 && validData.v_voucher) return "验证不成功!";
628
631
  await session.send("验证成功!请重启插件");
629
632
  });
630
633
  }
@@ -641,25 +644,30 @@ var ComRegister = class {
641
644
  return;
642
645
  }
643
646
  this.mergeStopWords(config.wordcloudStopWords);
644
- if (config.advancedSub) {
645
- this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
646
- await this.initAsyncPart(subs);
647
- });
648
- this.ctx.emit("bilibili-notify/ready-to-recive");
649
- } else if (config.subs && config.subs.length > 0) {
647
+ this.registeringForEvents();
648
+ if (config.advancedSub) this.ctx.emit("bilibili-notify/ready-to-recive");
649
+ else if (config.subs && config.subs.length > 0) {
650
650
  const subs = this.configSubsToSubscription(config.subs);
651
651
  await this.initAsyncPart(subs);
652
652
  }
653
+ }
654
+ registeringForEvents() {
653
655
  this.ctx.on("dispose", () => {
654
656
  if (this.loginTimer) this.loginTimer();
655
657
  if (this.dynamicJob) this.dynamicJob.stop();
656
658
  if (this.liveJob) this.liveJob.stop();
657
659
  });
660
+ this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
661
+ if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
662
+ else await this.initAsyncPart(subs);
663
+ this.reciveSubTimes++;
664
+ });
658
665
  }
659
666
  async initAsyncPart(subs) {
660
- const { code, msg } = await this.loadSubFromConfig(subs);
667
+ this.initAllManager();
668
+ const { code, message } = await this.loadSubFromConfig(subs);
661
669
  if (code !== 0) {
662
- this.logger.error(msg);
670
+ this.logger.error(message);
663
671
  this.logger.error("订阅对象加载失败,插件初始化失败!");
664
672
  await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
665
673
  return;
@@ -679,9 +687,9 @@ var ComRegister = class {
679
687
  this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
680
688
  }
681
689
  initManager() {
682
- for (const sub of this.subManager) {
683
- if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(DateTime.now().toSeconds()));
684
- if (sub.live) this.liveStatusManager.set(sub.uid, {
690
+ for (const [uid, sub] of this.subManager) {
691
+ if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(DateTime.now().toSeconds()));
692
+ if (sub.live) this.liveStatusManager.set(uid, {
685
693
  roomId: sub.roomId,
686
694
  live: false,
687
695
  liveRoomInfo: void 0,
@@ -693,6 +701,13 @@ var ComRegister = class {
693
701
  });
694
702
  }
695
703
  }
704
+ initAllManager() {
705
+ this.subManager = new Map();
706
+ this.dynamicTimelineManager = new Map();
707
+ this.liveStatusManager = new Map();
708
+ this.liveMsgManager = new Map();
709
+ this.pushArrMap = new Map();
710
+ }
696
711
  configSubsToSubscription(sub) {
697
712
  const subs = {};
698
713
  sub.forEach((s) => {
@@ -939,21 +954,21 @@ var ComRegister = class {
939
954
  if (this.dynamicTimelineManager.has(uid)) {
940
955
  const timeline = this.dynamicTimelineManager.get(uid);
941
956
  if (timeline < postTime) {
942
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
957
+ const sub = this.subManager.get(uid);
943
958
  const buffer = await withRetry(async () => {
944
959
  return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
945
960
  }, 1).catch(async (e) => {
946
961
  if (e.message === "直播开播动态,不做处理") return;
947
962
  if (e.message === "出现关键词,屏蔽该动态") {
948
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
963
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
949
964
  return;
950
965
  }
951
966
  if (e.message === "已屏蔽转发动态") {
952
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
967
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
953
968
  return;
954
969
  }
955
970
  if (e.message === "已屏蔽专栏动态") {
956
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
971
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
957
972
  return;
958
973
  }
959
974
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
@@ -967,7 +982,7 @@ var ComRegister = class {
967
982
  } else dUrl = `${name$2}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
968
983
  else dUrl = `${name$2}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
969
984
  this.logger.info("推送动态中...");
970
- await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
985
+ await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
971
986
  if (this.config.pushImgsInDynamic) {
972
987
  if (item.type === "DYNAMIC_TYPE_DRAW") {
973
988
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -979,7 +994,7 @@ var ComRegister = class {
979
994
  alt: "动态图片"
980
995
  }, pic.url))
981
996
  });
982
- await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
997
+ await this.broadcastToTargets(uid, picsMsg, PushType.Dynamic);
983
998
  }
984
999
  }
985
1000
  }
@@ -1043,22 +1058,22 @@ var ComRegister = class {
1043
1058
  this.logger.info(`上次推送时间线:${DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
1044
1059
  if (timeline < postTime) {
1045
1060
  this.logger.info("需要推送该条动态,开始推送...");
1046
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1061
+ const sub = this.subManager.get(uid);
1047
1062
  this.logger.info("开始渲染推送卡片...");
1048
1063
  const buffer = await withRetry(async () => {
1049
1064
  return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
1050
1065
  }, 1).catch(async (e) => {
1051
1066
  if (e.message === "直播开播动态,不做处理") return;
1052
1067
  if (e.message === "出现关键词,屏蔽该动态") {
1053
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
1068
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "发布了一条含有屏蔽关键字的动态"] }), PushType.Dynamic);
1054
1069
  return;
1055
1070
  }
1056
1071
  if (e.message === "已屏蔽转发动态") {
1057
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
1072
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "转发了一条动态,已屏蔽"] }), PushType.Dynamic);
1058
1073
  return;
1059
1074
  }
1060
1075
  if (e.message === "已屏蔽专栏动态") {
1061
- if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
1076
+ if (this.config.filter.notify) await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [name$2, "投稿了一条专栏,已屏蔽"] }), PushType.Dynamic);
1062
1077
  return;
1063
1078
  }
1064
1079
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
@@ -1077,7 +1092,7 @@ var ComRegister = class {
1077
1092
  this.logger.info("动态链接生成成功!");
1078
1093
  }
1079
1094
  this.logger.info("推送动态中...");
1080
- await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs("message", { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1095
+ await this.broadcastToTargets(uid, /* @__PURE__ */ jsxs("message", { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1081
1096
  if (this.config.pushImgsInDynamic) {
1082
1097
  this.logger.info("需要发送动态中的图片,开始发送...");
1083
1098
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1090,7 +1105,7 @@ var ComRegister = class {
1090
1105
  alt: "动态图片"
1091
1106
  }, pic.url))
1092
1107
  });
1093
- await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1108
+ await this.broadcastToTargets(uid, picsMsg, PushType.Dynamic);
1094
1109
  }
1095
1110
  }
1096
1111
  this.logger.info("动态中的图片发送完毕!");
@@ -1179,13 +1194,12 @@ var ComRegister = class {
1179
1194
  this.logger.info(top90Words);
1180
1195
  this.logger.info("正在准备生成弹幕词云");
1181
1196
  const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1182
- const img = /* @__PURE__ */ jsx("message", { children: h.image(buffer, "image/jpeg") });
1197
+ const img = h.image(buffer, "image/jpeg");
1183
1198
  this.logger.info("开始构建弹幕发送排行榜消息");
1184
1199
  const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1185
1200
  const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1186
1201
  const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1187
- const danmakuMakerMsg = customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1188
- const summary = /* @__PURE__ */ jsx("message", { children: danmakuMakerMsg });
1202
+ const summary = customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1189
1203
  await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
1190
1204
  Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
1191
1205
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
@@ -1347,7 +1361,7 @@ var ComRegister = class {
1347
1361
  const uid = item.uid.toString();
1348
1362
  const liveStatus = this.liveStatusManager.get(uid);
1349
1363
  const liveMsgObj = this.liveMsgManager.get(uid);
1350
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1364
+ const sub = this.subManager.get(uid);
1351
1365
  if (item.live_status === 1) {
1352
1366
  liveStatus.live = true;
1353
1367
  await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, liveStatus);
@@ -1360,7 +1374,7 @@ var ComRegister = class {
1360
1374
  liveRoomInfo: liveStatus.liveRoomInfo,
1361
1375
  masterInfo: liveStatus.masterInfo,
1362
1376
  cardStyle: sub.customCardStyle
1363
- }, sub.uid, liveMsg);
1377
+ }, uid, liveMsg);
1364
1378
  }
1365
1379
  }
1366
1380
  const handler = async () => {
@@ -1369,7 +1383,7 @@ var ComRegister = class {
1369
1383
  const uid = item.uid.toString();
1370
1384
  const liveStatus = this.liveStatusManager.get(uid);
1371
1385
  const liveMsgObj = this.liveMsgManager.get(uid);
1372
- const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1386
+ const sub = this.subManager.get(uid);
1373
1387
  if (!sub) return;
1374
1388
  switch (item.live_status) {
1375
1389
  case 0:
@@ -1393,7 +1407,7 @@ var ComRegister = class {
1393
1407
  liveRoomInfo: liveStatus.liveRoomInfo,
1394
1408
  masterInfo: liveStatus.masterInfo,
1395
1409
  cardStyle: sub.customCardStyle
1396
- }, sub.uid, liveEndMsg);
1410
+ }, uid, liveEndMsg);
1397
1411
  liveStatus.live = false;
1398
1412
  }
1399
1413
  break;
@@ -1412,7 +1426,7 @@ var ComRegister = class {
1412
1426
  liveRoomInfo: liveStatus.liveRoomInfo,
1413
1427
  masterInfo: liveStatus.masterInfo,
1414
1428
  cardStyle: sub.customCardStyle
1415
- }, sub.uid, liveStartMsg);
1429
+ }, uid, liveStartMsg);
1416
1430
  liveStatus.live = true;
1417
1431
  }
1418
1432
  if (liveStatus.live === true) {
@@ -1433,7 +1447,7 @@ var ComRegister = class {
1433
1447
  liveRoomInfo: liveStatus.liveRoomInfo,
1434
1448
  masterInfo: liveStatus.masterInfo,
1435
1449
  cardStyle: sub.customCardStyle
1436
- }, sub.uid, liveMsg);
1450
+ }, uid, liveMsg);
1437
1451
  liveStatus.push = 0;
1438
1452
  }
1439
1453
  break;
@@ -1446,7 +1460,7 @@ var ComRegister = class {
1446
1460
  }
1447
1461
  subShow() {
1448
1462
  let table = "";
1449
- for (const sub of this.subManager) table += `UID:${sub.uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1463
+ for (const [uid, sub] of this.subManager) table += `UID:${uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1450
1464
  return table ? table : "没有订阅任何UP";
1451
1465
  }
1452
1466
  updateSubNotifier() {
@@ -1481,22 +1495,22 @@ var ComRegister = class {
1481
1495
  this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
1482
1496
  return {
1483
1497
  code: 0,
1484
- msg: "分组已存在"
1498
+ message: "分组已存在"
1485
1499
  };
1486
1500
  }
1487
1501
  } else if (createGroupData.code !== 0) return {
1488
1502
  code: createGroupData.code,
1489
- msg: createGroupData.message
1503
+ message: createGroupData.message
1490
1504
  };
1491
1505
  this.ctx.database.set("loginBili", 1, { dynamic_group_id: createGroupData.data.tagid.toString() });
1492
1506
  return {
1493
1507
  code: createGroupData.code,
1494
- msg: createGroupData.message
1508
+ message: createGroupData.message
1495
1509
  };
1496
1510
  }
1497
1511
  return {
1498
1512
  code: 0,
1499
- msg: "分组已存在"
1513
+ message: "分组已存在"
1500
1514
  };
1501
1515
  };
1502
1516
  const resp = await checkGroupIsReady();
@@ -1512,93 +1526,105 @@ var ComRegister = class {
1512
1526
  }
1513
1527
  return {
1514
1528
  code: relationGroupDetailData.code,
1515
- msg: relationGroupDetailData.message,
1529
+ message: relationGroupDetailData.message,
1516
1530
  data: void 0
1517
1531
  };
1518
1532
  }
1519
1533
  return {
1520
1534
  code: 0,
1521
- msg: "获取分组明细成功",
1535
+ message: "获取分组明细成功",
1522
1536
  data: relationGroupDetailData.data
1523
1537
  };
1524
1538
  };
1525
- const { code, msg, data } = await getGroupDetailData();
1539
+ const { code, message, data } = await getGroupDetailData();
1526
1540
  if (code !== 0) return {
1527
1541
  code,
1528
- msg
1542
+ message
1529
1543
  };
1530
1544
  for (const user of data) if (user.mid === mid) return {
1531
1545
  code: 0,
1532
- msg: "订阅对象已存在于分组中"
1546
+ message: "订阅对象已存在于分组中"
1533
1547
  };
1534
1548
  const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
1535
1549
  const subUserMatchPattern = {
1536
1550
  [-101]: () => {
1537
1551
  return {
1538
1552
  code: subUserData.code,
1539
- msg: "账号未登录,请使用指令bili login登录后再进行订阅操作"
1553
+ message: "账号未登录,请使用指令bili login登录后再进行订阅操作"
1540
1554
  };
1541
1555
  },
1542
1556
  [-102]: () => {
1543
1557
  return {
1544
1558
  code: subUserData.code,
1545
- msg: "账号被封停,无法进行订阅操作"
1559
+ message: "账号被封停,无法进行订阅操作"
1546
1560
  };
1547
1561
  },
1548
1562
  22002: () => {
1549
1563
  return {
1550
1564
  code: subUserData.code,
1551
- msg: "因对方隐私设置,无法进行订阅操作"
1565
+ message: "因对方隐私设置,无法进行订阅操作"
1552
1566
  };
1553
1567
  },
1554
1568
  22003: () => {
1555
1569
  return {
1556
1570
  code: subUserData.code,
1557
- msg: "你已将对方拉黑,无法进行订阅操作"
1571
+ message: "你已将对方拉黑,无法进行订阅操作"
1558
1572
  };
1559
1573
  },
1560
1574
  22013: () => {
1561
1575
  return {
1562
1576
  code: subUserData.code,
1563
- msg: "账号已注销,无法进行订阅操作"
1577
+ message: "账号已注销,无法进行订阅操作"
1564
1578
  };
1565
1579
  },
1566
1580
  40061: () => {
1567
1581
  return {
1568
1582
  code: subUserData.code,
1569
- msg: "账号不存在,请检查uid输入是否正确或用户是否存在"
1583
+ message: "账号不存在,请检查uid输入是否正确或用户是否存在"
1570
1584
  };
1571
1585
  },
1572
1586
  22001: () => {
1573
1587
  return {
1574
1588
  code: 0,
1575
- msg: "订阅对象为自己,无需添加到分组"
1589
+ message: "订阅对象为自己,无需添加到分组"
1576
1590
  };
1577
1591
  },
1578
1592
  22014: async () => {
1579
1593
  const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1580
1594
  if (copyUserToGroupData.code !== 0) return {
1581
1595
  code: copyUserToGroupData.code,
1582
- msg: "添加订阅对象到分组失败,请稍后重试"
1596
+ message: "添加订阅对象到分组失败,请稍后重试"
1583
1597
  };
1584
1598
  return {
1585
1599
  code: 0,
1586
- msg: "订阅对象添加成功"
1600
+ message: "订阅对象添加成功"
1601
+ };
1602
+ },
1603
+ 22015: async () => {
1604
+ return {
1605
+ code: subUserData.code,
1606
+ message: subUserData.message
1587
1607
  };
1588
1608
  },
1589
1609
  0: async () => {
1590
1610
  const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1591
1611
  if (copyUserToGroupData.code !== 0) return {
1592
1612
  code: copyUserToGroupData.code,
1593
- msg: "添加订阅对象到分组失败,请稍后重试"
1613
+ message: "添加订阅对象到分组失败,请稍后重试"
1594
1614
  };
1595
1615
  return {
1596
1616
  code: 0,
1597
- msg: "订阅对象添加成功"
1617
+ message: "订阅对象添加成功"
1598
1618
  };
1599
1619
  }
1600
1620
  };
1601
- return await subUserMatchPattern[subUserData.code]();
1621
+ const subUserExecute = subUserMatchPattern[subUserData.code] || (() => {
1622
+ return {
1623
+ code: subUserData.code,
1624
+ message: subUserData.message
1625
+ };
1626
+ });
1627
+ return await subUserExecute();
1602
1628
  }
1603
1629
  async loadSubFromConfig(subs) {
1604
1630
  this.preInitConfig(subs);
@@ -1606,11 +1632,8 @@ var ComRegister = class {
1606
1632
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1607
1633
  const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1608
1634
  const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1609
- return {
1610
- code: 0,
1611
- data
1612
- };
1613
- }).then((content) => content.data).catch((e) => {
1635
+ return data;
1636
+ }).catch((e) => {
1614
1637
  this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1615
1638
  return {
1616
1639
  code: -1,
@@ -1622,12 +1645,12 @@ var ComRegister = class {
1622
1645
  await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1623
1646
  return {
1624
1647
  code: userInfoCode,
1625
- msg: userInfoMsg
1648
+ message: userInfoMsg
1626
1649
  };
1627
1650
  }
1628
1651
  if (userInfoCode !== 0) return {
1629
1652
  code: userInfoCode,
1630
- msg: userInfoMsg
1653
+ message: userInfoMsg
1631
1654
  };
1632
1655
  if (this.config.liveDetectType === "WS" && sub.live) {
1633
1656
  if (!userInfoData.live_room) {
@@ -1638,8 +1661,7 @@ var ComRegister = class {
1638
1661
  }
1639
1662
  const subInfo = await this.subUserInBili(sub.uid);
1640
1663
  if (subInfo.code !== 0) return subInfo;
1641
- this.subManager.push({
1642
- uid: sub.uid,
1664
+ this.subManager.set(sub.uid, {
1643
1665
  uname: userInfoData.name,
1644
1666
  roomId: sub.live ? userInfoData.live_room.roomid : "",
1645
1667
  target: sub.target,
@@ -1658,7 +1680,7 @@ var ComRegister = class {
1658
1680
  }
1659
1681
  return {
1660
1682
  code: 0,
1661
- msg: "订阅加载完毕!"
1683
+ message: "订阅加载完毕!"
1662
1684
  };
1663
1685
  }
1664
1686
  checkIfDynamicDetectIsNeeded() {
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.3.1-alpha.1",
4
+ "version": "3.3.1-rc.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -327,6 +327,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
327
327
  > - ver 3.3.0-rc.0 优化:将当前版本的订阅配置移到了新插件:`bilibili-notify-advanced-subscription` ,简化当前版本订阅配置; 新增:配置项 `advancedSub` ,开启后可通过下载插件 `bilibili-notify-advanced-subscription` 配置更自定义化的订阅配置、新增动态@全体成员功能;
328
328
  > - ver 3.3.1-alpha.0 新增:弹幕词云自定义停用词、UP主弹幕词云开关; 优化:`liveSummary` 排版方式更加直观;
329
329
  > - ver 3.3.1-alpha.1 优化:拆分 `wordcloud` 和 `liveSummary`,优化指令 `bili cap` 风控验证;
330
+ > - ver 3.3.1-rc.0 优化:代码结构,部分设置; 修复:启用高级订阅时,多次重载高级订阅插件会产生多个重复订阅;
330
331
 
331
332
  ## 交流群
332
333