koishi-plugin-bilibili-notify 3.1.0 → 3.1.1-alpha.0

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.
@@ -73,7 +73,6 @@ declare namespace ComRegister {
73
73
  masterAccount: string;
74
74
  masterAccountGuildId: string;
75
75
  };
76
- liveDetectMode: "API" | "WS";
77
76
  restartPush: boolean;
78
77
  pushTime: number;
79
78
  pushImgsInDynamic: boolean;
@@ -492,7 +492,7 @@ class ComRegister {
492
492
  // 延迟发送
493
493
  await this.ctx.sleep(500);
494
494
  }
495
- }
495
+ },
496
496
  };
497
497
  // 推送
498
498
  await pushTypePatternMatching[type]();
@@ -604,67 +604,71 @@ class ComRegister {
604
604
  // 动态ID如果一致则结束循环
605
605
  if (dynamicId === dynamicIdStr1st)
606
606
  break;
607
- // 判断动态时间戳是否大于时间线
608
- if (item.modules.module_author.pub_ts > timeline) {
609
- // 从动态数据中取出UP主名称、UID
610
- const upUID = item.modules.module_author.mid.toString();
611
- const upName = item.modules.module_author.name;
612
- // 寻找关注的UP主的动态
613
- for (const sub of this.subManager) {
614
- // 判断是否是订阅的UP主
615
- if (sub.uid === upUID && sub.dynamic) {
616
- // 订阅该UP主,推送该动态
617
- // 推送该条动态
618
- const buffer = await (0, utils_1.withRetry)(async () => {
619
- // 渲染图片
620
- return await this.ctx.gi.generateDynamicImg(item, sub.card);
621
- }, 1).catch(async (e) => {
622
- // 直播开播动态,不做处理
623
- if (e.message === "直播开播动态,不做处理")
624
- return;
625
- if (e.message === "出现关键词,屏蔽该动态") {
626
- // 如果需要发送才发送
627
- if (this.config.filter.notify) {
628
- await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
629
- }
630
- return;
607
+ // 获取动态发布时间
608
+ const postTime = item.modules.module_author.pub_ts;
609
+ // timeline已超过或与当前动态时间戳相同,则后面的动态不需要推送
610
+ if (postTime <= timeline)
611
+ break;
612
+ // 从动态数据中取出UP主名称、UID
613
+ const upUID = item.modules.module_author.mid.toString();
614
+ const upName = item.modules.module_author.name;
615
+ // 寻找关注的UP主的动态
616
+ for (const sub of this.subManager) {
617
+ // 判断是否是订阅的UP主
618
+ if (sub.dynamic && sub.uid === upUID) {
619
+ // 推送该条动态
620
+ const buffer = await (0, utils_1.withRetry)(async () => {
621
+ // 渲染图片
622
+ return await this.ctx.gi.generateDynamicImg(item, sub.card);
623
+ }, 1).catch(async (e) => {
624
+ // 直播开播动态,不做处理
625
+ if (e.message === "直播开播动态,不做处理")
626
+ return;
627
+ if (e.message === "出现关键词,屏蔽该动态") {
628
+ // 如果需要发送才发送
629
+ if (this.config.filter.notify) {
630
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
631
631
  }
632
- if (e.message === "已屏蔽转发动态") {
633
- if (this.config.filter.notify) {
634
- await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
635
- }
636
- return;
632
+ return;
633
+ }
634
+ if (e.message === "已屏蔽转发动态") {
635
+ if (this.config.filter.notify) {
636
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
637
637
  }
638
- // 未知错误
639
- this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
640
- // 发送私聊消息并重启服务
641
- await this.sendPrivateMsgAndStopService();
642
- });
643
- // 判断是否执行成功,未执行成功直接返回
644
- if (!buffer)
645
- continue;
646
- // 判断是否需要发送URL
647
- const dUrl = this.config.dynamicUrl
648
- ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
649
- : "";
650
- // logger
651
- this.logger.info("推送动态中...");
652
- // 发送推送卡片
653
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
654
- // 判断是否需要发送动态中的图片
655
- if (this.config.pushImgsInDynamic) {
656
- // 判断是否为图文动态,且存在draw
657
- if (item.type === "DYNAMIC_TYPE_DRAW" &&
658
- item.modules.module_dynamic.major?.draw) {
659
- for (const img of item.modules.module_dynamic.major.draw
660
- .items) {
661
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
662
- }
638
+ return;
639
+ }
640
+ // 未知错误
641
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
642
+ // 发送私聊消息并重启服务
643
+ await this.sendPrivateMsgAndStopService();
644
+ });
645
+ // 判断是否执行成功,未执行成功直接返回
646
+ if (!buffer)
647
+ continue;
648
+ // 定义动态链接
649
+ let dUrl = "";
650
+ // 判断是否需要发送URL
651
+ if (this.config.dynamicUrl) {
652
+ // 生成动态链接
653
+ dUrl = `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`;
654
+ }
655
+ // logger
656
+ this.logger.info("推送动态中...");
657
+ // 发送推送卡片
658
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
659
+ // 判断是否需要发送动态中的图片
660
+ if (this.config.pushImgsInDynamic) {
661
+ // 判断是否为图文动态,且存在draw
662
+ if (item.type === "DYNAMIC_TYPE_DRAW" &&
663
+ item.modules.module_dynamic.major?.draw) {
664
+ for (const img of item.modules.module_dynamic.major.draw
665
+ .items) {
666
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
663
667
  }
664
668
  }
665
- // logger
666
- this.logger.info("动态推送完毕!");
667
669
  }
670
+ // logger
671
+ this.logger.info("动态推送完毕!");
668
672
  }
669
673
  }
670
674
  }
@@ -812,93 +816,104 @@ class ComRegister {
812
816
  this.logger.info("动态ID与上一次获取第一条一致,结束循环");
813
817
  break;
814
818
  }
819
+ // 获取动态发布时间
820
+ const postTime = item.modules.module_author.pub_ts;
821
+ // logger
822
+ this.logger.info(`当前动态时间线:${postTime}`);
815
823
  // logger
816
- this.logger.info(`当前动态时间线:${item.modules.module_author.pub_ts}`);
817
824
  this.logger.info(`上一次获取到第一条动态时间线:${timeline}`);
818
- // 判断动态时间戳是否大于时间线
819
- if (item.modules.module_author.pub_ts > timeline) {
820
- // logger
821
- this.logger.info("动态时间线大于上一次获取到第一条动态时间线,开始判断是否是订阅的UP主...");
822
- // 从动态数据中取出UP主名称、UID
823
- const upUID = item.modules.module_author.mid.toString();
824
- const upName = item.modules.module_author.name;
825
+ // logger
826
+ this.logger.info(`当前动态发布时间:${luxon_1.DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
827
+ // logger
828
+ this.logger.info(`上一次获取到第一条动态发布时间:${luxon_1.DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
829
+ // timeline已超过或与当前动态时间戳相同,则后面的动态不需要推送
830
+ if (postTime <= timeline) {
825
831
  // logger
826
- this.logger.info(`当前动态UP主UID:${upUID},UP主名称:${upName}`);
827
- // 寻找关注的UP主的动态
828
- for (const sub of this.subManager) {
829
- // 判断是否是订阅的UP主
830
- if (sub.dynamic && sub.uid === upUID) {
831
- // logger:订阅该UP主,推送该动态
832
- this.logger.info("订阅该UP主,开始推送该动态...");
833
- // logger
834
- this.logger.info("开始生成推送卡片...");
835
- // 推送该条动态
836
- const buffer = await (0, utils_1.withRetry)(async () => {
837
- // 渲染图片
838
- return await this.ctx.gi.generateDynamicImg(item, sub.card);
839
- }, 1).catch(async (e) => {
840
- // 直播开播动态,不做处理
841
- if (e.message === "直播开播动态,不做处理")
842
- return;
843
- if (e.message === "出现关键词,屏蔽该动态") {
844
- // 如果需要发送才发送
845
- if (this.config.filter.notify) {
846
- await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
847
- }
848
- return;
849
- }
850
- if (e.message === "已屏蔽转发动态") {
851
- if (this.config.filter.notify) {
852
- await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
853
- }
854
- return;
832
+ this.logger.info("当前动态时间戳已小于等于上一次获取到第一条动态时间线,更晚发布的动态无需监测");
833
+ // 结束本次监测
834
+ break;
835
+ }
836
+ // logger
837
+ this.logger.info("动态时间线大于上一次获取到第一条动态时间线,开始判断是否是订阅的UP主...");
838
+ // 从动态数据中取出UP主名称、UID
839
+ const upUID = item.modules.module_author.mid.toString();
840
+ const upName = item.modules.module_author.name;
841
+ // logger
842
+ this.logger.info(`当前动态UP主UID:${upUID},UP主名称:${upName}`);
843
+ // 寻找关注的UP主的动态
844
+ for (const sub of this.subManager) {
845
+ // 判断是否是订阅的UP主
846
+ if (sub.dynamic && sub.uid === upUID) {
847
+ // logger:订阅该UP主,推送该动态
848
+ this.logger.info("订阅该UP主,开始推送该动态...");
849
+ // logger
850
+ this.logger.info("开始生成推送卡片...");
851
+ // 推送该条动态
852
+ const buffer = await (0, utils_1.withRetry)(async () => {
853
+ // 渲染图片
854
+ return await this.ctx.gi.generateDynamicImg(item, sub.card);
855
+ }, 1).catch(async (e) => {
856
+ // 直播开播动态,不做处理
857
+ if (e.message === "直播开播动态,不做处理")
858
+ return;
859
+ if (e.message === "出现关键词,屏蔽该动态") {
860
+ // 如果需要发送才发送
861
+ if (this.config.filter.notify) {
862
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
855
863
  }
856
- // 未知错误
857
- this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
858
- // 发送私聊消息并重启服务
859
- await this.sendPrivateMsgAndStopService();
860
- });
861
- // 判断是否执行成功,未执行成功直接返回
862
- if (!buffer) {
863
- // logger
864
- this.logger.info("推送卡片生成失败,或该动态为屏蔽动态,跳过该动态!");
865
- // 结束循环
866
- continue;
864
+ return;
867
865
  }
868
- // 定义动态链接
869
- let dUrl = "";
870
- // 判断是否需要发送URL
871
- if (this.config.dynamicUrl) {
872
- // logger
873
- this.logger.info("生成动态链接中...");
874
- // 生成动态链接
875
- dUrl = `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`;
866
+ if (e.message === "已屏蔽转发动态") {
867
+ if (this.config.filter.notify) {
868
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
869
+ }
870
+ return;
876
871
  }
872
+ // 未知错误
873
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
874
+ // 发送私聊消息并重启服务
875
+ await this.sendPrivateMsgAndStopService();
876
+ });
877
+ // 判断是否执行成功,未执行成功直接返回
878
+ if (!buffer) {
877
879
  // logger
878
- this.logger.info("推送动态中...");
879
- // 发送推送卡片
880
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
880
+ this.logger.info("推送卡片生成失败,或该动态为屏蔽动态,跳过该动态!");
881
+ // 结束循环
882
+ continue;
883
+ }
884
+ // 定义动态链接
885
+ let dUrl = "";
886
+ // 判断是否需要发送URL
887
+ if (this.config.dynamicUrl) {
888
+ // logger
889
+ this.logger.info("生成动态链接中...");
890
+ // 生成动态链接
891
+ dUrl = `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`;
892
+ }
893
+ // logger
894
+ this.logger.info("推送动态中...");
895
+ // 发送推送卡片
896
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
897
+ // 判断是否需要发送动态中的图片
898
+ if (this.config.pushImgsInDynamic) {
881
899
  // logger
882
- this.logger.info("动态推送完毕!");
883
- // 判断是否需要发送动态中的图片
884
- if (this.config.pushImgsInDynamic) {
885
- // logger
886
- this.logger.info("开始推送动态中的图片...");
887
- // 判断是否为图文动态,且存在draw
888
- if (item.type === "DYNAMIC_TYPE_DRAW" &&
889
- item.modules.module_dynamic.major?.draw) {
890
- for (const img of item.modules.module_dynamic.major.draw
891
- .items) {
892
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
893
- }
900
+ this.logger.info("开始推送动态中的图片...");
901
+ // 判断是否为图文动态,且存在draw
902
+ if (item.type === "DYNAMIC_TYPE_DRAW" &&
903
+ item.modules.module_dynamic.major?.draw) {
904
+ for (const img of item.modules.module_dynamic.major.draw
905
+ .items) {
906
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
894
907
  }
895
- // logger
896
- this.logger.info("图片推送完毕!");
897
908
  }
898
909
  // logger
899
- this.logger.info("动态推送完毕!");
910
+ this.logger.info("图片推送完毕!");
900
911
  }
912
+ // logger
913
+ this.logger.info("动态推送完毕!");
901
914
  }
915
+ // logger
916
+ this.logger.info("不是关注的UP主,跳过该动态");
902
917
  }
903
918
  }
904
919
  // 更新本次请求第一条动态的动态ID
@@ -910,6 +925,10 @@ class ComRegister {
910
925
  items[0].modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
911
926
  // logger
912
927
  this.logger.info(`更新时间线:${timeline}`);
928
+ // logger
929
+ this.logger.info(`时间线格式化:${luxon_1.DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
930
+ // logger
931
+ this.logger.info("动态监测完成,等待下一次检测...");
913
932
  };
914
933
  // 返回一个闭包函数
915
934
  return (0, utils_1.withLock)(handler);
@@ -998,7 +1017,9 @@ class ComRegister {
998
1017
  // 推送直播信息
999
1018
  const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
1000
1019
  // 只有在开播时才艾特全体成员
1001
- return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting ? type_1.PushType.StartBroadcasting : type_1.PushType.Live);
1020
+ return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting
1021
+ ? type_1.PushType.StartBroadcasting
1022
+ : type_1.PushType.Live);
1002
1023
  };
1003
1024
  // 找到频道/群组对应的
1004
1025
  const liveGuardBuyPushTargetArr = target.map((channel) => {
@@ -1552,10 +1573,6 @@ class ComRegister {
1552
1573
  masterAccount: koishi_1.Schema.string(),
1553
1574
  masterAccountGuildId: koishi_1.Schema.string(),
1554
1575
  }),
1555
- liveDetectMode: koishi_1.Schema.union([
1556
- koishi_1.Schema.const("API"),
1557
- koishi_1.Schema.const("WS"),
1558
- ]).required(),
1559
1576
  restartPush: koishi_1.Schema.boolean().required(),
1560
1577
  pushTime: koishi_1.Schema.number().required(),
1561
1578
  pushImgsInDynamic: koishi_1.Schema.boolean().required(),
package/lib/index.d.ts CHANGED
@@ -44,7 +44,6 @@ export interface Config {
44
44
  dynamicUrl: boolean;
45
45
  pushImgsInDynamic: boolean;
46
46
  live: {};
47
- liveDetectMode: "API" | "WS";
48
47
  restartPush: boolean;
49
48
  pushTime: number;
50
49
  customLiveStart: string;
package/lib/index.js CHANGED
@@ -127,7 +127,6 @@ class ServerManager extends koishi_1.Service {
127
127
  subLoadTimeout: globalConfig.subLoadTimeout,
128
128
  sub: globalConfig.sub,
129
129
  master: globalConfig.master,
130
- liveDetectMode: globalConfig.liveDetectMode,
131
130
  restartPush: globalConfig.restartPush,
132
131
  pushTime: globalConfig.pushTime,
133
132
  pushImgsInDynamic: globalConfig.pushImgsInDynamic,
@@ -325,15 +324,6 @@ exports.Config = koishi_1.Schema.object({
325
324
  .default(false)
326
325
  .description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片"),
327
326
  live: koishi_1.Schema.object({}).description("直播推送设置"),
328
- liveDetectMode: koishi_1.Schema.union([
329
- koishi_1.Schema.const("WS").description("WebSocket模式:连接到对应的直播间,可推送弹幕消息,开播下播响应最快,但对订阅数有限制"),
330
- koishi_1.Schema.const("API")
331
- .description("API模式:请求对应直播间API,无法获取弹幕消息,开播下播响应慢,理论可无限订阅")
332
- .deprecated(),
333
- ])
334
- .role("radio")
335
- .description("直播检测模式")
336
- .default("WS"),
337
327
  restartPush: koishi_1.Schema.boolean()
338
328
  .default(true)
339
329
  .description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
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.1.0",
4
+ "version": "3.1.1-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -233,6 +233,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
233
233
  - ver 3.1.0-alpha.0 修复:新插件在第一次订阅时提示 `订阅失败,错误信息:该分组已经存在`; 移除:消息重发功能; 重构:将消息发送模式改为 `broadcast`
234
234
  - ver 3.1.0-alpha.1 修复:无法发送 `@全体成员` 消息,将消息发送模式改回
235
235
  - ver 3.1.0 修复:订阅某位UP主直播和动态后,某些群聊只开启推送直播也会推送动态
236
+ - ver 3.1.1-alpha.0 修复:稿件重投后,会将之前日期的动态一起推送; 优化:加强动态debug输出; 移除:不必要选项 `live.liveDetectMode`
236
237
 
237
238
  ## 交流群
238
239