koishi-plugin-bilibili-notify 3.2.5-alpha.4 → 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.
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,53 +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.Live || type === PushType.StartBroadcasting) {
795
- for (const target of targets) for (const channel of target.channelArr) if (channel.live) pushArr.push(`${target.platform}:${channel.channelId}`);
796
- return pushArr;
800
+ initPushRecord(subs) {
801
+ const pushRecord = {};
802
+ for (const sub of subs) {
803
+ const atAllArr = [];
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
+ };
797
819
  }
798
- if (type === PushType.Dynamic) {
799
- for (const target of targets) for (const channel of target.channelArr) if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
800
- 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}`);
801
834
  }
802
- if (type === PushType.LiveGuardBuy) {
803
- for (const target of targets) for (const channel of target.channelArr) if (channel.liveGuardBuy) pushArr.push(`${target.platform}:${channel.channelId}`);
804
- 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}`);
805
840
  }
806
- }
807
- async broadcastToTargets(targets, content, type) {
808
- if (targets.length !== 1 || targets[0].channelArr.length !== 1) {
809
- const pushArr = this.getGroupsThatMeetCriteria(targets, type);
810
- this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
811
- await withRetry(async () => {
812
- 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 }));
813
844
  }, 1);
814
- return;
845
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
815
846
  }
816
- const targetChannel = targets[0].channelArr[0];
817
- const bot = this.getBot(targets[0].platform, targetChannel.bot);
818
- if (!bot || !bot.isActive) {
819
- this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
820
- this.logger.warn("未找到对应bot实例,本次消息推送取消!");
821
- 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}`);
822
852
  }
823
- const pushTypePatternMatching = {
824
- [PushType.Live]: async () => {
825
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
826
- },
827
- [PushType.Dynamic]: async () => {
828
- if (targetChannel.dynamic) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
829
- },
830
- [PushType.StartBroadcasting]: async () => {
831
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
832
- if (targetChannel.atAll) await this.sendMessageWithRetry(bot, targetChannel.channelId, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }));
833
- },
834
- [PushType.LiveGuardBuy]: async () => {
835
- if (targetChannel.liveGuardBuy) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
836
- }
837
- };
838
- await pushTypePatternMatching[type]();
853
+ return;
839
854
  }
840
855
  dynamicDetect() {
841
856
  const handler = async () => {
@@ -885,15 +900,15 @@ var ComRegister = class {
885
900
  }, 1).catch(async (e$1) => {
886
901
  if (e$1.message === "直播开播动态,不做处理") return;
887
902
  if (e$1.message === "出现关键词,屏蔽该动态") {
888
- 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);
889
904
  return;
890
905
  }
891
906
  if (e$1.message === "已屏蔽转发动态") {
892
- 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);
893
908
  return;
894
909
  }
895
910
  if (e$1.message === "已屏蔽专栏动态") {
896
- 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);
897
912
  return;
898
913
  }
899
914
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -907,7 +922,7 @@ var ComRegister = class {
907
922
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
908
923
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
909
924
  this.logger.info("推送动态中...");
910
- 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);
911
926
  if (this.config.pushImgsInDynamic) {
912
927
  if (item.type === "DYNAMIC_TYPE_DRAW") {
913
928
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -919,7 +934,7 @@ var ComRegister = class {
919
934
  alt: "动态图片"
920
935
  }, pic.url))
921
936
  });
922
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
937
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
923
938
  }
924
939
  }
925
940
  }
@@ -990,15 +1005,15 @@ var ComRegister = class {
990
1005
  }, 1).catch(async (e$1) => {
991
1006
  if (e$1.message === "直播开播动态,不做处理") return;
992
1007
  if (e$1.message === "出现关键词,屏蔽该动态") {
993
- 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);
994
1009
  return;
995
1010
  }
996
1011
  if (e$1.message === "已屏蔽转发动态") {
997
- 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);
998
1013
  return;
999
1014
  }
1000
1015
  if (e$1.message === "已屏蔽专栏动态") {
1001
- 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);
1002
1017
  return;
1003
1018
  }
1004
1019
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1017,7 +1032,7 @@ var ComRegister = class {
1017
1032
  this.logger.info("动态链接生成成功!");
1018
1033
  }
1019
1034
  this.logger.info("推送动态中...");
1020
- 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);
1021
1036
  if (this.config.pushImgsInDynamic) {
1022
1037
  this.logger.info("需要发送动态中的图片,开始发送...");
1023
1038
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1030,7 +1045,7 @@ var ComRegister = class {
1030
1045
  alt: "动态图片"
1031
1046
  }, pic.url))
1032
1047
  });
1033
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1048
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1034
1049
  }
1035
1050
  }
1036
1051
  this.logger.info("动态中的图片发送完毕!");
@@ -1082,7 +1097,7 @@ var ComRegister = class {
1082
1097
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1083
1098
  return data$1;
1084
1099
  }
1085
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1100
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1086
1101
  const buffer = await withRetry(async () => {
1087
1102
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1088
1103
  }, 1).catch((e$1) => {
@@ -1090,25 +1105,16 @@ var ComRegister = class {
1090
1105
  });
1091
1106
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1092
1107
  const msg = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] });
1093
- 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);
1094
1109
  }
1095
- async liveDetectWithListener(roomId, target, cardStyle) {
1110
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1096
1111
  let liveTime;
1097
1112
  let pushAtTimeTimer;
1098
1113
  const currentLiveDanmakuArr = [];
1099
1114
  let liveStatus = false;
1100
- let channelArrLen = 0;
1101
1115
  let liveRoomInfo;
1102
1116
  let masterInfo;
1103
1117
  let watchedNum;
1104
- const liveGuardBuyPushTargetArr = target.map((channel) => {
1105
- const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
1106
- channelArrLen += liveGuardBuyArr.length;
1107
- return {
1108
- channelArr: liveGuardBuyArr,
1109
- platform: channel.platform
1110
- };
1111
- });
1112
1118
  const pushAtTimeFunc = async () => {
1113
1119
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1114
1120
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1127,7 +1133,7 @@ var ComRegister = class {
1127
1133
  liveRoomInfo,
1128
1134
  masterInfo,
1129
1135
  cardStyle
1130
- }, target, liveMsg);
1136
+ }, uid, liveMsg);
1131
1137
  };
1132
1138
  const useMasterAndLiveRoomInfo = async (liveType) => {
1133
1139
  let flag = true;
@@ -1164,7 +1170,7 @@ var ComRegister = class {
1164
1170
  },
1165
1171
  onGuardBuy: ({ body }) => {
1166
1172
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1167
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1173
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1168
1174
  },
1169
1175
  onLiveStart: async () => {
1170
1176
  if (liveStatus) return;
@@ -1181,7 +1187,7 @@ var ComRegister = class {
1181
1187
  liveRoomInfo,
1182
1188
  masterInfo,
1183
1189
  cardStyle
1184
- }, target, liveStartMsg);
1190
+ }, uid, liveStartMsg);
1185
1191
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1186
1192
  },
1187
1193
  onLiveEnd: async () => {
@@ -1201,7 +1207,7 @@ var ComRegister = class {
1201
1207
  liveRoomInfo,
1202
1208
  masterInfo,
1203
1209
  cardStyle
1204
- }, target, liveEndMsg);
1210
+ }, uid, liveEndMsg);
1205
1211
  pushAtTimeTimer();
1206
1212
  pushAtTimeTimer = null;
1207
1213
  }
@@ -1216,7 +1222,7 @@ var ComRegister = class {
1216
1222
  liveRoomInfo,
1217
1223
  masterInfo,
1218
1224
  cardStyle
1219
- }, target, liveMsg);
1225
+ }, uid, liveMsg);
1220
1226
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1221
1227
  liveStatus = true;
1222
1228
  }
@@ -1267,7 +1273,7 @@ var ComRegister = class {
1267
1273
  liveRoomInfo: liveStatus.liveRoomInfo,
1268
1274
  masterInfo: liveStatus.masterInfo,
1269
1275
  cardStyle: sub.card
1270
- }, sub.target, liveMsg);
1276
+ }, sub.uid, liveMsg);
1271
1277
  }
1272
1278
  }
1273
1279
  const handler = async () => {
@@ -1299,7 +1305,7 @@ var ComRegister = class {
1299
1305
  liveRoomInfo: liveStatus.liveRoomInfo,
1300
1306
  masterInfo: liveStatus.masterInfo,
1301
1307
  cardStyle: sub.card
1302
- }, sub.target, liveEndMsg);
1308
+ }, sub.uid, liveEndMsg);
1303
1309
  liveStatus.live = false;
1304
1310
  }
1305
1311
  break;
@@ -1318,7 +1324,7 @@ var ComRegister = class {
1318
1324
  liveRoomInfo: liveStatus.liveRoomInfo,
1319
1325
  masterInfo: liveStatus.masterInfo,
1320
1326
  cardStyle: sub.card
1321
- }, sub.target, liveStartMsg);
1327
+ }, sub.uid, liveStartMsg);
1322
1328
  liveStatus.live = true;
1323
1329
  }
1324
1330
  if (liveStatus.live === true) {
@@ -1339,7 +1345,7 @@ var ComRegister = class {
1339
1345
  liveRoomInfo: liveStatus.liveRoomInfo,
1340
1346
  masterInfo: liveStatus.masterInfo,
1341
1347
  cardStyle: sub.card
1342
- }, sub.target, liveMsg);
1348
+ }, sub.uid, liveMsg);
1343
1349
  liveStatus.push = 0;
1344
1350
  }
1345
1351
  break;
@@ -1531,7 +1537,7 @@ var ComRegister = class {
1531
1537
  sub.live = false;
1532
1538
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1533
1539
  }
1534
- 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);
1535
1541
  }
1536
1542
  const subInfo = await this.subUserInBili(sub.uid);
1537
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,53 +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.Live || type === PushType.StartBroadcasting) {
797
- for (const target of targets) for (const channel of target.channelArr) if (channel.live) pushArr.push(`${target.platform}:${channel.channelId}`);
798
- return pushArr;
802
+ initPushRecord(subs) {
803
+ const pushRecord = {};
804
+ for (const sub of subs) {
805
+ const atAllArr = [];
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
+ };
799
821
  }
800
- if (type === PushType.Dynamic) {
801
- for (const target of targets) for (const channel of target.channelArr) if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
802
- 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}`);
803
836
  }
804
- if (type === PushType.LiveGuardBuy) {
805
- for (const target of targets) for (const channel of target.channelArr) if (channel.liveGuardBuy) pushArr.push(`${target.platform}:${channel.channelId}`);
806
- 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}`);
807
842
  }
808
- }
809
- async broadcastToTargets(targets, content, type) {
810
- if (targets.length !== 1 || targets[0].channelArr.length !== 1) {
811
- const pushArr = this.getGroupsThatMeetCriteria(targets, type);
812
- this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
813
- await withRetry(async () => {
814
- 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 }));
815
846
  }, 1);
816
- return;
847
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
817
848
  }
818
- const targetChannel = targets[0].channelArr[0];
819
- const bot = this.getBot(targets[0].platform, targetChannel.bot);
820
- if (!bot || !bot.isActive) {
821
- this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
822
- this.logger.warn("未找到对应bot实例,本次消息推送取消!");
823
- 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}`);
824
854
  }
825
- const pushTypePatternMatching = {
826
- [PushType.Live]: async () => {
827
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
828
- },
829
- [PushType.Dynamic]: async () => {
830
- if (targetChannel.dynamic) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
831
- },
832
- [PushType.StartBroadcasting]: async () => {
833
- if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
834
- if (targetChannel.atAll) await this.sendMessageWithRetry(bot, targetChannel.channelId, /* @__PURE__ */ jsx("at", { type: "all" }));
835
- },
836
- [PushType.LiveGuardBuy]: async () => {
837
- if (targetChannel.liveGuardBuy) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
838
- }
839
- };
840
- await pushTypePatternMatching[type]();
855
+ return;
841
856
  }
842
857
  dynamicDetect() {
843
858
  const handler = async () => {
@@ -887,15 +902,15 @@ var ComRegister = class {
887
902
  }, 1).catch(async (e$1) => {
888
903
  if (e$1.message === "直播开播动态,不做处理") return;
889
904
  if (e$1.message === "出现关键词,屏蔽该动态") {
890
- 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);
891
906
  return;
892
907
  }
893
908
  if (e$1.message === "已屏蔽转发动态") {
894
- 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);
895
910
  return;
896
911
  }
897
912
  if (e$1.message === "已屏蔽专栏动态") {
898
- 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);
899
914
  return;
900
915
  }
901
916
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -909,7 +924,7 @@ var ComRegister = class {
909
924
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
910
925
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
911
926
  this.logger.info("推送动态中...");
912
- 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);
913
928
  if (this.config.pushImgsInDynamic) {
914
929
  if (item.type === "DYNAMIC_TYPE_DRAW") {
915
930
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -921,7 +936,7 @@ var ComRegister = class {
921
936
  alt: "动态图片"
922
937
  }, pic.url))
923
938
  });
924
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
939
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
925
940
  }
926
941
  }
927
942
  }
@@ -992,15 +1007,15 @@ var ComRegister = class {
992
1007
  }, 1).catch(async (e$1) => {
993
1008
  if (e$1.message === "直播开播动态,不做处理") return;
994
1009
  if (e$1.message === "出现关键词,屏蔽该动态") {
995
- 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);
996
1011
  return;
997
1012
  }
998
1013
  if (e$1.message === "已屏蔽转发动态") {
999
- 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);
1000
1015
  return;
1001
1016
  }
1002
1017
  if (e$1.message === "已屏蔽专栏动态") {
1003
- 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);
1004
1019
  return;
1005
1020
  }
1006
1021
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1019,7 +1034,7 @@ var ComRegister = class {
1019
1034
  this.logger.info("动态链接生成成功!");
1020
1035
  }
1021
1036
  this.logger.info("推送动态中...");
1022
- 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);
1023
1038
  if (this.config.pushImgsInDynamic) {
1024
1039
  this.logger.info("需要发送动态中的图片,开始发送...");
1025
1040
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1032,7 +1047,7 @@ var ComRegister = class {
1032
1047
  alt: "动态图片"
1033
1048
  }, pic.url))
1034
1049
  });
1035
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1050
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1036
1051
  }
1037
1052
  }
1038
1053
  this.logger.info("动态中的图片发送完毕!");
@@ -1084,7 +1099,7 @@ var ComRegister = class {
1084
1099
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1085
1100
  return data$1;
1086
1101
  }
1087
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1102
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1088
1103
  const buffer = await withRetry(async () => {
1089
1104
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1090
1105
  }, 1).catch((e$1) => {
@@ -1092,25 +1107,16 @@ var ComRegister = class {
1092
1107
  });
1093
1108
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1094
1109
  const msg = /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] });
1095
- 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);
1096
1111
  }
1097
- async liveDetectWithListener(roomId, target, cardStyle) {
1112
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1098
1113
  let liveTime;
1099
1114
  let pushAtTimeTimer;
1100
1115
  const currentLiveDanmakuArr = [];
1101
1116
  let liveStatus = false;
1102
- let channelArrLen = 0;
1103
1117
  let liveRoomInfo;
1104
1118
  let masterInfo;
1105
1119
  let watchedNum;
1106
- const liveGuardBuyPushTargetArr = target.map((channel) => {
1107
- const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
1108
- channelArrLen += liveGuardBuyArr.length;
1109
- return {
1110
- channelArr: liveGuardBuyArr,
1111
- platform: channel.platform
1112
- };
1113
- });
1114
1120
  const pushAtTimeFunc = async () => {
1115
1121
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1116
1122
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1129,7 +1135,7 @@ var ComRegister = class {
1129
1135
  liveRoomInfo,
1130
1136
  masterInfo,
1131
1137
  cardStyle
1132
- }, target, liveMsg);
1138
+ }, uid, liveMsg);
1133
1139
  };
1134
1140
  const useMasterAndLiveRoomInfo = async (liveType) => {
1135
1141
  let flag = true;
@@ -1166,7 +1172,7 @@ var ComRegister = class {
1166
1172
  },
1167
1173
  onGuardBuy: ({ body }) => {
1168
1174
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1169
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1175
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1170
1176
  },
1171
1177
  onLiveStart: async () => {
1172
1178
  if (liveStatus) return;
@@ -1183,7 +1189,7 @@ var ComRegister = class {
1183
1189
  liveRoomInfo,
1184
1190
  masterInfo,
1185
1191
  cardStyle
1186
- }, target, liveStartMsg);
1192
+ }, uid, liveStartMsg);
1187
1193
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1188
1194
  },
1189
1195
  onLiveEnd: async () => {
@@ -1203,7 +1209,7 @@ var ComRegister = class {
1203
1209
  liveRoomInfo,
1204
1210
  masterInfo,
1205
1211
  cardStyle
1206
- }, target, liveEndMsg);
1212
+ }, uid, liveEndMsg);
1207
1213
  pushAtTimeTimer();
1208
1214
  pushAtTimeTimer = null;
1209
1215
  }
@@ -1218,7 +1224,7 @@ var ComRegister = class {
1218
1224
  liveRoomInfo,
1219
1225
  masterInfo,
1220
1226
  cardStyle
1221
- }, target, liveMsg);
1227
+ }, uid, liveMsg);
1222
1228
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1223
1229
  liveStatus = true;
1224
1230
  }
@@ -1269,7 +1275,7 @@ var ComRegister = class {
1269
1275
  liveRoomInfo: liveStatus.liveRoomInfo,
1270
1276
  masterInfo: liveStatus.masterInfo,
1271
1277
  cardStyle: sub.card
1272
- }, sub.target, liveMsg);
1278
+ }, sub.uid, liveMsg);
1273
1279
  }
1274
1280
  }
1275
1281
  const handler = async () => {
@@ -1301,7 +1307,7 @@ var ComRegister = class {
1301
1307
  liveRoomInfo: liveStatus.liveRoomInfo,
1302
1308
  masterInfo: liveStatus.masterInfo,
1303
1309
  cardStyle: sub.card
1304
- }, sub.target, liveEndMsg);
1310
+ }, sub.uid, liveEndMsg);
1305
1311
  liveStatus.live = false;
1306
1312
  }
1307
1313
  break;
@@ -1320,7 +1326,7 @@ var ComRegister = class {
1320
1326
  liveRoomInfo: liveStatus.liveRoomInfo,
1321
1327
  masterInfo: liveStatus.masterInfo,
1322
1328
  cardStyle: sub.card
1323
- }, sub.target, liveStartMsg);
1329
+ }, sub.uid, liveStartMsg);
1324
1330
  liveStatus.live = true;
1325
1331
  }
1326
1332
  if (liveStatus.live === true) {
@@ -1341,7 +1347,7 @@ var ComRegister = class {
1341
1347
  liveRoomInfo: liveStatus.liveRoomInfo,
1342
1348
  masterInfo: liveStatus.masterInfo,
1343
1349
  cardStyle: sub.card
1344
- }, sub.target, liveMsg);
1350
+ }, sub.uid, liveMsg);
1345
1351
  liveStatus.push = 0;
1346
1352
  }
1347
1353
  break;
@@ -1533,7 +1539,7 @@ var ComRegister = class {
1533
1539
  sub.live = false;
1534
1540
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1535
1541
  }
1536
- 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);
1537
1543
  }
1538
1544
  const subInfo = await this.subUserInBili(sub.uid);
1539
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.4",
4
+ "version": "3.2.5-alpha.6",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -283,6 +283,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
283
283
  > - ver 3.2.5-alpha.2 测试版本
284
284
  > - ver 3.2.5-alpha.3 更新依赖版本
285
285
  > - ver 3.2.5-alpha.4 测试版本
286
+ > - ver 3.2.5-alpha.5 测试版本
286
287
 
287
288
  ## 交流群
288
289