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

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.d.mts CHANGED
@@ -61,7 +61,6 @@ type Channel = {
61
61
  liveGuardBuy: boolean;
62
62
  wordcloud: boolean;
63
63
  liveSummary: boolean;
64
- bot: string;
65
64
  };
66
65
  type ChannelArr = Array<Channel>;
67
66
  type TargetItem = {
package/lib/index.d.ts CHANGED
@@ -61,7 +61,6 @@ type Channel = {
61
61
  liveGuardBuy: boolean;
62
62
  wordcloud: boolean;
63
63
  liveSummary: boolean;
64
- bot: string;
65
64
  };
66
65
  type ChannelArr = Array<Channel>;
67
66
  type TargetItem = {
package/lib/index.js CHANGED
@@ -751,8 +751,7 @@ var ComRegister = class {
751
751
  liveAtAll: s.liveAtAll,
752
752
  liveGuardBuy: s.liveGuardBuy,
753
753
  wordcloud: s.wordcloud,
754
- liveSummary: s.liveSummary,
755
- bot: null
754
+ liveSummary: s.liveSummary
756
755
  }));
757
756
  const target = [{
758
757
  channelArr,
@@ -779,7 +778,7 @@ var ComRegister = class {
779
778
  }
780
779
  async sendPrivateMsg(content) {
781
780
  if (this.config.master.enable) {
782
- if (this.privateBot.status !== koishi.Universal.Status.ONLINE) {
781
+ if (this.privateBot?.status !== koishi.Universal.Status.ONLINE) {
783
782
  this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
784
783
  return;
785
784
  }
@@ -846,13 +845,16 @@ var ComRegister = class {
846
845
  const liveSummaryArr = [];
847
846
  for (const platform of sub.target) for (const channel of platform.channelArr) {
848
847
  const target = `${platform.platform}:${channel.channelId}`;
849
- if (channel.dynamic) dynamicArr.push(target);
850
- if (channel.dynamicAtAll) dynamicAtAllArr.push(target);
851
- if (channel.live) liveArr.push(target);
852
- if (channel.liveAtAll) liveAtAllArr.push(target);
853
- if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
854
- if (channel.wordcloud) wordcloudArr.push(target);
855
- if (channel.liveSummary) liveSummaryArr.push(target);
848
+ const conditions = [
849
+ ["dynamic", dynamicArr],
850
+ ["dynamicAtAll", dynamicAtAllArr],
851
+ ["live", liveArr],
852
+ ["liveAtAll", liveAtAllArr],
853
+ ["liveGuardBuy", liveGuardBuyArr],
854
+ ["wordcloud", wordcloudArr],
855
+ ["liveSummary", liveSummaryArr]
856
+ ];
857
+ for (const [key, arr] of conditions) if (channel[key]) arr.push(target);
856
858
  }
857
859
  this.pushArrMap.set(sub.uid, {
858
860
  dynamicArr,
@@ -877,24 +879,26 @@ var ComRegister = class {
877
879
  for (const platform of Object.keys(t)) {
878
880
  const bots = [];
879
881
  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
+ let num = 0;
883
+ const sendMessageByBot = async (channelId, botIndex = 0) => {
884
+ if (bots[botIndex].status !== koishi.Universal.Status.ONLINE) {
882
885
  this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
883
886
  this.ctx.setTimeout(async () => {
884
- await this.pushMessage(targets, retry * 2);
887
+ await this.pushMessage(targets, content, retry * 2);
885
888
  }, retry);
886
889
  return;
887
890
  }
888
- let num = 0;
889
- for (const channelId of t[platform]) try {
890
- await bot.sendMessage(channelId, content);
891
+ try {
892
+ await bots[botIndex].sendMessage(channelId, content);
891
893
  num++;
894
+ await this.ctx.sleep(500);
892
895
  } catch (e) {
893
896
  this.logger.error(e);
894
- if (bots.length > 1) continue botloop;
897
+ if (bots.length > 1) await sendMessageByBot(channelId, botIndex++);
895
898
  }
896
- this.logger.info(`成功推送消息 ${num} 条`);
897
- }
899
+ };
900
+ for (const channelId of t[platform]) await sendMessageByBot(channelId);
901
+ this.logger.info(`成功推送消息 ${num} 条`);
898
902
  }
899
903
  }
900
904
  async broadcastToTargets(uid, content, type) {
package/lib/index.mjs CHANGED
@@ -732,8 +732,7 @@ var ComRegister = class {
732
732
  liveAtAll: s.liveAtAll,
733
733
  liveGuardBuy: s.liveGuardBuy,
734
734
  wordcloud: s.wordcloud,
735
- liveSummary: s.liveSummary,
736
- bot: null
735
+ liveSummary: s.liveSummary
737
736
  }));
738
737
  const target = [{
739
738
  channelArr,
@@ -760,7 +759,7 @@ var ComRegister = class {
760
759
  }
761
760
  async sendPrivateMsg(content) {
762
761
  if (this.config.master.enable) {
763
- if (this.privateBot.status !== Universal.Status.ONLINE) {
762
+ if (this.privateBot?.status !== Universal.Status.ONLINE) {
764
763
  this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
765
764
  return;
766
765
  }
@@ -827,13 +826,16 @@ var ComRegister = class {
827
826
  const liveSummaryArr = [];
828
827
  for (const platform of sub.target) for (const channel of platform.channelArr) {
829
828
  const target = `${platform.platform}:${channel.channelId}`;
830
- if (channel.dynamic) dynamicArr.push(target);
831
- if (channel.dynamicAtAll) dynamicAtAllArr.push(target);
832
- if (channel.live) liveArr.push(target);
833
- if (channel.liveAtAll) liveAtAllArr.push(target);
834
- if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
835
- if (channel.wordcloud) wordcloudArr.push(target);
836
- if (channel.liveSummary) liveSummaryArr.push(target);
829
+ const conditions = [
830
+ ["dynamic", dynamicArr],
831
+ ["dynamicAtAll", dynamicAtAllArr],
832
+ ["live", liveArr],
833
+ ["liveAtAll", liveAtAllArr],
834
+ ["liveGuardBuy", liveGuardBuyArr],
835
+ ["wordcloud", wordcloudArr],
836
+ ["liveSummary", liveSummaryArr]
837
+ ];
838
+ for (const [key, arr] of conditions) if (channel[key]) arr.push(target);
837
839
  }
838
840
  this.pushArrMap.set(sub.uid, {
839
841
  dynamicArr,
@@ -858,24 +860,26 @@ var ComRegister = class {
858
860
  for (const platform of Object.keys(t)) {
859
861
  const bots = [];
860
862
  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
+ let num = 0;
864
+ const sendMessageByBot = async (channelId, botIndex = 0) => {
865
+ if (bots[botIndex].status !== Universal.Status.ONLINE) {
863
866
  this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
864
867
  this.ctx.setTimeout(async () => {
865
- await this.pushMessage(targets, retry * 2);
868
+ await this.pushMessage(targets, content, retry * 2);
866
869
  }, retry);
867
870
  return;
868
871
  }
869
- let num = 0;
870
- for (const channelId of t[platform]) try {
871
- await bot.sendMessage(channelId, content);
872
+ try {
873
+ await bots[botIndex].sendMessage(channelId, content);
872
874
  num++;
875
+ await this.ctx.sleep(500);
873
876
  } catch (e) {
874
877
  this.logger.error(e);
875
- if (bots.length > 1) continue botloop;
878
+ if (bots.length > 1) await sendMessageByBot(channelId, botIndex++);
876
879
  }
877
- this.logger.info(`成功推送消息 ${num} 条`);
878
- }
880
+ };
881
+ for (const channelId of t[platform]) await sendMessageByBot(channelId);
882
+ this.logger.info(`成功推送消息 ${num} 条`);
879
883
  }
880
884
  }
881
885
  async broadcastToTargets(uid, content, type) {
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.4-alpha.1",
4
+ "version": "3.3.4-alpha.3",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -335,7 +335,9 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
335
335
  > - ver 3.3.2 修复:当插件因动态报错停止后,应使用指令 `bn start` 启动插件,而不是 `bn restart`;
336
336
  > - ver 3.3.3 优化:初始化logger输出; 修复:B站订阅操作bug;
337
337
  > - ver 3.3.4-alpha.0 优化:在错误消息向主人帐号推送前会先进行机器人状态判断; 重构:部分重构消息发送逻辑;
338
- > - ver 3.3.4-alpha.1 修复CI错误;
338
+ > - ver 3.3.4-alpha.1 修复: CI错误;
339
+ > - ver 3.3.4-alpha.2 修复: 推送消息时发送6000的bug;
340
+ > - ver 3.3.4-alpha.3 修复: 相同平台多个机器人可能造成消息重复推送、错误信息推送机器人未初始化完毕推送时会报错;
339
341
 
340
342
  ## 交流群
341
343