koishi-plugin-bilibili-notify 3.0.5-alpha.2 → 3.1.0-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.
@@ -16,7 +16,6 @@ declare class ComRegister {
16
16
  loginDBData: FlatPick<LoginBili, "dynamic_group_id">;
17
17
  privateBot: Bot<Context>;
18
18
  dynamicDispose: () => void;
19
- sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
20
19
  constructor(ctx: Context, config: ComRegister.Config);
21
20
  init(config: ComRegister.Config): Promise<void>;
22
21
  getBot(pf: string): Bot<Context, any>;
@@ -24,7 +23,8 @@ declare class ComRegister {
24
23
  sendPrivateMsg(content: string): Promise<void>;
25
24
  sendPrivateMsgAndRebootService(): Promise<void>;
26
25
  sendPrivateMsgAndStopService(): Promise<void>;
27
- sendMsg(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, live?: boolean): 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;
@@ -73,7 +73,6 @@ declare namespace ComRegister {
73
73
  masterAccount: string;
74
74
  masterAccountGuildId: string;
75
75
  };
76
- automaticResend: boolean;
77
76
  liveDetectMode: "API" | "WS";
78
77
  restartPush: boolean;
79
78
  pushTime: number;
@@ -48,8 +48,6 @@ class ComRegister {
48
48
  privateBot;
49
49
  // 动态检测销毁函数
50
50
  dynamicDispose;
51
- // 发送消息方式
52
- sendMsgFunc;
53
51
  // 构造函数
54
52
  constructor(ctx, config) {
55
53
  // 将ctx赋值给类属性
@@ -286,49 +284,6 @@ class ComRegister {
286
284
  content: "您未配置私人机器人,将无法向您推送机器人状态!",
287
285
  });
288
286
  }
289
- // 判断消息发送方式
290
- if (config.automaticResend) {
291
- this.sendMsgFunc = async (
292
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
293
- bot, channelId,
294
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
295
- content) => {
296
- (0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content)).catch(async (e) => {
297
- if (e.message === "this._request is not a function") {
298
- // 2S之后重新发送消息
299
- this.ctx.setTimeout(async () => {
300
- await this.sendMsgFunc(bot, channelId, content);
301
- }, 2000);
302
- // 返回
303
- return;
304
- }
305
- // 打印错误信息
306
- this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
307
- await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
308
- });
309
- };
310
- }
311
- else {
312
- this.sendMsgFunc = async (
313
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
314
- bot, channelId,
315
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
316
- content) => {
317
- (0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
318
- if (e.message === "this._request is not a function") {
319
- // 2S之后重新发送消息
320
- this.ctx.setTimeout(async () => {
321
- await this.sendMsgFunc(bot, channelId, content);
322
- }, 2000);
323
- // 返回
324
- return;
325
- }
326
- // 打印错误信息
327
- this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
328
- await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
329
- });
330
- };
331
- }
332
287
  // 检查登录数据库是否有数据
333
288
  this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
334
289
  // 判断登录信息是否已加载完毕
@@ -384,7 +339,7 @@ class ComRegister {
384
339
  // Test
385
340
  const testTarget = [
386
341
  {
387
- channelIdArr: [
342
+ channelArr: [
388
343
  {
389
344
  channelId: "635762054",
390
345
  dynamic: true,
@@ -450,49 +405,71 @@ class ComRegister {
450
405
  // 结束
451
406
  return;
452
407
  }
408
+ async sendMessageWithRetry(bot, channelId,
453
409
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
454
- async sendMsg(targets, content, live) {
410
+ content) {
411
+ (0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
412
+ if (e.message === "this._request is not a function") {
413
+ // 2S之后重新发送消息
414
+ this.ctx.setTimeout(async () => {
415
+ await this.sendMessageWithRetry(bot, channelId, content);
416
+ }, 2000);
417
+ // 返回
418
+ return;
419
+ }
420
+ // 打印错误信息
421
+ this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
422
+ await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
423
+ });
424
+ }
425
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
426
+ async broadcastToTargets(targets, content, live) {
455
427
  for (const target of targets) {
456
428
  // 获取机器人实例
457
429
  const bot = this.getBot(target.platform);
458
430
  // 定义需要发送的数组
459
- let sendArr = [];
431
+ let channelArr = [];
460
432
  // 判断是否需要推送所有机器人加入的群
461
- if (target.channelIdArr[0].channelId === "all") {
433
+ if (target.channelArr[0].channelId === "all") {
462
434
  // 获取所有guild
463
435
  for (const guild of (await bot.getGuildList()).data) {
464
- sendArr.push({
436
+ channelArr.push({
465
437
  channelId: guild.id,
466
- dynamic: target.channelIdArr[0].dynamic,
467
- live: target.channelIdArr[0].live,
468
- liveGuardBuy: target.channelIdArr[0].liveGuardBuy,
469
- 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,
470
442
  });
471
443
  }
472
444
  }
473
445
  else {
474
- sendArr = target.channelIdArr;
446
+ channelArr = target.channelArr;
475
447
  }
476
448
  // 判断是否是直播开播推送,如果是则需要进一步判断是否需要艾特群体成员
477
449
  if (live) {
478
450
  // 直播开播推送,判断是否需要艾特全体成员
479
- for (const channel of sendArr) {
451
+ for (const channel of channelArr) {
480
452
  // 判断是否需要推送直播消息
481
453
  if (channel.live) {
482
- await this.sendMsgFunc(bot, channel.channelId, content);
454
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
483
455
  }
484
456
  // 判断是否需要艾特全体成员
485
457
  if (channel.atAll) {
486
- await this.sendMsgFunc(bot, channel.channelId, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
458
+ await this.sendMessageWithRetry(bot, channel.channelId, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
487
459
  }
460
+ // 延迟发送
461
+ await this.ctx.sleep(500);
488
462
  }
489
463
  }
490
464
  else {
491
- for (const channel of sendArr) {
465
+ // 不是直播开播推送
466
+ for (const channel of channelArr) {
492
467
  // 判断是否需要推送动态消息
493
468
  if (channel.dynamic || channel.live) {
494
- await this.sendMsgFunc(bot, channel.channelId, content);
469
+ await this.sendMessageWithRetry(bot, channel.channelId, content);
495
470
  }
471
+ // 延迟发送
472
+ await this.ctx.sleep(500);
496
473
  }
497
474
  }
498
475
  }
@@ -624,13 +601,13 @@ class ComRegister {
624
601
  if (e.message === "出现关键词,屏蔽该动态") {
625
602
  // 如果需要发送才发送
626
603
  if (this.config.filter.notify) {
627
- await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
604
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
628
605
  }
629
606
  return;
630
607
  }
631
608
  if (e.message === "已屏蔽转发动态") {
632
609
  if (this.config.filter.notify) {
633
- await this.sendMsg(sub.target, `${upName}转发了一条动态,已屏蔽`);
610
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
634
611
  }
635
612
  return;
636
613
  }
@@ -649,7 +626,7 @@ class ComRegister {
649
626
  // logger
650
627
  this.logger.info("推送动态中...");
651
628
  // 发送推送卡片
652
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
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
630
  // 判断是否需要发送动态中的图片
654
631
  if (this.config.pushImgsInDynamic) {
655
632
  // 判断是否为图文动态,且存在draw
@@ -657,7 +634,7 @@ class ComRegister {
657
634
  item.modules.module_dynamic.major?.draw) {
658
635
  for (const img of item.modules.module_dynamic.major.draw
659
636
  .items) {
660
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
637
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
661
638
  }
662
639
  }
663
640
  }
@@ -842,13 +819,13 @@ class ComRegister {
842
819
  if (e.message === "出现关键词,屏蔽该动态") {
843
820
  // 如果需要发送才发送
844
821
  if (this.config.filter.notify) {
845
- await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
822
+ await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
846
823
  }
847
824
  return;
848
825
  }
849
826
  if (e.message === "已屏蔽转发动态") {
850
827
  if (this.config.filter.notify) {
851
- await this.sendMsg(sub.target, `${upName}转发了一条动态,已屏蔽`);
828
+ await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
852
829
  }
853
830
  return;
854
831
  }
@@ -876,7 +853,7 @@ class ComRegister {
876
853
  // logger
877
854
  this.logger.info("推送动态中...");
878
855
  // 发送推送卡片
879
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
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
857
  // logger
881
858
  this.logger.info("动态推送完毕!");
882
859
  // 判断是否需要发送动态中的图片
@@ -888,7 +865,7 @@ class ComRegister {
888
865
  item.modules.module_dynamic.major?.draw) {
889
866
  for (const img of item.modules.module_dynamic.major.draw
890
867
  .items) {
891
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
868
+ await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
892
869
  }
893
870
  }
894
871
  // logger
@@ -976,7 +953,7 @@ class ComRegister {
976
953
  let liveStatus = false;
977
954
  // 处理target
978
955
  // 定义channelIdArr总长度
979
- let channelIdArrLen = 0;
956
+ let channelArrLen = 0;
980
957
  // 定义数据
981
958
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
982
959
  let liveRoomInfo;
@@ -997,17 +974,17 @@ class ComRegister {
997
974
  // 推送直播信息
998
975
  const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
999
976
  // 只有在开播时才艾特全体成员
1000
- return await this.sendMsg(target, msg, liveType === type_1.LiveType.StartBroadcasting);
977
+ return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting);
1001
978
  };
1002
979
  // 找到频道/群组对应的
1003
980
  const liveGuardBuyPushTargetArr = target.map((channel) => {
1004
981
  // 获取符合条件的target
1005
- const liveGuardBuyArr = channel.channelIdArr.filter((channelId) => channelId.liveGuardBuy);
982
+ const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
1006
983
  // 将当前liveDanmakuArr的长度+到channelIdArrLen中
1007
- channelIdArrLen += liveGuardBuyArr.length;
984
+ channelArrLen += liveGuardBuyArr.length;
1008
985
  // 返回符合的target
1009
986
  return {
1010
- channelIdArr: liveGuardBuyArr,
987
+ channelArr: liveGuardBuyArr,
1011
988
  platform: channel.platform,
1012
989
  };
1013
990
  });
@@ -1080,7 +1057,8 @@ class ComRegister {
1080
1057
  // 定义消息
1081
1058
  const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
1082
1059
  // 直接发送消息
1083
- channelIdArrLen > 0 && this.sendMsg(liveGuardBuyPushTargetArr, content);
1060
+ channelArrLen > 0 &&
1061
+ this.broadcastToTargets(liveGuardBuyPushTargetArr, content);
1084
1062
  },
1085
1063
  onLiveStart: async () => {
1086
1064
  // 判断是否已经开播
@@ -1257,8 +1235,12 @@ class ComRegister {
1257
1235
  if (group.name === "订阅") {
1258
1236
  // 拿到分组id
1259
1237
  this.loginDBData.dynamic_group_id = group.tagid;
1260
- // 结束循环
1261
- break;
1238
+ // 保存到数据库
1239
+ this.ctx.database.set("loginBili", 1, {
1240
+ dynamic_group_id: this.loginDBData.dynamic_group_id,
1241
+ });
1242
+ // 返回分组已存在
1243
+ return { code: 0, msg: "分组已存在" };
1262
1244
  }
1263
1245
  }
1264
1246
  }
@@ -1521,7 +1503,7 @@ class ComRegister {
1521
1503
  dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
1522
1504
  live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
1523
1505
  target: koishi_1.Schema.array(koishi_1.Schema.object({
1524
- channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
1506
+ channelArr: koishi_1.Schema.array(koishi_1.Schema.object({
1525
1507
  channelId: koishi_1.Schema.string().description("频道/群组号"),
1526
1508
  dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
1527
1509
  live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
@@ -1546,7 +1528,6 @@ class ComRegister {
1546
1528
  masterAccount: koishi_1.Schema.string(),
1547
1529
  masterAccountGuildId: koishi_1.Schema.string(),
1548
1530
  }),
1549
- automaticResend: koishi_1.Schema.boolean().required(),
1550
1531
  liveDetectMode: koishi_1.Schema.union([
1551
1532
  koishi_1.Schema.const("API"),
1552
1533
  koishi_1.Schema.const("WS"),
package/lib/index.d.ts CHANGED
@@ -20,7 +20,6 @@ export interface Config {
20
20
  key: string;
21
21
  master: {};
22
22
  basicSettings: {};
23
- automaticResend: boolean;
24
23
  userAgent: string;
25
24
  subTitle: {};
26
25
  subLoadTimeout: number;
@@ -31,7 +30,7 @@ export interface Config {
31
30
  live: boolean;
32
31
  card: {};
33
32
  target: Array<{
34
- channelIdArr: Array<{
33
+ channelArr: Array<{
35
34
  channelId: string;
36
35
  dynamic: boolean;
37
36
  live: boolean;
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
- automaticResend: globalConfig.automaticResend,
131
130
  liveDetectMode: globalConfig.liveDetectMode,
132
131
  restartPush: globalConfig.restartPush,
133
132
  pushTime: globalConfig.pushTime,
@@ -197,12 +196,13 @@ function apply(ctx, config) {
197
196
  // 设置提示
198
197
  ctx.notifier.create({
199
198
  type: "danger",
200
- content: "3.0.0-alpha.16 全面从指令订阅迁移到配置订阅,以前使用指令的订阅需要全部重新填写到订阅配置中",
199
+ content: "3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1版本必定报错,请重新填写订阅配置中sub.target.channelArr的内容",
201
200
  });
202
201
  ctx.notifier.create({
203
202
  type: "warning",
204
203
  content: "请使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令",
205
204
  });
205
+ ctx.logger.warn("从3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1版本必定报错,请重新填写订阅配置中sub.target.channelArr的内容");
206
206
  // load database
207
207
  ctx.plugin(Database);
208
208
  // Register ServerManager
@@ -254,9 +254,6 @@ exports.Config = koishi_1.Schema.object({
254
254
  ]),
255
255
  ]),
256
256
  basicSettings: koishi_1.Schema.object({}).description("基本设置"),
257
- automaticResend: koishi_1.Schema.boolean()
258
- .default(true)
259
- .description("是否开启自动重发功能,默认开启。开启后,如果推送失败,将会自动重发,尝试三次。关闭后,推送失败将不会再重发,直到下一次推送"),
260
257
  userAgent: koishi_1.Schema.string()
261
258
  .required()
262
259
  .description("设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111"),
@@ -273,7 +270,7 @@ exports.Config = koishi_1.Schema.object({
273
270
  platform: koishi_1.Schema.string()
274
271
  .required()
275
272
  .description("推送平台,例如onebot、qq、discord"),
276
- channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
273
+ channelArr: koishi_1.Schema.array(koishi_1.Schema.object({
277
274
  channelId: koishi_1.Schema.string().required().description("频道/群组号"),
278
275
  dynamic: koishi_1.Schema.boolean()
279
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>;
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.0.5-alpha.2",
4
+ "version": "3.1.0-alpha.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -230,6 +230,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
230
230
  - ver 3.0.5-alpha.0 优化:推送卡片渲染,压缩图片; 新增:指令 `bili dyn` 可用于推送指定UP主指定动态
231
231
  - ver 3.0.5-alpha.1 优化:推送卡片渲染,调整渲染图片格式为 `jpeg`
232
232
  - ver 3.0.5-alpha.2 优化:移除多余依赖
233
+ - ver 3.1.0-alpha.0 修复:新插件在第一次订阅时提示 `订阅失败,错误信息:该分组已经存在`; 移除:消息重发功能; 重构:将消息发送模式改为 `broadcast`
234
+ - ver 3.1.0-alpha.1 修复:无法发送 `@全体成员` 消息,将消息发送模式改回
233
235
 
234
236
  ## 交流群
235
237