koishi-plugin-bilibili-notify 3.3.3 → 3.3.4-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -778,8 +778,14 @@ var ComRegister = class {
778
778
  return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
779
779
  }
780
780
  async sendPrivateMsg(content) {
781
- if (this.config.master.enable) if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
782
- else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
781
+ if (this.config.master.enable) {
782
+ if (this.privateBot.status !== koishi.Universal.Status.ONLINE) {
783
+ this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
784
+ return;
785
+ }
786
+ if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
787
+ else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
788
+ }
783
789
  }
784
790
  async sendPrivateMsgAndRebootService() {
785
791
  if (this.rebootCount >= 3) {
@@ -861,59 +867,74 @@ var ComRegister = class {
861
867
  this.logger.info("初始化推送群组/频道信息:");
862
868
  this.logger.info(this.pushArrMap);
863
869
  }
864
- checkAllBotsAreReady() {
865
- return !this.ctx.bots.some((bot) => bot.status !== koishi.Universal.Status.ONLINE);
866
- }
867
- async broadcastToTargets(uid, content, type, retry = 3e3) {
868
- if (!this.checkAllBotsAreReady()) {
869
- this.logger.error(`存在机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
870
- this.ctx.setTimeout(() => {
871
- this.broadcastToTargets(uid, content, type, retry * 2);
872
- }, retry);
873
- return;
870
+ async pushMessage(targets, content, retry = 3e3) {
871
+ const t = {};
872
+ for (const target of targets) {
873
+ const [platform, channleId] = target.split(":");
874
+ if (!t[platform]) t[platform] = [channleId];
875
+ else t[platform].push(channleId);
874
876
  }
877
+ for (const platform of Object.keys(t)) {
878
+ const bots = [];
879
+ for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
880
+ botloop: for (const bot of bots) {
881
+ if (bot.status !== koishi.Universal.Status.ONLINE) {
882
+ this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
883
+ this.ctx.setTimeout(async () => {
884
+ await this.pushMessage(targets, retry * 2);
885
+ }, retry);
886
+ return;
887
+ }
888
+ let num = 0;
889
+ for (const channelId of t[platform]) try {
890
+ await bot.sendMessage(channelId, content);
891
+ num++;
892
+ } catch (e) {
893
+ this.logger.error(e);
894
+ if (bots.length > 1) continue botloop;
895
+ }
896
+ this.logger.info(`成功推送消息 ${num} 条`);
897
+ }
898
+ }
899
+ }
900
+ async broadcastToTargets(uid, content, type) {
875
901
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
876
902
  const record = this.pushArrMap.get(uid);
877
903
  this.logger.info("本次推送目标:");
878
904
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length >= 1) {
879
905
  this.logger.info(record.liveAtAllArr);
880
906
  const atAllArr = structuredClone(record.liveAtAllArr);
881
- const success = await withRetry(async () => {
882
- return await this.ctx.broadcast(atAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
907
+ await withRetry(async () => {
908
+ return await this.pushMessage(atAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
883
909
  }, 1);
884
- this.logger.info(`成功推送全体成员消息:${success.length}条`);
885
910
  }
886
911
  if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
887
912
  if (record.dynamicAtAllArr?.length >= 1) {
888
913
  this.logger.info(record.dynamicAtAllArr);
889
914
  const dynamicAtAllArr = structuredClone(record.dynamicAtAllArr);
890
- const success$1 = await withRetry(async () => {
891
- return await this.ctx.broadcast(dynamicAtAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
915
+ await withRetry(async () => {
916
+ return await this.pushMessage(dynamicAtAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
892
917
  }, 1);
893
- this.logger.info(`成功推送全体成员消息:${success$1.length}条`);
894
918
  }
895
919
  this.logger.info(record.dynamicArr);
896
920
  const dynamicArr = structuredClone(record.dynamicArr);
897
- const success = await withRetry(async () => {
898
- return await this.ctx.broadcast(dynamicArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
921
+ await withRetry(async () => {
922
+ return await this.pushMessage(dynamicArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
899
923
  }, 1);
900
- this.logger.info(`成功推送动态消息:${success.length}条`);
901
924
  }
902
925
  if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
903
926
  this.logger.info(record.liveArr);
904
927
  const liveArr = structuredClone(record.liveArr);
905
- const success = await withRetry(async () => {
906
- return await this.ctx.broadcast(liveArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
928
+ await withRetry(async () => {
929
+ return await this.pushMessage(liveArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
907
930
  }, 1);
908
- this.logger.info(`成功推送直播消息:${success.length}条`);
909
931
  }
910
932
  if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
911
933
  this.logger.info(record.liveGuardBuyArr);
912
934
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
913
- const success = await withRetry(async () => {
914
- return await this.ctx.broadcast(liveGuardBuyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
935
+ await withRetry(async () => {
936
+ return await this.pushMessage(liveGuardBuyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
915
937
  }, 1);
916
- this.logger.info(`成功推送上舰消息:${success.length}条`);
917
938
  }
918
939
  if (type === PushType.WordCloudAndLiveSummary) {
919
940
  const wordcloudArr = structuredClone(record.wordcloudArr);
@@ -924,26 +945,23 @@ var ComRegister = class {
924
945
  if (wordcloudAndLiveSummaryArr.length > 0) {
925
946
  this.logger.info("词云和直播总结");
926
947
  this.logger.info(wordcloudAndLiveSummaryArr);
927
- const success = await withRetry(async () => {
928
- return await this.ctx.broadcast(wordcloudAndLiveSummaryArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [content[0], content[1]] }));
948
+ await withRetry(async () => {
949
+ return await this.pushMessage(wordcloudAndLiveSummaryArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [content[0], content[1]] }));
929
950
  }, 1);
930
- this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
931
951
  }
932
952
  if (wordcloudOnlyArr.length > 0) {
933
953
  this.logger.info("词云");
934
954
  this.logger.info(wordcloudOnlyArr);
935
- const success = await withRetry(async () => {
936
- return await this.ctx.broadcast(wordcloudOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[0] }));
955
+ await withRetry(async () => {
956
+ return await this.pushMessage(wordcloudOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[0] }));
937
957
  }, 1);
938
- this.logger.info(`成功推送词云消息:${success.length}条`);
939
958
  }
940
959
  if (liveSummaryOnlyArr.length > 0) {
941
960
  this.logger.info("直播总结");
942
961
  this.logger.info(liveSummaryOnlyArr);
943
- const success = await withRetry(async () => {
944
- return await this.ctx.broadcast(liveSummaryOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[1] }));
962
+ await withRetry(async () => {
963
+ return await this.pushMessage(liveSummaryOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[1] }));
945
964
  }, 1);
946
- this.logger.info(`成功推送直播总结消息:${success.length}条`);
947
965
  }
948
966
  }
949
967
  }
package/lib/index.mjs CHANGED
@@ -759,8 +759,14 @@ var ComRegister = class {
759
759
  return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
760
760
  }
761
761
  async sendPrivateMsg(content) {
762
- if (this.config.master.enable) if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
763
- else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
762
+ if (this.config.master.enable) {
763
+ if (this.privateBot.status !== Universal.Status.ONLINE) {
764
+ this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
765
+ return;
766
+ }
767
+ if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
768
+ else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
769
+ }
764
770
  }
765
771
  async sendPrivateMsgAndRebootService() {
766
772
  if (this.rebootCount >= 3) {
@@ -842,59 +848,74 @@ var ComRegister = class {
842
848
  this.logger.info("初始化推送群组/频道信息:");
843
849
  this.logger.info(this.pushArrMap);
844
850
  }
845
- checkAllBotsAreReady() {
846
- return !this.ctx.bots.some((bot) => bot.status !== Universal.Status.ONLINE);
847
- }
848
- async broadcastToTargets(uid, content, type, retry = 3e3) {
849
- if (!this.checkAllBotsAreReady()) {
850
- this.logger.error(`存在机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
851
- this.ctx.setTimeout(() => {
852
- this.broadcastToTargets(uid, content, type, retry * 2);
853
- }, retry);
854
- return;
851
+ async pushMessage(targets, content, retry = 3e3) {
852
+ const t = {};
853
+ for (const target of targets) {
854
+ const [platform, channleId] = target.split(":");
855
+ if (!t[platform]) t[platform] = [channleId];
856
+ else t[platform].push(channleId);
855
857
  }
858
+ for (const platform of Object.keys(t)) {
859
+ const bots = [];
860
+ for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
861
+ botloop: for (const bot of bots) {
862
+ if (bot.status !== Universal.Status.ONLINE) {
863
+ this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
864
+ this.ctx.setTimeout(async () => {
865
+ await this.pushMessage(targets, retry * 2);
866
+ }, retry);
867
+ return;
868
+ }
869
+ let num = 0;
870
+ for (const channelId of t[platform]) try {
871
+ await bot.sendMessage(channelId, content);
872
+ num++;
873
+ } catch (e) {
874
+ this.logger.error(e);
875
+ if (bots.length > 1) continue botloop;
876
+ }
877
+ this.logger.info(`成功推送消息 ${num} 条`);
878
+ }
879
+ }
880
+ }
881
+ async broadcastToTargets(uid, content, type) {
856
882
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
857
883
  const record = this.pushArrMap.get(uid);
858
884
  this.logger.info("本次推送目标:");
859
885
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length >= 1) {
860
886
  this.logger.info(record.liveAtAllArr);
861
887
  const atAllArr = structuredClone(record.liveAtAllArr);
862
- const success = await withRetry(async () => {
863
- return await this.ctx.broadcast(atAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
888
+ await withRetry(async () => {
889
+ return await this.pushMessage(atAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
864
890
  }, 1);
865
- this.logger.info(`成功推送全体成员消息:${success.length}条`);
866
891
  }
867
892
  if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
868
893
  if (record.dynamicAtAllArr?.length >= 1) {
869
894
  this.logger.info(record.dynamicAtAllArr);
870
895
  const dynamicAtAllArr = structuredClone(record.dynamicAtAllArr);
871
- const success$1 = await withRetry(async () => {
872
- return await this.ctx.broadcast(dynamicAtAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
896
+ await withRetry(async () => {
897
+ return await this.pushMessage(dynamicAtAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
873
898
  }, 1);
874
- this.logger.info(`成功推送全体成员消息:${success$1.length}条`);
875
899
  }
876
900
  this.logger.info(record.dynamicArr);
877
901
  const dynamicArr = structuredClone(record.dynamicArr);
878
- const success = await withRetry(async () => {
879
- return await this.ctx.broadcast(dynamicArr, /* @__PURE__ */ jsx("message", { children: content }));
902
+ await withRetry(async () => {
903
+ return await this.pushMessage(dynamicArr, /* @__PURE__ */ jsx("message", { children: content }));
880
904
  }, 1);
881
- this.logger.info(`成功推送动态消息:${success.length}条`);
882
905
  }
883
906
  if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
884
907
  this.logger.info(record.liveArr);
885
908
  const liveArr = structuredClone(record.liveArr);
886
- const success = await withRetry(async () => {
887
- return await this.ctx.broadcast(liveArr, /* @__PURE__ */ jsx("message", { children: content }));
909
+ await withRetry(async () => {
910
+ return await this.pushMessage(liveArr, /* @__PURE__ */ jsx("message", { children: content }));
888
911
  }, 1);
889
- this.logger.info(`成功推送直播消息:${success.length}条`);
890
912
  }
891
913
  if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
892
914
  this.logger.info(record.liveGuardBuyArr);
893
915
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
894
- const success = await withRetry(async () => {
895
- return await this.ctx.broadcast(liveGuardBuyArr, /* @__PURE__ */ jsx("message", { children: content }));
916
+ await withRetry(async () => {
917
+ return await this.pushMessage(liveGuardBuyArr, /* @__PURE__ */ jsx("message", { children: content }));
896
918
  }, 1);
897
- this.logger.info(`成功推送上舰消息:${success.length}条`);
898
919
  }
899
920
  if (type === PushType.WordCloudAndLiveSummary) {
900
921
  const wordcloudArr = structuredClone(record.wordcloudArr);
@@ -905,26 +926,23 @@ var ComRegister = class {
905
926
  if (wordcloudAndLiveSummaryArr.length > 0) {
906
927
  this.logger.info("词云和直播总结");
907
928
  this.logger.info(wordcloudAndLiveSummaryArr);
908
- const success = await withRetry(async () => {
909
- return await this.ctx.broadcast(wordcloudAndLiveSummaryArr, /* @__PURE__ */ jsxs("message", { children: [content[0], content[1]] }));
929
+ await withRetry(async () => {
930
+ return await this.pushMessage(wordcloudAndLiveSummaryArr, /* @__PURE__ */ jsxs("message", { children: [content[0], content[1]] }));
910
931
  }, 1);
911
- this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
912
932
  }
913
933
  if (wordcloudOnlyArr.length > 0) {
914
934
  this.logger.info("词云");
915
935
  this.logger.info(wordcloudOnlyArr);
916
- const success = await withRetry(async () => {
917
- return await this.ctx.broadcast(wordcloudOnlyArr, /* @__PURE__ */ jsx("message", { children: content[0] }));
936
+ await withRetry(async () => {
937
+ return await this.pushMessage(wordcloudOnlyArr, /* @__PURE__ */ jsx("message", { children: content[0] }));
918
938
  }, 1);
919
- this.logger.info(`成功推送词云消息:${success.length}条`);
920
939
  }
921
940
  if (liveSummaryOnlyArr.length > 0) {
922
941
  this.logger.info("直播总结");
923
942
  this.logger.info(liveSummaryOnlyArr);
924
- const success = await withRetry(async () => {
925
- return await this.ctx.broadcast(liveSummaryOnlyArr, /* @__PURE__ */ jsx("message", { children: content[1] }));
943
+ await withRetry(async () => {
944
+ return await this.pushMessage(liveSummaryOnlyArr, /* @__PURE__ */ jsx("message", { children: content[1] }));
926
945
  }, 1);
927
- this.logger.info(`成功推送直播总结消息:${success.length}条`);
928
946
  }
929
947
  }
930
948
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.3.3",
4
+ "version": "3.3.4-alpha.1",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -334,6 +334,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
334
334
  > - ver 3.3.1 优化:如果不订阅UP主直播且未填写房间号不再请求用户接口;
335
335
  > - ver 3.3.2 修复:当插件因动态报错停止后,应使用指令 `bn start` 启动插件,而不是 `bn restart`;
336
336
  > - ver 3.3.3 优化:初始化logger输出; 修复:B站订阅操作bug;
337
+ > - ver 3.3.4-alpha.0 优化:在错误消息向主人帐号推送前会先进行机器人状态判断; 重构:部分重构消息发送逻辑;
338
+ > - ver 3.3.4-alpha.1 修复CI错误;
337
339
 
338
340
  ## 交流群
339
341