koishi-plugin-bilibili-notify 1.2.3-rc.5 → 1.2.3-rc.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.
@@ -28,9 +28,9 @@ declare class ComRegister {
28
28
  constructor(ctx: Context, config: ComRegister.Config);
29
29
  getTheCorrespondingBotBasedOnTheSession(session: Session): Bot<Context, any>;
30
30
  sendPrivateMsg(bot: Bot<Context>, content: string): Promise<void>;
31
- sendPrivateMsgAndRebootService(bot: Bot<Context>, ctx: Context, content: string): Promise<void>;
31
+ sendPrivateMsgAndRebootService(ctx: Context, bot: Bot<Context>, content: string): Promise<void>;
32
+ sendMsg(ctx: Context, targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
32
33
  dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
33
- sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<string[]>;
34
34
  liveDetect(ctx: Context, bot: Bot<Context>, roomId: string, guildId: Array<string>): () => Promise<void>;
35
35
  subShow(): string;
36
36
  checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
@@ -636,7 +636,7 @@ class ComRegister {
636
636
  // 获得对应bot
637
637
  const bot = this.getTheCorrespondingBotBasedOnTheSession(session);
638
638
  // 发送提示消息,重启服务
639
- await this.sendPrivateMsgAndRebootService(bot, ctx, '测试biliAPI等服务自动重启功能');
639
+ await this.sendPrivateMsgAndRebootService(ctx, bot, '测试biliAPI等服务自动重启功能');
640
640
  });
641
641
  biliCom
642
642
  .subcommand('.sendall', '测试给机器人加入的所有群发送消息', { hidden: true })
@@ -646,7 +646,7 @@ class ComRegister {
646
646
  // 获得对应bot
647
647
  const bot = this.getTheCorrespondingBotBasedOnTheSession(session);
648
648
  // 发送消息
649
- await this.sendMsg(['all'], bot, 'Hello World');
649
+ await this.sendMsg(ctx, ['all'], bot, 'Hello World');
650
650
  // 发送提示
651
651
  await session.send('已向机器人加入的所有群发送了消息');
652
652
  });
@@ -706,7 +706,7 @@ class ComRegister {
706
706
  }
707
707
  }
708
708
  }
709
- async sendPrivateMsgAndRebootService(bot, ctx, content) {
709
+ async sendPrivateMsgAndRebootService(ctx, bot, content) {
710
710
  await this.sendPrivateMsg(bot, content);
711
711
  // 停用插件
712
712
  ctx.sm.disposePlugin();
@@ -715,6 +715,38 @@ class ComRegister {
715
715
  ctx.sm.registerPlugin();
716
716
  }, 1000);
717
717
  }
718
+ async sendMsg(ctx, targets, bot, content) {
719
+ // 定义需要发送的数组
720
+ let sendArr = [];
721
+ // 判断是否需要推送所有机器人加入的群
722
+ if (targets[0] === 'all') {
723
+ // 获取所有guild
724
+ for (let guild of (await bot.getGuildList()).data) {
725
+ sendArr.push(guild.id);
726
+ }
727
+ }
728
+ else {
729
+ sendArr = targets;
730
+ }
731
+ // 循环给每个群组发送
732
+ for (let guildId of sendArr) {
733
+ // 多次尝试发送消息
734
+ let attempts = 3;
735
+ for (let i = 0; i < attempts; i++) {
736
+ try {
737
+ // 发送消息
738
+ await bot.sendMessage(guildId, content);
739
+ // 防止消息发送速度过快被忽略
740
+ await ctx.sleep(500);
741
+ }
742
+ catch (e) {
743
+ if (i === attempts - 1) { // 已尝试三次
744
+ throw new Error(`发送群组ID:${guildId}消息失败!原因: ` + e.toString());
745
+ }
746
+ }
747
+ }
748
+ }
749
+ }
718
750
  dynamicDetect(ctx, bot, uid, guildId) {
719
751
  let firstSubscription = true;
720
752
  let timePoint;
@@ -782,22 +814,22 @@ class ComRegister {
782
814
  break;
783
815
  if (e.message === '出现关键词,屏蔽该动态') {
784
816
  // 如果需要发送才发送
785
- this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
817
+ this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
786
818
  break;
787
819
  }
788
820
  if (e.message === '已屏蔽转发动态') {
789
- this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
821
+ this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
790
822
  break;
791
823
  }
792
824
  }
793
825
  // 如果pic存在,则直接返回pic
794
826
  if (pic) {
795
827
  // pic存在,使用的是render模式
796
- await this.sendMsg(guildId, bot, pic + dUrl);
828
+ await this.sendMsg(ctx, guildId, bot, pic + dUrl);
797
829
  }
798
830
  else {
799
831
  // pic不存在,说明使用的是page模式
800
- await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
832
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
801
833
  }
802
834
  // 如果成功,那么跳出循环
803
835
  break;
@@ -805,7 +837,7 @@ class ComRegister {
805
837
  catch (e) {
806
838
  this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.toString());
807
839
  if (i === attempts - 1) { // 如果已经尝试了三次,那么抛出错误
808
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
840
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
809
841
  }
810
842
  }
811
843
  }
@@ -823,35 +855,6 @@ class ComRegister {
823
855
  }
824
856
  };
825
857
  }
826
- async sendMsg(targets, bot, content) {
827
- // 定义需要发送的数组
828
- let sendArr = [];
829
- // 判断是否需要推送所有机器人加入的群
830
- if (targets[0] === 'all') {
831
- // 获取所有guild
832
- for (let guild of (await bot.getGuildList()).data) {
833
- sendArr.push(guild.id);
834
- }
835
- }
836
- else {
837
- sendArr = targets;
838
- }
839
- // 循环给每个群组发送
840
- for (let guildId of sendArr) {
841
- // 多次尝试生成图片
842
- let attempts = 3;
843
- for (let i = 0; i < attempts; i++) {
844
- try {
845
- return await bot.sendMessage(guildId, content);
846
- }
847
- catch (e) {
848
- if (i === attempts - 1) { // 已尝试三次
849
- throw new Error(`发送群组ID:${guildId}消息失败!原因: ` + e.toString());
850
- }
851
- }
852
- }
853
- }
854
- }
855
858
  liveDetect(ctx, bot, roomId, guildId) {
856
859
  let firstSubscription = true;
857
860
  let timer = 0;
@@ -870,23 +873,23 @@ class ComRegister {
870
873
  if (!liveStartMsg) {
871
874
  // pic 存在,使用的是render模式
872
875
  if (pic)
873
- return await this.sendMsg(guildId, bot, pic);
876
+ return await this.sendMsg(ctx, guildId, bot, pic);
874
877
  // pic不存在,说明使用的是page模式
875
- await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png'));
878
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
876
879
  }
877
880
  else if (liveStartMsg && atAll) {
878
881
  // pic 存在,使用的是render模式
879
882
  if (pic)
880
- return await this.sendMsg(guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
883
+ return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
881
884
  // pic不存在,说明使用的是page模式
882
- await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
885
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
883
886
  }
884
887
  else {
885
888
  // pic 存在,使用的是render模式
886
889
  if (pic)
887
- return await this.sendMsg(guildId, bot, pic + liveStartMsg);
890
+ return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
888
891
  // pic不存在,说明使用的是page模式
889
- await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
892
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
890
893
  }
891
894
  // 成功则跳出循环
892
895
  break;
@@ -894,7 +897,7 @@ class ComRegister {
894
897
  catch (e) {
895
898
  this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
896
899
  if (i === attempts - 1) { // 已尝试三次
897
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
900
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
898
901
  }
899
902
  }
900
903
  }
@@ -918,7 +921,7 @@ class ComRegister {
918
921
  catch (e) {
919
922
  this.logger.error('liveDetect getLiveRoomInfo 网络请求失败');
920
923
  if (i === attempts - 1) { // 已尝试三次
921
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
924
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
922
925
  }
923
926
  }
924
927
  }
@@ -940,7 +943,7 @@ class ComRegister {
940
943
  catch (e) {
941
944
  this.logger.error('liveDetect getMasterInfo() 本次网络请求失败');
942
945
  if (i === attempts - 1) { // 已尝试三次
943
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
946
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
944
947
  }
945
948
  }
946
949
  }
@@ -971,7 +974,7 @@ class ComRegister {
971
974
  .replace('-name', uData.info.uname)
972
975
  .replace('-time', await ctx.gimg.getTimeDifference(liveTime));
973
976
  // 发送下播通知
974
- await this.sendMsg(guildId, bot, liveEndMsg);
977
+ await this.sendMsg(ctx, guildId, bot, liveEndMsg);
975
978
  }
976
979
  // 未进循环,还未开播,继续循环
977
980
  break;
@@ -996,7 +999,7 @@ class ComRegister {
996
999
  catch (e) {
997
1000
  this.logger.error('liveDetect open getMasterInfo() 网络请求错误');
998
1001
  if (i === attempts - 1) { // 已尝试三次
999
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
1002
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
1000
1003
  }
1001
1004
  }
1002
1005
  }
@@ -1203,7 +1206,7 @@ class ComRegister {
1203
1206
  catch (e) {
1204
1207
  this.logger.error('getSubFromDatabase() getUserInfo() 本次网络请求失败');
1205
1208
  if (i === attempts - 1) { // 已尝试三次
1206
- return await this.sendPrivateMsgAndRebootService(bot, ctx, '你的网络可能出现了某些问题,请检查后重启插件');
1209
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '你的网络可能出现了某些问题,请检查后重启插件');
1207
1210
  }
1208
1211
  }
1209
1212
  }
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": "1.2.3-rc.5",
4
+ "version": "1.2.3-rc.7",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -130,6 +130,8 @@
130
130
  - ver 1.2.3-rc.3 bug测试版本,请跳过
131
131
  - ver 1.2.3-rc.4 bug测试版本,请跳过
132
132
  - ver 1.2.3-rc.5 修复了第一次使用插件时,扫码登录后没有任何反应,并且仍提示没有登录的bug
133
+ - ver 1.2.3-rc.6 bug测试版本,请跳过
134
+ - ver 1.2.3-rc.7 尝试修复多群推送时部分群未推送的bug
133
135
 
134
136
  ## 交流群
135
137