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

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;
@@ -789,72 +796,60 @@ var ComRegister = class {
789
796
  await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
790
797
  });
791
798
  }
792
- getGroupsThatMeetCriteria(targets, type) {
793
- const pushArr = [];
794
- if (type === PushType.StartBroadcasting) {
799
+ initPushRecord(subs) {
800
+ const pushRecord = {};
801
+ for (const sub of subs) {
795
802
  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];
803
+ const dynamicArr = [];
804
+ const liveArr = [];
805
+ const liveGuardBuyArr = [];
806
+ for (const platform of sub.target) for (const channel of platform.channelArr) {
807
+ if (channel.atAll) atAllArr.push(`${platform.platform}:${channel.channelId}`);
808
+ if (channel.dynamic) dynamicArr.push(`${platform.platform}:${channel.channelId}`);
809
+ if (channel.live) liveArr.push(`${platform.platform}:${channel.channelId}`);
810
+ if (channel.liveGuardBuy) liveGuardBuyArr.push(`${platform.platform}:${channel.channelId}`);
811
+ }
812
+ pushRecord[sub.uid] = {
813
+ atAllArr,
814
+ dynamicArr,
815
+ liveArr,
816
+ liveGuardBuyArr
817
+ };
808
818
  }
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];
819
+ this.pushRecord = pushRecord;
820
+ this.logger.info("初始化推送群组/频道信息:");
821
+ this.logger.info(this.pushRecord);
822
+ }
823
+ async broadcastToTargets(uid, content, type) {
824
+ this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
825
+ const record = this.pushRecord[uid];
826
+ this.logger.info("本次推送目标:");
827
+ this.logger.info(record);
828
+ if (type === PushType.StartBroadcasting && record.atAllArr?.length >= 1) {
829
+ const success = await withRetry(async () => {
830
+ 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 })] }));
831
+ }, 1);
832
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
812
833
  }
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];
834
+ if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
835
+ const success = await withRetry(async () => {
836
+ return await this.ctx.broadcast(record.dynamicArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
837
+ }, 1);
838
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
816
839
  }
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);
840
+ if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
841
+ const success = await withRetry(async () => {
842
+ return await this.ctx.broadcast(record.liveArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
832
843
  }, 1);
833
- return;
844
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
834
845
  }
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;
846
+ if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
847
+ const success = await withRetry(async () => {
848
+ return await this.ctx.broadcast(record.liveGuardBuyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
849
+ }, 1);
850
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
841
851
  }
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]();
852
+ return;
858
853
  }
859
854
  dynamicDetect() {
860
855
  const handler = async () => {
@@ -904,15 +899,15 @@ var ComRegister = class {
904
899
  }, 1).catch(async (e$1) => {
905
900
  if (e$1.message === "直播开播动态,不做处理") return;
906
901
  if (e$1.message === "出现关键词,屏蔽该动态") {
907
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
902
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
908
903
  return;
909
904
  }
910
905
  if (e$1.message === "已屏蔽转发动态") {
911
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
906
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
912
907
  return;
913
908
  }
914
909
  if (e$1.message === "已屏蔽专栏动态") {
915
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
910
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
916
911
  return;
917
912
  }
918
913
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -926,7 +921,7 @@ var ComRegister = class {
926
921
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
927
922
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
928
923
  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);
924
+ 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
925
  if (this.config.pushImgsInDynamic) {
931
926
  if (item.type === "DYNAMIC_TYPE_DRAW") {
932
927
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -938,7 +933,7 @@ var ComRegister = class {
938
933
  alt: "动态图片"
939
934
  }, pic.url))
940
935
  });
941
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
936
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
942
937
  }
943
938
  }
944
939
  }
@@ -1009,15 +1004,15 @@ var ComRegister = class {
1009
1004
  }, 1).catch(async (e$1) => {
1010
1005
  if (e$1.message === "直播开播动态,不做处理") return;
1011
1006
  if (e$1.message === "出现关键词,屏蔽该动态") {
1012
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1007
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1013
1008
  return;
1014
1009
  }
1015
1010
  if (e$1.message === "已屏蔽转发动态") {
1016
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1011
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1017
1012
  return;
1018
1013
  }
1019
1014
  if (e$1.message === "已屏蔽专栏动态") {
1020
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1015
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1021
1016
  return;
1022
1017
  }
1023
1018
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1036,7 +1031,7 @@ var ComRegister = class {
1036
1031
  this.logger.info("动态链接生成成功!");
1037
1032
  }
1038
1033
  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);
1034
+ 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
1035
  if (this.config.pushImgsInDynamic) {
1041
1036
  this.logger.info("需要发送动态中的图片,开始发送...");
1042
1037
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1049,7 +1044,7 @@ var ComRegister = class {
1049
1044
  alt: "动态图片"
1050
1045
  }, pic.url))
1051
1046
  });
1052
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1047
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1053
1048
  }
1054
1049
  }
1055
1050
  this.logger.info("动态中的图片发送完毕!");
@@ -1101,7 +1096,7 @@ var ComRegister = class {
1101
1096
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1102
1097
  return data$1;
1103
1098
  }
1104
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1099
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1105
1100
  const buffer = await withRetry(async () => {
1106
1101
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1107
1102
  }, 1).catch((e$1) => {
@@ -1109,25 +1104,16 @@ var ComRegister = class {
1109
1104
  });
1110
1105
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1111
1106
  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);
1107
+ return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1113
1108
  }
1114
- async liveDetectWithListener(roomId, target, cardStyle) {
1109
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1115
1110
  let liveTime;
1116
1111
  let pushAtTimeTimer;
1117
1112
  const currentLiveDanmakuArr = [];
1118
1113
  let liveStatus = false;
1119
- let channelArrLen = 0;
1120
1114
  let liveRoomInfo;
1121
1115
  let masterInfo;
1122
1116
  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
1117
  const pushAtTimeFunc = async () => {
1132
1118
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1133
1119
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1146,7 +1132,7 @@ var ComRegister = class {
1146
1132
  liveRoomInfo,
1147
1133
  masterInfo,
1148
1134
  cardStyle
1149
- }, target, liveMsg);
1135
+ }, uid, liveMsg);
1150
1136
  };
1151
1137
  const useMasterAndLiveRoomInfo = async (liveType) => {
1152
1138
  let flag = true;
@@ -1183,7 +1169,7 @@ var ComRegister = class {
1183
1169
  },
1184
1170
  onGuardBuy: ({ body }) => {
1185
1171
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1186
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1172
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1187
1173
  },
1188
1174
  onLiveStart: async () => {
1189
1175
  if (liveStatus) return;
@@ -1200,7 +1186,7 @@ var ComRegister = class {
1200
1186
  liveRoomInfo,
1201
1187
  masterInfo,
1202
1188
  cardStyle
1203
- }, target, liveStartMsg);
1189
+ }, uid, liveStartMsg);
1204
1190
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1205
1191
  },
1206
1192
  onLiveEnd: async () => {
@@ -1220,7 +1206,7 @@ var ComRegister = class {
1220
1206
  liveRoomInfo,
1221
1207
  masterInfo,
1222
1208
  cardStyle
1223
- }, target, liveEndMsg);
1209
+ }, uid, liveEndMsg);
1224
1210
  pushAtTimeTimer();
1225
1211
  pushAtTimeTimer = null;
1226
1212
  }
@@ -1235,7 +1221,7 @@ var ComRegister = class {
1235
1221
  liveRoomInfo,
1236
1222
  masterInfo,
1237
1223
  cardStyle
1238
- }, target, liveMsg);
1224
+ }, uid, liveMsg);
1239
1225
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1240
1226
  liveStatus = true;
1241
1227
  }
@@ -1286,7 +1272,7 @@ var ComRegister = class {
1286
1272
  liveRoomInfo: liveStatus.liveRoomInfo,
1287
1273
  masterInfo: liveStatus.masterInfo,
1288
1274
  cardStyle: sub.card
1289
- }, sub.target, liveMsg);
1275
+ }, sub.uid, liveMsg);
1290
1276
  }
1291
1277
  }
1292
1278
  const handler = async () => {
@@ -1318,7 +1304,7 @@ var ComRegister = class {
1318
1304
  liveRoomInfo: liveStatus.liveRoomInfo,
1319
1305
  masterInfo: liveStatus.masterInfo,
1320
1306
  cardStyle: sub.card
1321
- }, sub.target, liveEndMsg);
1307
+ }, sub.uid, liveEndMsg);
1322
1308
  liveStatus.live = false;
1323
1309
  }
1324
1310
  break;
@@ -1337,7 +1323,7 @@ var ComRegister = class {
1337
1323
  liveRoomInfo: liveStatus.liveRoomInfo,
1338
1324
  masterInfo: liveStatus.masterInfo,
1339
1325
  cardStyle: sub.card
1340
- }, sub.target, liveStartMsg);
1326
+ }, sub.uid, liveStartMsg);
1341
1327
  liveStatus.live = true;
1342
1328
  }
1343
1329
  if (liveStatus.live === true) {
@@ -1358,7 +1344,7 @@ var ComRegister = class {
1358
1344
  liveRoomInfo: liveStatus.liveRoomInfo,
1359
1345
  masterInfo: liveStatus.masterInfo,
1360
1346
  cardStyle: sub.card
1361
- }, sub.target, liveMsg);
1347
+ }, sub.uid, liveMsg);
1362
1348
  liveStatus.push = 0;
1363
1349
  }
1364
1350
  break;
@@ -1526,6 +1512,7 @@ var ComRegister = class {
1526
1512
  return await subUserMatchPattern[subUserData.code]();
1527
1513
  }
1528
1514
  async loadSubFromConfig(subs) {
1515
+ this.initPushRecord(subs);
1529
1516
  for (const sub of subs) {
1530
1517
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1531
1518
  const { code: userInfoCode, msg: userInfoMsg, data: userInfoData } = await withRetry(async () => {
@@ -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;
@@ -791,72 +798,60 @@ var ComRegister = class {
791
798
  await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
792
799
  });
793
800
  }
794
- getGroupsThatMeetCriteria(targets, type) {
795
- const pushArr = [];
796
- if (type === PushType.StartBroadcasting) {
801
+ initPushRecord(subs) {
802
+ const pushRecord = {};
803
+ for (const sub of subs) {
797
804
  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];
805
+ const dynamicArr = [];
806
+ const liveArr = [];
807
+ const liveGuardBuyArr = [];
808
+ for (const platform of sub.target) for (const channel of platform.channelArr) {
809
+ if (channel.atAll) atAllArr.push(`${platform.platform}:${channel.channelId}`);
810
+ if (channel.dynamic) dynamicArr.push(`${platform.platform}:${channel.channelId}`);
811
+ if (channel.live) liveArr.push(`${platform.platform}:${channel.channelId}`);
812
+ if (channel.liveGuardBuy) liveGuardBuyArr.push(`${platform.platform}:${channel.channelId}`);
813
+ }
814
+ pushRecord[sub.uid] = {
815
+ atAllArr,
816
+ dynamicArr,
817
+ liveArr,
818
+ liveGuardBuyArr
819
+ };
810
820
  }
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];
821
+ this.pushRecord = pushRecord;
822
+ this.logger.info("初始化推送群组/频道信息:");
823
+ this.logger.info(this.pushRecord);
824
+ }
825
+ async broadcastToTargets(uid, content, type) {
826
+ this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
827
+ const record = this.pushRecord[uid];
828
+ this.logger.info("本次推送目标:");
829
+ this.logger.info(record);
830
+ if (type === PushType.StartBroadcasting && record.atAllArr?.length >= 1) {
831
+ const success = await withRetry(async () => {
832
+ return await this.ctx.broadcast(record.atAllArr, /* @__PURE__ */ jsxs("message", { children: [/* @__PURE__ */ jsx("at", { type: "all" }), /* @__PURE__ */ jsx("message", { children: content })] }));
833
+ }, 1);
834
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
814
835
  }
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];
836
+ if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
837
+ const success = await withRetry(async () => {
838
+ return await this.ctx.broadcast(record.dynamicArr, /* @__PURE__ */ jsx("message", { children: content }));
839
+ }, 1);
840
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
818
841
  }
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);
842
+ if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
843
+ const success = await withRetry(async () => {
844
+ return await this.ctx.broadcast(record.liveArr, /* @__PURE__ */ jsx("message", { children: content }));
834
845
  }, 1);
835
- return;
846
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
836
847
  }
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;
848
+ if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
849
+ const success = await withRetry(async () => {
850
+ return await this.ctx.broadcast(record.liveGuardBuyArr, /* @__PURE__ */ jsx("message", { children: content }));
851
+ }, 1);
852
+ this.logger.info(`成功推送全体成员消息群组/频道:${success}`);
843
853
  }
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]();
854
+ return;
860
855
  }
861
856
  dynamicDetect() {
862
857
  const handler = async () => {
@@ -906,15 +901,15 @@ var ComRegister = class {
906
901
  }, 1).catch(async (e$1) => {
907
902
  if (e$1.message === "直播开播动态,不做处理") return;
908
903
  if (e$1.message === "出现关键词,屏蔽该动态") {
909
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
904
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
910
905
  return;
911
906
  }
912
907
  if (e$1.message === "已屏蔽转发动态") {
913
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
908
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
914
909
  return;
915
910
  }
916
911
  if (e$1.message === "已屏蔽专栏动态") {
917
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
912
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
918
913
  return;
919
914
  }
920
915
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -928,7 +923,7 @@ var ComRegister = class {
928
923
  } else dUrl = `${name$3}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
929
924
  else dUrl = `${name$3}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
930
925
  this.logger.info("推送动态中...");
931
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
926
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
932
927
  if (this.config.pushImgsInDynamic) {
933
928
  if (item.type === "DYNAMIC_TYPE_DRAW") {
934
929
  const pics = item.modules?.module_dynamic?.major?.opus?.pics;
@@ -940,7 +935,7 @@ var ComRegister = class {
940
935
  alt: "动态图片"
941
936
  }, pic.url))
942
937
  });
943
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
938
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
944
939
  }
945
940
  }
946
941
  }
@@ -1011,15 +1006,15 @@ var ComRegister = class {
1011
1006
  }, 1).catch(async (e$1) => {
1012
1007
  if (e$1.message === "直播开播动态,不做处理") return;
1013
1008
  if (e$1.message === "出现关键词,屏蔽该动态") {
1014
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1009
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}发布了一条含有屏蔽关键字的动态`, PushType.Dynamic);
1015
1010
  return;
1016
1011
  }
1017
1012
  if (e$1.message === "已屏蔽转发动态") {
1018
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1013
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}转发了一条动态,已屏蔽`, PushType.Dynamic);
1019
1014
  return;
1020
1015
  }
1021
1016
  if (e$1.message === "已屏蔽专栏动态") {
1022
- if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1017
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.uid, `${name$3}投稿了一条专栏,已屏蔽`, PushType.Dynamic);
1023
1018
  return;
1024
1019
  }
1025
1020
  this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e$1.message}`);
@@ -1038,7 +1033,7 @@ var ComRegister = class {
1038
1033
  this.logger.info("动态链接生成成功!");
1039
1034
  }
1040
1035
  this.logger.info("推送动态中...");
1041
- await this.broadcastToTargets(sub.target, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1036
+ await this.broadcastToTargets(sub.uid, /* @__PURE__ */ jsxs(Fragment, { children: [h.image(buffer, "image/jpeg"), dUrl] }), PushType.Dynamic);
1042
1037
  if (this.config.pushImgsInDynamic) {
1043
1038
  this.logger.info("需要发送动态中的图片,开始发送...");
1044
1039
  if (item.type === "DYNAMIC_TYPE_DRAW") {
@@ -1051,7 +1046,7 @@ var ComRegister = class {
1051
1046
  alt: "动态图片"
1052
1047
  }, pic.url))
1053
1048
  });
1054
- await this.broadcastToTargets(sub.target, picsMsg, PushType.Dynamic);
1049
+ await this.broadcastToTargets(sub.uid, picsMsg, PushType.Dynamic);
1055
1050
  }
1056
1051
  }
1057
1052
  this.logger.info("动态中的图片发送完毕!");
@@ -1103,7 +1098,7 @@ var ComRegister = class {
1103
1098
  if (!data$1) return await this.sendPrivateMsgAndStopService();
1104
1099
  return data$1;
1105
1100
  }
1106
- async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
1101
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1107
1102
  const buffer = await withRetry(async () => {
1108
1103
  return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1109
1104
  }, 1).catch((e$1) => {
@@ -1111,25 +1106,16 @@ var ComRegister = class {
1111
1106
  });
1112
1107
  if (!buffer) return await this.sendPrivateMsgAndStopService();
1113
1108
  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);
1109
+ return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1115
1110
  }
1116
- async liveDetectWithListener(roomId, target, cardStyle) {
1111
+ async liveDetectWithListener(roomId, uid, cardStyle) {
1117
1112
  let liveTime;
1118
1113
  let pushAtTimeTimer;
1119
1114
  const currentLiveDanmakuArr = [];
1120
1115
  let liveStatus = false;
1121
- let channelArrLen = 0;
1122
1116
  let liveRoomInfo;
1123
1117
  let masterInfo;
1124
1118
  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
1119
  const pushAtTimeFunc = async () => {
1134
1120
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1135
1121
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1148,7 +1134,7 @@ var ComRegister = class {
1148
1134
  liveRoomInfo,
1149
1135
  masterInfo,
1150
1136
  cardStyle
1151
- }, target, liveMsg);
1137
+ }, uid, liveMsg);
1152
1138
  };
1153
1139
  const useMasterAndLiveRoomInfo = async (liveType) => {
1154
1140
  let flag = true;
@@ -1185,7 +1171,7 @@ var ComRegister = class {
1185
1171
  },
1186
1172
  onGuardBuy: ({ body }) => {
1187
1173
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1188
- channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, PushType.LiveGuardBuy);
1174
+ this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1189
1175
  },
1190
1176
  onLiveStart: async () => {
1191
1177
  if (liveStatus) return;
@@ -1202,7 +1188,7 @@ var ComRegister = class {
1202
1188
  liveRoomInfo,
1203
1189
  masterInfo,
1204
1190
  cardStyle
1205
- }, target, liveStartMsg);
1191
+ }, uid, liveStartMsg);
1206
1192
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1207
1193
  },
1208
1194
  onLiveEnd: async () => {
@@ -1222,7 +1208,7 @@ var ComRegister = class {
1222
1208
  liveRoomInfo,
1223
1209
  masterInfo,
1224
1210
  cardStyle
1225
- }, target, liveEndMsg);
1211
+ }, uid, liveEndMsg);
1226
1212
  pushAtTimeTimer();
1227
1213
  pushAtTimeTimer = null;
1228
1214
  }
@@ -1237,7 +1223,7 @@ var ComRegister = class {
1237
1223
  liveRoomInfo,
1238
1224
  masterInfo,
1239
1225
  cardStyle
1240
- }, target, liveMsg);
1226
+ }, uid, liveMsg);
1241
1227
  if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1242
1228
  liveStatus = true;
1243
1229
  }
@@ -1288,7 +1274,7 @@ var ComRegister = class {
1288
1274
  liveRoomInfo: liveStatus.liveRoomInfo,
1289
1275
  masterInfo: liveStatus.masterInfo,
1290
1276
  cardStyle: sub.card
1291
- }, sub.target, liveMsg);
1277
+ }, sub.uid, liveMsg);
1292
1278
  }
1293
1279
  }
1294
1280
  const handler = async () => {
@@ -1320,7 +1306,7 @@ var ComRegister = class {
1320
1306
  liveRoomInfo: liveStatus.liveRoomInfo,
1321
1307
  masterInfo: liveStatus.masterInfo,
1322
1308
  cardStyle: sub.card
1323
- }, sub.target, liveEndMsg);
1309
+ }, sub.uid, liveEndMsg);
1324
1310
  liveStatus.live = false;
1325
1311
  }
1326
1312
  break;
@@ -1339,7 +1325,7 @@ var ComRegister = class {
1339
1325
  liveRoomInfo: liveStatus.liveRoomInfo,
1340
1326
  masterInfo: liveStatus.masterInfo,
1341
1327
  cardStyle: sub.card
1342
- }, sub.target, liveStartMsg);
1328
+ }, sub.uid, liveStartMsg);
1343
1329
  liveStatus.live = true;
1344
1330
  }
1345
1331
  if (liveStatus.live === true) {
@@ -1360,7 +1346,7 @@ var ComRegister = class {
1360
1346
  liveRoomInfo: liveStatus.liveRoomInfo,
1361
1347
  masterInfo: liveStatus.masterInfo,
1362
1348
  cardStyle: sub.card
1363
- }, sub.target, liveMsg);
1349
+ }, sub.uid, liveMsg);
1364
1350
  liveStatus.push = 0;
1365
1351
  }
1366
1352
  break;
@@ -1528,6 +1514,7 @@ var ComRegister = class {
1528
1514
  return await subUserMatchPattern[subUserData.code]();
1529
1515
  }
1530
1516
  async loadSubFromConfig(subs) {
1517
+ this.initPushRecord(subs);
1531
1518
  for (const sub of subs) {
1532
1519
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1533
1520
  const { code: userInfoCode, msg: userInfoMsg, data: userInfoData } = await withRetry(async () => {
@@ -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.7",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -284,6 +284,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
284
284
  > - ver 3.2.5-alpha.3 更新依赖版本
285
285
  > - ver 3.2.5-alpha.4 测试版本
286
286
  > - ver 3.2.5-alpha.5 测试版本
287
+ > - ver 3.2.5-alpha.6 测试版本
288
+ > - ver 3.2.5-alpha.7 测试版本
287
289
 
288
290
  ## 交流群
289
291