koishi-plugin-bilibili-notify 3.2.5-alpha.5 → 3.2.5-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.js +78 -91
  2. package/lib/index.mjs +78 -91
  3. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -517,6 +517,12 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
517
517
  PushType$1[PushType$1["LiveGuardBuy"] = 3] = "LiveGuardBuy";
518
518
  return PushType$1;
519
519
  }({});
520
+ const PushTypeMsg = {
521
+ [PushType.Live]: "直播推送",
522
+ [PushType.Dynamic]: "动态推送",
523
+ [PushType.StartBroadcasting]: "开播推送",
524
+ [PushType.LiveGuardBuy]: "上舰推送"
525
+ };
520
526
 
521
527
  //#endregion
522
528
  //#region src/comRegister.tsx
@@ -546,6 +552,7 @@ var ComRegister = class {
546
552
  subManager = [];
547
553
  dynamicTimelineManager = /* @__PURE__ */ new Map();
548
554
  liveStatusManager = /* @__PURE__ */ new Map();
555
+ pushRecord = {};
549
556
  loginDBData;
550
557
  privateBot;
551
558
  dynamicJob;
@@ -721,6 +728,7 @@ var ComRegister = class {
721
728
  }
722
729
  }
723
730
  this.initManager();
731
+ this.initPushRecord(this.subManager);
724
732
  this.checkIfDynamicDetectIsNeeded();
725
733
  this.checkIfLiveDetectIsNeeded();
726
734
  this.updateSubNotifier();
@@ -789,72 +797,60 @@ var ComRegister = class {
789
797
  await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
790
798
  });
791
799
  }
792
- getGroupsThatMeetCriteria(targets, type) {
793
- const pushArr = [];
794
- if (type === PushType.StartBroadcasting) {
800
+ initPushRecord(subs) {
801
+ const pushRecord = {};
802
+ for (const sub of subs) {
795
803
  const atAllArr = [];
796
- for (const target of targets) for (const channel of target.channelArr) {
797
- if (channel.atAll && channel.dynamic) {
798
- atAllArr.push(`${target.platform}:${channel.channelId}`);
799
- continue;
800
- }
801
- if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
802
- }
803
- return [pushArr, atAllArr];
804
- }
805
- if (type === PushType.Live) {
806
- for (const target of targets) for (const channel of target.channelArr) if (channel.live) pushArr.push(`${target.platform}:${channel.channelId}`);
807
- return [pushArr];
804
+ const dynamicArr = [];
805
+ const liveArr = [];
806
+ const liveGuardBuyArr = [];
807
+ for (const platform of sub.target) for (const channel of platform.channelArr) {
808
+ if (channel.atAll) atAllArr.push(`${platform.platform}:${channel.channelId}`);
809
+ if (channel.dynamic) dynamicArr.push(`${platform.platform}:${channel.channelId}`);
810
+ if (channel.live) liveArr.push(`${platform.platform}:${channel.channelId}`);
811
+ if (channel.liveGuardBuy) liveGuardBuyArr.push(`${platform.platform}:${channel.channelId}`);
812
+ }
813
+ pushRecord[sub.uid] = {
814
+ atAllArr,
815
+ dynamicArr,
816
+ liveArr,
817
+ liveGuardBuyArr
818
+ };
808
819
  }
809
- if (type === PushType.Dynamic) {
810
- for (const target of targets) for (const channel of target.channelArr) if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
811
- return [pushArr];
820
+ this.pushRecord = pushRecord;
821
+ this.logger.info("初始化推送群组/频道信息:");
822
+ this.logger.info(this.pushRecord);
823
+ }
824
+ async broadcastToTargets(uid, content, type) {
825
+ this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
826
+ const record = this.pushRecord[uid];
827
+ this.logger.info("本次推送目标:");
828
+ this.logger.info(record);
829
+ if (type === PushType.StartBroadcasting && record.atAllArr?.length >= 1) {
830
+ const success = await withRetry(async () => {
831
+ return await this.ctx.broadcast(record.atAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }), /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content })] }));
832
+ }, 1);
833
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
812
834
  }
813
- if (type === PushType.LiveGuardBuy) {
814
- for (const target of targets) for (const channel of target.channelArr) if (channel.liveGuardBuy) pushArr.push(`${target.platform}:${channel.channelId}`);
815
- return [pushArr];
835
+ if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
836
+ const success = await withRetry(async () => {
837
+ return await this.ctx.broadcast(record.dynamicArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
838
+ }, 1);
839
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
816
840
  }
817
- }
818
- async broadcastToTargets(targets, content, type) {
819
- if (targets.length !== 1 || targets[0].channelArr.length !== 1) {
820
- const [pushArr, atAllArr] = this.getGroupsThatMeetCriteria(targets, type);
821
- this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
822
- if (type === PushType.StartBroadcasting && atAllArr?.length >= 1) {
823
- await withRetry(async () => {
824
- await this.ctx.broadcast(atAllArr, koishi.h.at("all"));
825
- }, 1);
826
- await withRetry(async () => {
827
- await this.ctx.broadcast(atAllArr, content);
828
- }, 1);
829
- }
830
- if (pushArr?.length >= 1) await withRetry(async () => {
831
- await this.ctx.broadcast(pushArr, content);
841
+ if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
842
+ const success = await withRetry(async () => {
843
+ return await this.ctx.broadcast(record.liveArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
832
844
  }, 1);
833
- return;
845
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
834
846
  }
835
- const targetChannel = targets[0].channelArr[0];
836
- const bot = this.getBot(targets[0].platform, targetChannel.bot);
837
- if (!bot || !bot.isActive) {
838
- this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
839
- this.logger.warn("未找到对应bot实例,本次消息推送取消!");
840
- return;
847
+ if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
848
+ const success = await withRetry(async () => {
849
+ return await this.ctx.broadcast(record.liveGuardBuyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
850
+ }, 1);
851
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
841
852
  }
842
- const pushTypePatternMatching = {
843
- [PushType.Live]: async () => {
844
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
845
- },
846
- [PushType.Dynamic]: async () => {
847
- if (targetChannel.dynamic) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
848
- },
849
- [PushType.StartBroadcasting]: async () => {
850
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
851
- if (targetChannel.atAll) await this.sendMessageWithRetry(bot, targetChannel.channelId, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }));
852
- },
853
- [PushType.LiveGuardBuy]: async () => {
854
- if (targetChannel.liveGuardBuy) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
855
- }
856
- };
857
- await pushTypePatternMatching[type]();
853
+ return;
858
854
  }
859
855
  dynamicDetect() {
860
856
  const handler = async () => {
@@ -904,15 +900,15 @@ var ComRegister = class {
904
900
  }, 1).catch(async (e$1) => {
905
901
  if (e$1.message === "直播开播动态,不做处理") return;
906
902
  if (e$1.message === "出现关键词,屏蔽该动态") {
907
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
903
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
908
904
  return;
909
905
  }
910
906
  if (e$1.message === "已屏蔽转发动态") {
911
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
907
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
912
908
  return;
913
909
  }
914
910
  if (e$1.message === "已屏蔽专栏动态") {
915
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
911
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
916
912
  return;
917
913
  }
918
914
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -926,7 +922,7 @@ var ComRegister = class {
926
922
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
927
923
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
928
924
  this.logger.info("推送动态中...");
929
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
925
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
930
926
  if (this.config.pushImgsInDynamic) {
931
927
  if (item.type === "DYNAMIC_TYPE_DRAW") {
932
928
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -938,7 +934,7 @@ var ComRegister = class {
938
934
  alt: "动态图片"
939
935
  }, pic.url))
940
936
  });
941
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
937
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
942
938
  }
943
939
  }
944
940
  }
@@ -1009,15 +1005,15 @@ var ComRegister = class {
1009
1005
  }, 1).catch(async (e$1) => {
1010
1006
  if (e$1.message === "直播开播动态,不做处理") return;
1011
1007
  if (e$1.message === "出现关键词,屏蔽该动态") {
1012
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1008
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1013
1009
  return;
1014
1010
  }
1015
1011
  if (e$1.message === "已屏蔽转发动态") {
1016
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1012
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1017
1013
  return;
1018
1014
  }
1019
1015
  if (e$1.message === "已屏蔽专栏动态") {
1020
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1016
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1021
1017
  return;
1022
1018
  }
1023
1019
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1036,7 +1032,7 @@ var ComRegister = class {
1036
1032
  this.logger.info("动态链接生成成功!");
1037
1033
  }
1038
1034
  this.logger.info("推送动态中...");
1039
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1035
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1040
1036
  if (this.config.pushImgsInDynamic) {
1041
1037
  this.logger.info("需要发送动态中的图片,开始发送...");
1042
1038
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1049,7 +1045,7 @@ var ComRegister = class {
1049
1045
  alt: "动态图片"
1050
1046
  }, pic.url))
1051
1047
  });
1052
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1048
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1053
1049
  }
1054
1050
  }
1055
1051
  this.logger.info("动态中的图片发送完毕!");
@@ -1101,7 +1097,7 @@ var ComRegister = class {
1101
1097
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1102
1098
  return data$1;
1103
1099
  }
1104
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1100
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1105
1101
  const buffer = await withRetry(async () => {
1106
1102
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1107
1103
  }, 1).catch((e$1) => {
@@ -1109,25 +1105,16 @@ var ComRegister = class {
1109
1105
  });
1110
1106
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1111
1107
  const msg = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] });
1112
- return await this.broadcastToTargets(target, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1108
+ return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1113
1109
  }
1114
- async liveDetectWithListener(roomId, target, cardStyle) {
1110
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1115
1111
  let liveTime;
1116
1112
  let pushAtTimeTimer;
1117
1113
  const currentLiveDanmakuArr = [];
1118
1114
  let liveStatus = false;
1119
- let channelArrLen = 0;
1120
1115
  let liveRoomInfo;
1121
1116
  let masterInfo;
1122
1117
  let watchedNum;
1123
- const liveGuardBuyPushTargetArr = target.map((channel) => {
1124
- const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
1125
- channelArrLen += liveGuardBuyArr.length;
1126
- return {
1127
- channelArr: liveGuardBuyArr,
1128
- platform: channel.platform
1129
- };
1130
- });
1131
1118
  const pushAtTimeFunc = async () => {
1132
1119
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1133
1120
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1146,7 +1133,7 @@ var ComRegister = class {
1146
1133
  liveRoomInfo,
1147
1134
  masterInfo,
1148
1135
  cardStyle
1149
- }, target, liveMsg);
1136
+ }, uid, liveMsg);
1150
1137
  };
1151
1138
  const useMasterAndLiveRoomInfo = async (liveType) => {
1152
1139
  let flag = true;
@@ -1183,7 +1170,7 @@ var ComRegister = class {
1183
1170
  },
1184
1171
  onGuardBuy: ({ body }) => {
1185
1172
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1186
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1173
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1187
1174
  },
1188
1175
  onLiveStart: async () => {
1189
1176
  if (liveStatus) return;
@@ -1200,7 +1187,7 @@ var ComRegister = class {
1200
1187
  liveRoomInfo,
1201
1188
  masterInfo,
1202
1189
  cardStyle
1203
- }, target, liveStartMsg);
1190
+ }, uid, liveStartMsg);
1204
1191
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1205
1192
  },
1206
1193
  onLiveEnd: async () => {
@@ -1220,7 +1207,7 @@ var ComRegister = class {
1220
1207
  liveRoomInfo,
1221
1208
  masterInfo,
1222
1209
  cardStyle
1223
- }, target, liveEndMsg);
1210
+ }, uid, liveEndMsg);
1224
1211
  pushAtTimeTimer();
1225
1212
  pushAtTimeTimer = null;
1226
1213
  }
@@ -1235,7 +1222,7 @@ var ComRegister = class {
1235
1222
  liveRoomInfo,
1236
1223
  masterInfo,
1237
1224
  cardStyle
1238
- }, target, liveMsg);
1225
+ }, uid, liveMsg);
1239
1226
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1240
1227
  liveStatus = true;
1241
1228
  }
@@ -1286,7 +1273,7 @@ var ComRegister = class {
1286
1273
  liveRoomInfo: liveStatus.liveRoomInfo,
1287
1274
  masterInfo: liveStatus.masterInfo,
1288
1275
  cardStyle: sub.card
1289
- }, sub.target, liveMsg);
1276
+ }, sub.uid, liveMsg);
1290
1277
  }
1291
1278
  }
1292
1279
  const handler = async () => {
@@ -1318,7 +1305,7 @@ var ComRegister = class {
1318
1305
  liveRoomInfo: liveStatus.liveRoomInfo,
1319
1306
  masterInfo: liveStatus.masterInfo,
1320
1307
  cardStyle: sub.card
1321
- }, sub.target, liveEndMsg);
1308
+ }, sub.uid, liveEndMsg);
1322
1309
  liveStatus.live = false;
1323
1310
  }
1324
1311
  break;
@@ -1337,7 +1324,7 @@ var ComRegister = class {
1337
1324
  liveRoomInfo: liveStatus.liveRoomInfo,
1338
1325
  masterInfo: liveStatus.masterInfo,
1339
1326
  cardStyle: sub.card
1340
- }, sub.target, liveStartMsg);
1327
+ }, sub.uid, liveStartMsg);
1341
1328
  liveStatus.live = true;
1342
1329
  }
1343
1330
  if (liveStatus.live === true) {
@@ -1358,7 +1345,7 @@ var ComRegister = class {
1358
1345
  liveRoomInfo: liveStatus.liveRoomInfo,
1359
1346
  masterInfo: liveStatus.masterInfo,
1360
1347
  cardStyle: sub.card
1361
- }, sub.target, liveMsg);
1348
+ }, sub.uid, liveMsg);
1362
1349
  liveStatus.push = 0;
1363
1350
  }
1364
1351
  break;
@@ -1550,7 +1537,7 @@ var ComRegister = class {
1550
1537
  sub.live = false;
1551
1538
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1552
1539
  }
1553
- if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.target, sub.card);
1540
+ if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.uid, sub.card);
1554
1541
  }
1555
1542
  const subInfo = await this.subUserInBili(sub.uid);
1556
1543
  if (subInfo.code !== 0) return subInfo;
package/lib/index.mjs CHANGED
@@ -519,6 +519,12 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
519
519
  PushType$1[PushType$1["LiveGuardBuy"] = 3] = "LiveGuardBuy";
520
520
  return PushType$1;
521
521
  }({});
522
+ const PushTypeMsg = {
523
+ [PushType.Live]: "直播推送",
524
+ [PushType.Dynamic]: "动态推送",
525
+ [PushType.StartBroadcasting]: "开播推送",
526
+ [PushType.LiveGuardBuy]: "上舰推送"
527
+ };
522
528
 
523
529
  //#endregion
524
530
  //#region src/comRegister.tsx
@@ -548,6 +554,7 @@ var ComRegister = class {
548
554
  subManager = [];
549
555
  dynamicTimelineManager = /* @__PURE__ */ new Map();
550
556
  liveStatusManager = /* @__PURE__ */ new Map();
557
+ pushRecord = {};
551
558
  loginDBData;
552
559
  privateBot;
553
560
  dynamicJob;
@@ -723,6 +730,7 @@ var ComRegister = class {
723
730
  }
724
731
  }
725
732
  this.initManager();
733
+ this.initPushRecord(this.subManager);
726
734
  this.checkIfDynamicDetectIsNeeded();
727
735
  this.checkIfLiveDetectIsNeeded();
728
736
  this.updateSubNotifier();
@@ -791,72 +799,60 @@ var ComRegister = class {
791
799
  await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
792
800
  });
793
801
  }
794
- getGroupsThatMeetCriteria(targets, type) {
795
- const pushArr = [];
796
- if (type === PushType.StartBroadcasting) {
802
+ initPushRecord(subs) {
803
+ const pushRecord = {};
804
+ for (const sub of subs) {
797
805
  const atAllArr = [];
798
- for (const target of targets) for (const channel of target.channelArr) {
799
- if (channel.atAll && channel.dynamic) {
800
- atAllArr.push(`${target.platform}:${channel.channelId}`);
801
- continue;
802
- }
803
- if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
804
- }
805
- return [pushArr, atAllArr];
806
- }
807
- if (type === PushType.Live) {
808
- for (const target of targets) for (const channel of target.channelArr) if (channel.live) pushArr.push(`${target.platform}:${channel.channelId}`);
809
- return [pushArr];
806
+ const dynamicArr = [];
807
+ const liveArr = [];
808
+ const liveGuardBuyArr = [];
809
+ for (const platform of sub.target) for (const channel of platform.channelArr) {
810
+ if (channel.atAll) atAllArr.push(`${platform.platform}:${channel.channelId}`);
811
+ if (channel.dynamic) dynamicArr.push(`${platform.platform}:${channel.channelId}`);
812
+ if (channel.live) liveArr.push(`${platform.platform}:${channel.channelId}`);
813
+ if (channel.liveGuardBuy) liveGuardBuyArr.push(`${platform.platform}:${channel.channelId}`);
814
+ }
815
+ pushRecord[sub.uid] = {
816
+ atAllArr,
817
+ dynamicArr,
818
+ liveArr,
819
+ liveGuardBuyArr
820
+ };
810
821
  }
811
- if (type === PushType.Dynamic) {
812
- for (const target of targets) for (const channel of target.channelArr) if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
813
- return [pushArr];
822
+ this.pushRecord = pushRecord;
823
+ this.logger.info("初始化推送群组/频道信息:");
824
+ this.logger.info(this.pushRecord);
825
+ }
826
+ async broadcastToTargets(uid, content, type) {
827
+ this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
828
+ const record = this.pushRecord[uid];
829
+ this.logger.info("本次推送目标:");
830
+ this.logger.info(record);
831
+ if (type === PushType.StartBroadcasting && record.atAllArr?.length >= 1) {
832
+ const success = await withRetry(async () => {
833
+ return await this.ctx.broadcast(record.atAllArr, /* @__PURE__ */ jsxs("message", { children: [/* @__PURE__ */ jsx("at", { type: "all" }), /* @__PURE__ */ jsx("message", { children: content })] }));
834
+ }, 1);
835
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
814
836
  }
815
- if (type === PushType.LiveGuardBuy) {
816
- for (const target of targets) for (const channel of target.channelArr) if (channel.liveGuardBuy) pushArr.push(`${target.platform}:${channel.channelId}`);
817
- return [pushArr];
837
+ if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
838
+ const success = await withRetry(async () => {
839
+ return await this.ctx.broadcast(record.dynamicArr, /* @__PURE__ */ jsx("message", { children: content }));
840
+ }, 1);
841
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
818
842
  }
819
- }
820
- async broadcastToTargets(targets, content, type) {
821
- if (targets.length !== 1 || targets[0].channelArr.length !== 1) {
822
- const [pushArr, atAllArr] = this.getGroupsThatMeetCriteria(targets, type);
823
- this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
824
- if (type === PushType.StartBroadcasting && atAllArr?.length >= 1) {
825
- await withRetry(async () => {
826
- await this.ctx.broadcast(atAllArr, h.at("all"));
827
- }, 1);
828
- await withRetry(async () => {
829
- await this.ctx.broadcast(atAllArr, content);
830
- }, 1);
831
- }
832
- if (pushArr?.length >= 1) await withRetry(async () => {
833
- await this.ctx.broadcast(pushArr, content);
843
+ if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
844
+ const success = await withRetry(async () => {
845
+ return await this.ctx.broadcast(record.liveArr, /* @__PURE__ */ jsx("message", { children: content }));
834
846
  }, 1);
835
- return;
847
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
836
848
  }
837
- const targetChannel = targets[0].channelArr[0];
838
- const bot = this.getBot(targets[0].platform, targetChannel.bot);
839
- if (!bot || !bot.isActive) {
840
- this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
841
- this.logger.warn("未找到对应bot实例,本次消息推送取消!");
842
- return;
849
+ if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
850
+ const success = await withRetry(async () => {
851
+ return await this.ctx.broadcast(record.liveGuardBuyArr, /* @__PURE__ */ jsx("message", { children: content }));
852
+ }, 1);
853
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
843
854
  }
844
- const pushTypePatternMatching = {
845
- [PushType.Live]: async () => {
846
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
847
- },
848
- [PushType.Dynamic]: async () => {
849
- if (targetChannel.dynamic) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
850
- },
851
- [PushType.StartBroadcasting]: async () => {
852
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
853
- if (targetChannel.atAll) await this.sendMessageWithRetry(bot, targetChannel.channelId, /* @__PURE__ */ jsx("at", { type: "all" }));
854
- },
855
- [PushType.LiveGuardBuy]: async () => {
856
- if (targetChannel.liveGuardBuy) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
857
- }
858
- };
859
- await pushTypePatternMatching[type]();
855
+ return;
860
856
  }
861
857
  dynamicDetect() {
862
858
  const handler = async () => {
@@ -906,15 +902,15 @@ var ComRegister = class {
906
902
  }, 1).catch(async (e$1) => {
907
903
  if (e$1.message === "直播开播动态,不做处理") return;
908
904
  if (e$1.message === "出现关键词,屏蔽该动态") {
909
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
905
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
910
906
  return;
911
907
  }
912
908
  if (e$1.message === "已屏蔽转发动态") {
913
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
909
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
914
910
  return;
915
911
  }
916
912
  if (e$1.message === "已屏蔽专栏动态") {
917
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
913
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
918
914
  return;
919
915
  }
920
916
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -928,7 +924,7 @@ var ComRegister = class {
928
924
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
929
925
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
930
926
  this.logger.info("推送动态中...");
931
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
927
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
932
928
  if (this.config.pushImgsInDynamic) {
933
929
  if (item.type === "DYNAMIC_TYPE_DRAW") {
934
930
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -940,7 +936,7 @@ var ComRegister = class {
940
936
  alt: "动态图片"
941
937
  }, pic.url))
942
938
  });
943
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
939
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
944
940
  }
945
941
  }
946
942
  }
@@ -1011,15 +1007,15 @@ var ComRegister = class {
1011
1007
  }, 1).catch(async (e$1) => {
1012
1008
  if (e$1.message === "直播开播动态,不做处理") return;
1013
1009
  if (e$1.message === "出现关键词,屏蔽该动态") {
1014
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1010
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1015
1011
  return;
1016
1012
  }
1017
1013
  if (e$1.message === "已屏蔽转发动态") {
1018
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1014
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1019
1015
  return;
1020
1016
  }
1021
1017
  if (e$1.message === "已屏蔽专栏动态") {
1022
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1018
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1023
1019
  return;
1024
1020
  }
1025
1021
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1038,7 +1034,7 @@ var ComRegister = class {
1038
1034
  this.logger.info("动态链接生成成功!");
1039
1035
  }
1040
1036
  this.logger.info("推送动态中...");
1041
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1037
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1042
1038
  if (this.config.pushImgsInDynamic) {
1043
1039
  this.logger.info("需要发送动态中的图片,开始发送...");
1044
1040
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1051,7 +1047,7 @@ var ComRegister = class {
1051
1047
  alt: "动态图片"
1052
1048
  }, pic.url))
1053
1049
  });
1054
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1050
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1055
1051
  }
1056
1052
  }
1057
1053
  this.logger.info("动态中的图片发送完毕!");
@@ -1103,7 +1099,7 @@ var ComRegister = class {
1103
1099
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1104
1100
  return data$1;
1105
1101
  }
1106
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1102
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1107
1103
  const buffer = await withRetry(async () => {
1108
1104
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1109
1105
  }, 1).catch((e$1) => {
@@ -1111,25 +1107,16 @@ var ComRegister = class {
1111
1107
  });
1112
1108
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1113
1109
  const msg = /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] });
1114
- return await this.broadcastToTargets(target, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1110
+ return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1115
1111
  }
1116
- async liveDetectWithListener(roomId, target, cardStyle) {
1112
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1117
1113
  let liveTime;
1118
1114
  let pushAtTimeTimer;
1119
1115
  const currentLiveDanmakuArr = [];
1120
1116
  let liveStatus = false;
1121
- let channelArrLen = 0;
1122
1117
  let liveRoomInfo;
1123
1118
  let masterInfo;
1124
1119
  let watchedNum;
1125
- const liveGuardBuyPushTargetArr = target.map((channel) => {
1126
- const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
1127
- channelArrLen += liveGuardBuyArr.length;
1128
- return {
1129
- channelArr: liveGuardBuyArr,
1130
- platform: channel.platform
1131
- };
1132
- });
1133
1120
  const pushAtTimeFunc = async () => {
1134
1121
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1135
1122
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1148,7 +1135,7 @@ var ComRegister = class {
1148
1135
  liveRoomInfo,
1149
1136
  masterInfo,
1150
1137
  cardStyle
1151
- }, target, liveMsg);
1138
+ }, uid, liveMsg);
1152
1139
  };
1153
1140
  const useMasterAndLiveRoomInfo = async (liveType) => {
1154
1141
  let flag = true;
@@ -1185,7 +1172,7 @@ var ComRegister = class {
1185
1172
  },
1186
1173
  onGuardBuy: ({ body }) => {
1187
1174
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1188
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1175
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1189
1176
  },
1190
1177
  onLiveStart: async () => {
1191
1178
  if (liveStatus) return;
@@ -1202,7 +1189,7 @@ var ComRegister = class {
1202
1189
  liveRoomInfo,
1203
1190
  masterInfo,
1204
1191
  cardStyle
1205
- }, target, liveStartMsg);
1192
+ }, uid, liveStartMsg);
1206
1193
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1207
1194
  },
1208
1195
  onLiveEnd: async () => {
@@ -1222,7 +1209,7 @@ var ComRegister = class {
1222
1209
  liveRoomInfo,
1223
1210
  masterInfo,
1224
1211
  cardStyle
1225
- }, target, liveEndMsg);
1212
+ }, uid, liveEndMsg);
1226
1213
  pushAtTimeTimer();
1227
1214
  pushAtTimeTimer = null;
1228
1215
  }
@@ -1237,7 +1224,7 @@ var ComRegister = class {
1237
1224
  liveRoomInfo,
1238
1225
  masterInfo,
1239
1226
  cardStyle
1240
- }, target, liveMsg);
1227
+ }, uid, liveMsg);
1241
1228
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1242
1229
  liveStatus = true;
1243
1230
  }
@@ -1288,7 +1275,7 @@ var ComRegister = class {
1288
1275
  liveRoomInfo: liveStatus.liveRoomInfo,
1289
1276
  masterInfo: liveStatus.masterInfo,
1290
1277
  cardStyle: sub.card
1291
- }, sub.target, liveMsg);
1278
+ }, sub.uid, liveMsg);
1292
1279
  }
1293
1280
  }
1294
1281
  const handler = async () => {
@@ -1320,7 +1307,7 @@ var ComRegister = class {
1320
1307
  liveRoomInfo: liveStatus.liveRoomInfo,
1321
1308
  masterInfo: liveStatus.masterInfo,
1322
1309
  cardStyle: sub.card
1323
- }, sub.target, liveEndMsg);
1310
+ }, sub.uid, liveEndMsg);
1324
1311
  liveStatus.live = false;
1325
1312
  }
1326
1313
  break;
@@ -1339,7 +1326,7 @@ var ComRegister = class {
1339
1326
  liveRoomInfo: liveStatus.liveRoomInfo,
1340
1327
  masterInfo: liveStatus.masterInfo,
1341
1328
  cardStyle: sub.card
1342
- }, sub.target, liveStartMsg);
1329
+ }, sub.uid, liveStartMsg);
1343
1330
  liveStatus.live = true;
1344
1331
  }
1345
1332
  if (liveStatus.live === true) {
@@ -1360,7 +1347,7 @@ var ComRegister = class {
1360
1347
  liveRoomInfo: liveStatus.liveRoomInfo,
1361
1348
  masterInfo: liveStatus.masterInfo,
1362
1349
  cardStyle: sub.card
1363
- }, sub.target, liveMsg);
1350
+ }, sub.uid, liveMsg);
1364
1351
  liveStatus.push = 0;
1365
1352
  }
1366
1353
  break;
@@ -1552,7 +1539,7 @@ var ComRegister = class {
1552
1539
  sub.live = false;
1553
1540
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1554
1541
  }
1555
- if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.target, sub.card);
1542
+ if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.uid, sub.card);
1556
1543
  }
1557
1544
  const subInfo = await this.subUserInBili(sub.uid);
1558
1545
  if (subInfo.code !== 0) return subInfo;
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.5-alpha.5",
4
+ "version": "3.2.5-alpha.6",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],