koishi-plugin-bilibili-notify 3.1.0-alpha.0 → 3.1.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.
@@ -1,7 +1,7 @@
1
1
  import { type Bot, type Context, type FlatPick, type Logger, Schema } from "koishi";
2
2
  import type { Notifier } from "@koishijs/plugin-notifier";
3
3
  import type { LoginBili } from "./database";
4
- import { LiveType, type MasterInfo, type SubItem, type SubManager, type Target } from "./type";
4
+ import { LiveType, type MasterInfo, PushType, type SubItem, type SubManager, type Target } from "./type";
5
5
  declare class ComRegister {
6
6
  static inject: string[];
7
7
  qqRelatedBotList: Array<string>;
@@ -23,8 +23,8 @@ declare class ComRegister {
23
23
  sendPrivateMsg(content: string): Promise<void>;
24
24
  sendPrivateMsgAndRebootService(): Promise<void>;
25
25
  sendPrivateMsgAndStopService(): Promise<void>;
26
- sendMessageWithRetry(broadcastTarget: string[], content: any): Promise<void>;
27
- broadcastToTargets(targets: Target, content: any, live?: boolean): Promise<void>;
26
+ sendMessageWithRetry(bot: Bot<Context>, channelId: string, content: any): Promise<void>;
27
+ broadcastToTargets(targets: Target, content: any, type: PushType): Promise<void>;
28
28
  dynamicDetect(): (...args: any[]) => void;
29
29
  debug_dynamicDetect(): (...args: any[]) => void;
30
30
  useMasterInfo(uid: string, masterInfo: MasterInfo, liveType: LiveType): Promise<MasterInfo>;
@@ -50,7 +50,7 @@ declare namespace ComRegister {
50
50
  dynamic: boolean;
51
51
  live: boolean;
52
52
  target: Array<{
53
- channelIdArr: Array<{
53
+ channelArr: Array<{
54
54
  channelId: string;
55
55
  dynamic: boolean;
56
56
  live: boolean;
@@ -339,7 +339,7 @@ class ComRegister {
339
339
  // Test
340
340
  const testTarget = [
341
341
  {
342
- channelIdArr: [
342
+ channelArr: [
343
343
  {
344
344
  channelId: "635762054",
345
345
  dynamic: true,
@@ -405,73 +405,97 @@ class ComRegister {
405
405
  // 结束
406
406
  return;
407
407
  }
408
- async sendMessageWithRetry(broadcastTarget,
408
+ async sendMessageWithRetry(bot, channelId,
409
409
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
410
410
  content) {
411
- (0, utils_1.withRetry)(async () => await this.ctx.broadcast(broadcastTarget, content), 1).catch(async (e) => {
411
+ (0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
412
412
  if (e.message === "this._request is not a function") {
413
413
  // 2S之后重新发送消息
414
414
  this.ctx.setTimeout(async () => {
415
- await this.sendMessageWithRetry(broadcastTarget, content);
415
+ await this.sendMessageWithRetry(bot, channelId, content);
416
416
  }, 2000);
417
417
  // 返回
418
418
  return;
419
419
  }
420
420
  // 打印错误信息
421
- this.logger.error(`发送群组ID:${broadcastTarget[0]}消息失败!原因: ${e.message}`);
422
- await this.sendPrivateMsg(`发送群组ID:${broadcastTarget[0]}消息失败,请查看日志`);
421
+ this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
422
+ await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
423
423
  });
424
424
  }
425
- ;
426
425
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
427
- async broadcastToTargets(targets, content, live) {
426
+ async broadcastToTargets(targets, content, type) {
428
427
  for (const target of targets) {
429
428
  // 获取机器人实例
430
429
  const bot = this.getBot(target.platform);
431
430
  // 定义需要发送的数组
432
- let sendArr = [];
431
+ let channelArr = [];
433
432
  // 判断是否需要推送所有机器人加入的群
434
- if (target.channelIdArr[0].channelId === "all") {
433
+ if (target.channelArr[0].channelId === "all") {
435
434
  // 获取所有guild
436
435
  for (const guild of (await bot.getGuildList()).data) {
437
- sendArr.push({
436
+ channelArr.push({
438
437
  channelId: guild.id,
439
- dynamic: target.channelIdArr[0].dynamic,
440
- live: target.channelIdArr[0].live,
441
- liveGuardBuy: target.channelIdArr[0].liveGuardBuy,
442
- atAll: target.channelIdArr[0].atAll,
438
+ dynamic: target.channelArr[0].dynamic,
439
+ live: target.channelArr[0].live,
440
+ liveGuardBuy: target.channelArr[0].liveGuardBuy,
441
+ atAll: target.channelArr[0].atAll,
443
442
  });
444
443
  }
445
444
  }
446
445
  else {
447
- sendArr = target.channelIdArr;
446
+ channelArr = target.channelArr;
448
447
  }
449
- // 判断是否是直播开播推送,如果是则需要进一步判断是否需要艾特群体成员
450
- if (live) {
451
- // 直播开播推送,判断是否需要艾特全体成员
452
- for (const channel of sendArr) {
453
- // 构建广播目标
454
- const broadcastTarget = [`${target.platform}:${channel.channelId}`];
455
- // 判断是否需要推送直播消息
456
- if (channel.live) {
457
- await this.sendMessageWithRetry(broadcastTarget, content);
448
+ // 模式匹配
449
+ const pushTypePatternMatching = {
450
+ [type_1.PushType.Live]: async () => {
451
+ for (const channel of channelArr) {
452
+ // 判断是否需要推送动态消息
453
+ if (channel.live) {
454
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
455
+ }
456
+ // 延迟发送
457
+ await this.ctx.sleep(500);
458
458
  }
459
- // 判断是否需要艾特全体成员
460
- if (channel.atAll) {
461
- await this.sendMessageWithRetry(broadcastTarget, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
459
+ },
460
+ [type_1.PushType.Dynamic]: async () => {
461
+ for (const channel of channelArr) {
462
+ // 判断是否需要推送动态消息
463
+ if (channel.live) {
464
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
465
+ }
466
+ // 延迟发送
467
+ await this.ctx.sleep(500);
462
468
  }
463
- }
464
- }
465
- else {
466
- for (const channel of sendArr) {
467
- // 构建广播目标
468
- const broadcastTarget = [`${target.platform}:${channel.channelId}`];
469
- // 判断是否需要推送动态消息
470
- if (channel.dynamic || channel.live) {
471
- await this.sendMessageWithRetry(broadcastTarget, content);
469
+ },
470
+ [type_1.PushType.StartBroadcasting]: async () => {
471
+ // 直播开播推送,判断是否需要艾特全体成员
472
+ for (const channel of channelArr) {
473
+ // 判断是否需要推送直播消息
474
+ if (channel.live) {
475
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
476
+ }
477
+ // 判断是否需要艾特全体成员
478
+ if (channel.atAll) {
479
+ await this.sendMessageWithRetry(bot, channel.channelId, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
480
+ }
481
+ // 延迟发送
482
+ await this.ctx.sleep(500);
483
+ }
484
+ },
485
+ [type_1.PushType.LiveGuardBuy]: async () => {
486
+ // 直播守护购买推送,判断是否需要艾特全体成员
487
+ for (const channel of channelArr) {
488
+ // 判断是否需要推送直播消息
489
+ if (channel.liveGuardBuy) {
490
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
491
+ }
492
+ // 延迟发送
493
+ await this.ctx.sleep(500);
472
494
  }
473
495
  }
474
- }
496
+ };
497
+ // 推送
498
+ await pushTypePatternMatching[type]();
475
499
  }
476
500
  }
477
501
  dynamicDetect() {
@@ -588,7 +612,7 @@ class ComRegister {
588
612
  // 寻找关注的UP主的动态
589
613
  for (const sub of this.subManager) {
590
614
  // 判断是否是订阅的UP主
591
- if (sub.dynamic && sub.uid === upUID) {
615
+ if (sub.uid === upUID && sub.dynamic) {
592
616
  // 订阅该UP主,推送该动态
593
617
  // 推送该条动态
594
618
  const buffer = await (0, utils_1.withRetry)(async () => {
@@ -601,13 +625,13 @@ class ComRegister {
601
625
  if (e.message === "出现关键词,屏蔽该动态") {
602
626
  // 如果需要发送才发送
603
627
  if (this.config.filter.notify) {
604
- await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
628
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
605
629
  }
606
630
  return;
607
631
  }
608
632
  if (e.message === "已屏蔽转发动态") {
609
633
  if (this.config.filter.notify) {
610
- await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
634
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
611
635
  }
612
636
  return;
613
637
  }
@@ -626,7 +650,7 @@ class ComRegister {
626
650
  // logger
627
651
  this.logger.info("推送动态中...");
628
652
  // 发送推送卡片
629
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
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);
630
654
  // 判断是否需要发送动态中的图片
631
655
  if (this.config.pushImgsInDynamic) {
632
656
  // 判断是否为图文动态,且存在draw
@@ -634,7 +658,7 @@ class ComRegister {
634
658
  item.modules.module_dynamic.major?.draw) {
635
659
  for (const img of item.modules.module_dynamic.major.draw
636
660
  .items) {
637
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
661
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
638
662
  }
639
663
  }
640
664
  }
@@ -819,13 +843,13 @@ class ComRegister {
819
843
  if (e.message === "出现关键词,屏蔽该动态") {
820
844
  // 如果需要发送才发送
821
845
  if (this.config.filter.notify) {
822
- await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
846
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
823
847
  }
824
848
  return;
825
849
  }
826
850
  if (e.message === "已屏蔽转发动态") {
827
851
  if (this.config.filter.notify) {
828
- await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
852
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
829
853
  }
830
854
  return;
831
855
  }
@@ -853,7 +877,7 @@ class ComRegister {
853
877
  // logger
854
878
  this.logger.info("推送动态中...");
855
879
  // 发送推送卡片
856
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
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);
857
881
  // logger
858
882
  this.logger.info("动态推送完毕!");
859
883
  // 判断是否需要发送动态中的图片
@@ -865,7 +889,7 @@ class ComRegister {
865
889
  item.modules.module_dynamic.major?.draw) {
866
890
  for (const img of item.modules.module_dynamic.major.draw
867
891
  .items) {
868
- await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
892
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
869
893
  }
870
894
  }
871
895
  // logger
@@ -953,7 +977,7 @@ class ComRegister {
953
977
  let liveStatus = false;
954
978
  // 处理target
955
979
  // 定义channelIdArr总长度
956
- let channelIdArrLen = 0;
980
+ let channelArrLen = 0;
957
981
  // 定义数据
958
982
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
959
983
  let liveRoomInfo;
@@ -974,17 +998,17 @@ class ComRegister {
974
998
  // 推送直播信息
975
999
  const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
976
1000
  // 只有在开播时才艾特全体成员
977
- return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting);
1001
+ return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting ? type_1.PushType.StartBroadcasting : type_1.PushType.Live);
978
1002
  };
979
1003
  // 找到频道/群组对应的
980
1004
  const liveGuardBuyPushTargetArr = target.map((channel) => {
981
1005
  // 获取符合条件的target
982
- const liveGuardBuyArr = channel.channelIdArr.filter((channelId) => channelId.liveGuardBuy);
1006
+ const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
983
1007
  // 将当前liveDanmakuArr的长度+到channelIdArrLen中
984
- channelIdArrLen += liveGuardBuyArr.length;
1008
+ channelArrLen += liveGuardBuyArr.length;
985
1009
  // 返回符合的target
986
1010
  return {
987
- channelIdArr: liveGuardBuyArr,
1011
+ channelArr: liveGuardBuyArr,
988
1012
  platform: channel.platform,
989
1013
  };
990
1014
  });
@@ -1057,7 +1081,8 @@ class ComRegister {
1057
1081
  // 定义消息
1058
1082
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1059
1083
  // 直接发送消息
1060
- channelIdArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content);
1084
+ channelArrLen > 0 &&
1085
+ this.broadcastToTargets(liveGuardBuyPushTargetArr, content, type_1.PushType.LiveGuardBuy);
1061
1086
  },
1062
1087
  onLiveStart: async () => {
1063
1088
  // 判断是否已经开播
@@ -1502,7 +1527,7 @@ class ComRegister {
1502
1527
  dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
1503
1528
  live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
1504
1529
  target: koishi_1.Schema.array(koishi_1.Schema.object({
1505
- channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
1530
+ channelArr: koishi_1.Schema.array(koishi_1.Schema.object({
1506
1531
  channelId: koishi_1.Schema.string().description("频道/群组号"),
1507
1532
  dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
1508
1533
  live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
package/lib/index.d.ts CHANGED
@@ -30,7 +30,7 @@ export interface Config {
30
30
  live: boolean;
31
31
  card: {};
32
32
  target: Array<{
33
- channelIdArr: Array<{
33
+ channelArr: Array<{
34
34
  channelId: string;
35
35
  dynamic: boolean;
36
36
  live: boolean;
package/lib/index.js CHANGED
@@ -196,12 +196,13 @@ function apply(ctx, config) {
196
196
  // 设置提示
197
197
  ctx.notifier.create({
198
198
  type: "danger",
199
- content: "3.0.0-alpha.16 全面从指令订阅迁移到配置订阅,以前使用指令的订阅需要全部重新填写到订阅配置中",
199
+ content: "3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1及以后版本必定报错,请重新填写订阅配置中sub.target.channelArr的内容",
200
200
  });
201
201
  ctx.notifier.create({
202
202
  type: "warning",
203
203
  content: "请使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令",
204
204
  });
205
+ ctx.logger.warn("从3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1版本必定报错,请重新填写订阅配置中sub.target.channelArr的内容");
205
206
  // load database
206
207
  ctx.plugin(Database);
207
208
  // Register ServerManager
@@ -269,7 +270,7 @@ exports.Config = koishi_1.Schema.object({
269
270
  platform: koishi_1.Schema.string()
270
271
  .required()
271
272
  .description("推送平台,例如onebot、qq、discord"),
272
- channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
273
+ channelArr: koishi_1.Schema.array(koishi_1.Schema.object({
273
274
  channelId: koishi_1.Schema.string().required().description("频道/群组号"),
274
275
  dynamic: koishi_1.Schema.boolean()
275
276
  .default(false)
@@ -5,7 +5,7 @@ export declare enum LiveType {
5
5
  StopBroadcast = 3,
6
6
  FirstLiveBroadcast = 4
7
7
  }
8
- export type ChannelIdArr = Array<{
8
+ export type ChannelArr = Array<{
9
9
  channelId: string;
10
10
  dynamic: boolean;
11
11
  live: boolean;
@@ -13,7 +13,7 @@ export type ChannelIdArr = Array<{
13
13
  atAll: boolean;
14
14
  }>;
15
15
  export type TargetItem = {
16
- channelIdArr: ChannelIdArr;
16
+ channelArr: ChannelArr;
17
17
  platform: string;
18
18
  };
19
19
  export type Target = Array<TargetItem>;
@@ -89,3 +89,9 @@ export type AllDynamicInfo = {
89
89
  update_num: number;
90
90
  };
91
91
  };
92
+ export declare enum PushType {
93
+ Live = 0,
94
+ Dynamic = 1,
95
+ StartBroadcasting = 2,
96
+ LiveGuardBuy = 3
97
+ }
package/lib/type/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiveType = void 0;
3
+ exports.PushType = exports.LiveType = void 0;
4
4
  var LiveType;
5
5
  (function (LiveType) {
6
6
  LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
@@ -9,3 +9,10 @@ var LiveType;
9
9
  LiveType[LiveType["StopBroadcast"] = 3] = "StopBroadcast";
10
10
  LiveType[LiveType["FirstLiveBroadcast"] = 4] = "FirstLiveBroadcast";
11
11
  })(LiveType || (exports.LiveType = LiveType = {}));
12
+ var PushType;
13
+ (function (PushType) {
14
+ PushType[PushType["Live"] = 0] = "Live";
15
+ PushType[PushType["Dynamic"] = 1] = "Dynamic";
16
+ PushType[PushType["StartBroadcasting"] = 2] = "StartBroadcasting";
17
+ PushType[PushType["LiveGuardBuy"] = 3] = "LiveGuardBuy";
18
+ })(PushType || (exports.PushType = PushType = {}));
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-alpha.0",
4
+ "version": "3.1.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -231,6 +231,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
231
231
  - ver 3.0.5-alpha.1 优化:推送卡片渲染,调整渲染图片格式为 `jpeg`
232
232
  - ver 3.0.5-alpha.2 优化:移除多余依赖
233
233
  - ver 3.1.0-alpha.0 修复:新插件在第一次订阅时提示 `订阅失败,错误信息:该分组已经存在`; 移除:消息重发功能; 重构:将消息发送模式改为 `broadcast`
234
+ - ver 3.1.0-alpha.1 修复:无法发送 `@全体成员` 消息,将消息发送模式改回
235
+ - ver 3.1.0 修复:订阅某位UP主直播和动态后,某些群聊只开启推送直播也会推送动态
234
236
 
235
237
  ## 交流群
236
238