koishi-plugin-bilibili-notify 2.0.0-alpha.6 → 2.0.0-alpha.8

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.
@@ -5,6 +5,7 @@
5
5
  ---
6
6
 
7
7
  - koishi-plugin-bilibili-notify [![npm](https://img.shields.io/npm/v/koishi-plugin-bilibili-notify?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
8
+ - [重新订阅](#重新订阅)
8
9
  - [功能](#功能)
9
10
  - [注意事项](#注意事项)
10
11
  - [安装](#安装)
@@ -14,6 +15,10 @@
14
15
  - [感谢](#感谢)
15
16
  - [License](#License)
16
17
 
18
+ ## 重新订阅
19
+
20
+ 由于版本 `2.0.0-alpha.7` 重构了订阅功能,从 `2.0.0-alpha.7` 以前版本升级到以后版本的需重新订阅
21
+
17
22
  ## 功能
18
23
 
19
24
  订阅B站UP主动态
@@ -48,23 +53,22 @@
48
53
 
49
54
  订阅UP主:订阅你想要推送的UP主
50
55
 
51
- - 使用指令 `bili sub <uid> [Q群号]` 订阅需要订阅的UP主
56
+ - 使用指令 `bili sub <uid>` 订阅需要订阅的UP主
52
57
  - 参数说明:
53
58
  - `uid` 为必填参数,为 `up主` 的 `uid`
54
- - `Q群号` 为可选参数,可以添加多个,如果Q群号为 `all` 则会向机器人加入的所有群聊推送
55
- - 选项说明:`bili sub <uid>` 有两个选项:-l 和 -d
59
+ - 选项说明:`bili sub <uid>` 有三个选项:-l -d -m
56
60
  - `-l` 为订阅UP主直播间,包括直播开播通知,定时推送直播内容,下播通知
57
61
  - `-d` 为订阅UP主动态推送,目前实现推送的动态类型有:普通图文动态,转发动态,直播预约动态
62
+ - `-m` 为多平台动态推送,格式为:群号/频道号,群号/频道号,群号/频道号.平台名;群号/频道号,群号/频道号.平台号
63
+ 例如:
64
+ `-m 3247293,324389,89874324.qq;EDBWIUBIU.qqguild;79324792,3247892.onebot`
65
+ 所有分隔符均为英文符号
58
66
 
59
67
  - 例如:
60
- - `bili sub 1194210119 ` 订阅UID为1194210119的UP
68
+ - `bili sub 1194210119 ` 订阅UID为1194210119的UP主动态推送和直播间
61
69
  - `bili sub 1194210119 -d` 订阅UID为1194210119的UP主动态推送
62
- - `bili sub 1194210119 -ld` 订阅UID为1194210119的UP主动态推送和直播间
63
- - `bili sub 1194210119 1234567 2345678` 订阅UID为1194210119的UP主,向Q群号为1234567和2345678两个群进行推送
64
- - `bili sub 1194210119 all` 订阅UID为1194210119的UP主,向机器人加入的所有群聊进行推送
65
- - Tips:
66
- - 除非使用指令 `bili sub 1194210119 -ld` ,没有加选项或只加了一个选项的指令都会再次询问是否需要订阅另一项。例如:使用指令 `bili sub 1194210119 -d` 机器人会询问是否需要订阅直播间
67
- - `[Q群号]` 这个可选参数仅支持Q群
70
+ - `bili sub 1194210119 -l` 订阅UID为1194210119的UP主直播间
71
+ - `bili sub 1194210119 -m 3247293,324389,89874324.qq;all.onebot;EHUIWDBUAWD.qqguild` 订阅UID为1194210119的UP主,向群号为3247293,324389,89874324的QQ群,所有onebot平台下的群聊,频道号为EHUIWDBUAWD的QQ频道平台进行推送
68
72
 
69
73
  取消订阅UP主:取消订阅不需要推送的UP主
70
74
 
@@ -184,6 +188,8 @@
184
188
  - ver 2.0.0-alpha.4 修复:初次订阅后不推送动态的bug 优化:下播不再发送链接
185
189
  - ver 2.0.0-alpha.5 移除:选项pushUrl,选项platform 新增:选项customLive,主人账号中platform选项。支持多平台,且可同时推送不同平台,单个UP主只能推送一个平台
186
190
  - ver 2.0.0-alpha.6 修复:直播推送发送失败的bug
191
+ - ver 2.0.0-alpha.7 重构:现已支持同一UP多平台推送
192
+ - ver 2.0.0-alpha.8 新增:重新订阅提示
187
193
 
188
194
  ## 交流群
189
195
 
@@ -1,11 +1,16 @@
1
1
  import { Bot, Context, FlatPick, Logger, Schema, Session } from "koishi";
2
2
  import { Notifier } from "@koishijs/plugin-notifier";
3
3
  import { LoginBili } from "./database";
4
+ type TargetItem = {
5
+ idArr: Array<string>;
6
+ platform: string;
7
+ };
8
+ type Target = Array<TargetItem>;
4
9
  type SubItem = {
5
10
  id: number;
6
11
  uid: string;
7
12
  roomId: string;
8
- targetIdArr: Array<string>;
13
+ target: Target;
9
14
  platform: string;
10
15
  live: boolean;
11
16
  dynamic: boolean;
@@ -14,6 +19,7 @@ type SubItem = {
14
19
  type SubManager = Array<SubItem>;
15
20
  declare class ComRegister {
16
21
  static inject: string[];
22
+ qqRelatedBotList: Array<string>;
17
23
  logger: Logger;
18
24
  config: ComRegister.Config;
19
25
  loginTimer: Function;
@@ -26,16 +32,20 @@ declare class ComRegister {
26
32
  dynamicDispose: Function;
27
33
  sendMsgFunc: (bot: Bot<Context, any>, guild: string, content: any) => Promise<void>;
28
34
  constructor(ctx: Context, config: ComRegister.Config);
35
+ splitMultiPlatformStr(str: string): Array<{
36
+ idArr: Array<string>;
37
+ platform: string;
38
+ }>;
29
39
  getBot(ctx: Context, pf: string): Bot<Context, any>;
30
40
  sendPrivateMsg(content: string): Promise<void>;
31
41
  sendPrivateMsgAndRebootService(ctx: Context): Promise<void>;
32
42
  sendPrivateMsgAndStopService(ctx: Context): Promise<void>;
33
- sendMsg(ctx: Context, targets: Array<string>, content: any, platform: string): Promise<void>;
43
+ sendMsg(ctx: Context, targets: Target, content: any): Promise<void>;
34
44
  dynamicDetect(ctx: Context): () => Promise<void>;
35
45
  debug_dynamicDetect(ctx: Context): () => Promise<void>;
36
- liveDetect(ctx: Context, roomId: string, guildId: Array<string>, platform: string): () => Promise<void>;
46
+ liveDetect(ctx: Context, roomId: string, target: Target): () => Promise<void>;
37
47
  subShow(): string;
38
- checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session, data?: any): Promise<Array<boolean>>;
48
+ checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session, liveRoomData: any): Promise<Array<boolean>>;
39
49
  updateSubNotifier(ctx: Context): void;
40
50
  checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
41
51
  subUserInBili(ctx: Context, mid: string): Promise<{
@@ -19,6 +19,7 @@ var LiveType;
19
19
  })(LiveType || (LiveType = {}));
20
20
  class ComRegister {
21
21
  static inject = ['ba', 'gi', 'database', 'sm'];
22
+ qqRelatedBotList = ['qq', 'onebot', 'red', 'satori', 'chronocat'];
22
23
  logger;
23
24
  config;
24
25
  loginTimer;
@@ -105,6 +106,27 @@ class ComRegister {
105
106
  this.logger.info(this.subManager);
106
107
  return '查看控制台';
107
108
  });
109
+ statusCom
110
+ .subcommand('.bot', '查询当前拥有的机器人信息', { hidden: true })
111
+ .usage('查询当前拥有的机器人信息')
112
+ .example('status bot 查询当前拥有的机器人信息')
113
+ .action(() => {
114
+ this.logger.info('开始输出BOT信息');
115
+ ctx.bots.forEach(bot => {
116
+ this.logger.info('--------------------------------');
117
+ this.logger.info('平台:' + bot.platform);
118
+ this.logger.info('名称:' + bot.user.name);
119
+ this.logger.info('--------------------------------');
120
+ });
121
+ });
122
+ statusCom
123
+ .subcommand('.env', '查询当前环境的信息', { hidden: true })
124
+ .usage('查询当前环境的信息')
125
+ .example('status env 查询当前环境的信息')
126
+ .action(async ({ session }) => {
127
+ await session.send(`Guild ID:${session.event.guild.id}`);
128
+ await session.send(`Channel ID: ${session.event.channel.id}`);
129
+ });
108
130
  const biliCom = ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] });
109
131
  biliCom.subcommand('.login', '登录B站之后才可以进行之后的操作')
110
132
  .usage('使用二维码登录,登录B站之后才可以进行之后的操作')
@@ -270,12 +292,13 @@ class ComRegister {
270
292
  return subTable;
271
293
  });
272
294
  biliCom
273
- .subcommand('.sub <mid:string> [...guildId:string]', '订阅用户动态和直播通知')
295
+ .subcommand('.sub <mid:string>', '订阅用户动态和直播通知')
296
+ .option('multiplatform', '-m <value:string>', { type: /^[A-Za-z0-9]+(?:,[A-Za-z0-9]+)*\.[A-Za-z0-9]+(?:,[A-Za-z0-9]+)*(?:;[A-Za-z0-9]+(?:,[A-Za-z0-9]+)*\.[A-Za-z0-9]+(?:,[A-Za-z0-9]+)*)*$/ })
274
297
  .option('live', '-l')
275
298
  .option('dynamic', '-d')
276
299
  .usage('订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d。若没有加任何参数,之后会向你单独询问,尖括号中为必选参数,中括号为可选参数,目标群号若不填,则默认为当前群聊')
277
300
  .example('bili sub 1194210119 目标QQ群号(实验性) -l -d 订阅UID为1194210119的UP主的动态和直播')
278
- .action(async ({ session, options }, mid, ...guildId) => {
301
+ .action(async ({ session, options }, mid) => {
279
302
  this.logger.info('调用bili.sub指令');
280
303
  // 先判断是否订阅直播,再判断是否解锁订阅限制,最后判断直播订阅是否已超三个
281
304
  if (options.live && !this.config.unlockSubLimits && (this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3)) {
@@ -294,6 +317,68 @@ class ComRegister {
294
317
  // 判断是否订阅对象存在
295
318
  if (!subUserData.flag)
296
319
  return '订阅对象失败,请稍后重试!';
320
+ let target;
321
+ // 判断是否使用多平台功能
322
+ if (options.multiplatform) {
323
+ // 分割字符串,赋值给target
324
+ target = this.splitMultiPlatformStr(options.multiplatform);
325
+ }
326
+ if (target) {
327
+ target.forEach(async ({ idArr, platform }, index) => {
328
+ if (idArr.length > 0) { // 输入了推送群号或频道号
329
+ // 拿到对应的bot
330
+ const bot = this.getBot(ctx, platform);
331
+ // 判断是否配置了对应平台的机器人
332
+ if (!ctx.bots.some(bot => bot.platform === platform)) {
333
+ await session.send('您未配置对应平台的机器人,不能在该平台进行订阅操作');
334
+ }
335
+ // 判断是否需要加入的群全部推送
336
+ if (idArr[0] !== 'all') {
337
+ // 定义满足条件的群组数组
338
+ const targetArr = [];
339
+ // 获取机器人加入的群组
340
+ const guildList = await bot.getGuildList();
341
+ // 遍历群组
342
+ for (const guild of guildList.data) {
343
+ // 获取频道
344
+ const channelList = await bot.getChannelList(guild.id);
345
+ // 判断群号是否符合条件
346
+ for (const id of idArr) {
347
+ // 判断是否机器人加入了该群
348
+ if (channelList.data.some(channel => channel.id === id)) { // 机器人加入了该群
349
+ // 保存到数组
350
+ targetArr.push(id);
351
+ // 继续下一个循环
352
+ continue;
353
+ }
354
+ // 不满足条件发送错误提示
355
+ await session.send(`您的机器未加入${id},无法对该群或频道进行推送`);
356
+ }
357
+ }
358
+ // 判断targetArr是否为空
359
+ if (targetArr.length === 0) {
360
+ // 为空则默认为当前环境
361
+ target = [{ idArr: [session.event.channel.id], platform: session.event.platform }];
362
+ // 没有满足条件的群组或频道
363
+ await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
364
+ }
365
+ // 将符合条件的群组添加到target中
366
+ target[index].idArr = targetArr;
367
+ }
368
+ // 如果为all则全部推送,不需要进行修改
369
+ }
370
+ else {
371
+ // 未填写群号或频道号,默认为当前环境
372
+ target = [{ idArr: [session.event.channel.id], platform: session.event.platform }];
373
+ // 发送提示消息
374
+ await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
375
+ }
376
+ });
377
+ }
378
+ else {
379
+ // 用户直接订阅,将当前环境赋值给target
380
+ target = [{ idArr: [session.event.channel.id], platform: session.event.platform }];
381
+ }
297
382
  // 定义外围变量
298
383
  let content;
299
384
  try {
@@ -329,90 +414,14 @@ class ComRegister {
329
414
  // 返回错误信息
330
415
  return msg;
331
416
  }
332
- // 定义目标群组id
333
- let targetId;
334
- // 定义目标群组id数组
335
- let targetIdArr;
336
- // 判断是否输入了QQ群号
337
- if (guildId.length > 0) { // 输入了QQ群号
338
- // 定义方法
339
- const checkIfGuildHasJoined = async (bot) => {
340
- // 获取机器人加入的群组
341
- const guildList = await bot.getGuildList();
342
- // 定义满足条件的群组数组
343
- const targetArr = [];
344
- // 判断群号是否符合条件
345
- for (const guild of guildId) {
346
- // 判断是否机器人加入了该群
347
- if (guildList.data.some(cv => cv.id === guild)) { // 机器人加入了该群
348
- // 保存到数组
349
- targetArr.push(guild);
350
- // 继续下一个循环
351
- continue;
352
- }
353
- // 不满足条件发送错误提示
354
- session.send(`您的机器未加入${guild},无法对该群进行推送`);
355
- }
356
- // 返回数组
357
- return targetArr;
358
- };
359
- // 定义可用的群组数组
360
- let okGuild = [];
361
- // 判断是否需要加入的群全部推送
362
- if (guildId[0] === 'all') {
363
- // 判断是否有群机器人相关Bot
364
- if (['qq', 'onebot', 'red', 'satori', 'chronocat'].includes(session.event.platform)) {
365
- // 推送所有群组
366
- okGuild.push('all');
367
- }
368
- else {
369
- // 发送错误提示并返回
370
- session.send('您尚未配置任何QQ群相关机器人,不能对QQ群进行操作');
371
- // 直接返回
372
- return;
373
- }
374
- }
375
- else {
376
- // 判断是否有群机器人相关Bot
377
- switch (session.event.platform) {
378
- case 'qq':
379
- case 'onebot':
380
- case 'red':
381
- case 'satori':
382
- case 'chronocat': {
383
- // 获取该会话机器人
384
- const bot = this.getBot(ctx, session.event.platform);
385
- // 检查机器人是否加入该群
386
- okGuild = await checkIfGuildHasJoined(bot);
387
- break;
388
- }
389
- default: {
390
- // 发送错误提示并返回
391
- session.send('您尚未配置任何QQ群相关机器人,不能对QQ群进行操作');
392
- // 直接返回
393
- return;
394
- }
395
- }
396
- }
397
- // 将可用的目标赋值给数组
398
- targetIdArr = okGuild;
399
- // 将群号用空格进行分割
400
- targetId = okGuild.join(' ');
401
- }
402
- else { // 没有输入QQ群号
403
- // 为当前群聊环境进行推送
404
- targetId = session.event.channel.id;
405
- // 将目标id转换为数组进行赋值
406
- targetIdArr = [session.event.channel.id];
407
- }
408
417
  // 获取data
409
418
  const { data } = content;
410
419
  // 判断是否需要订阅直播和动态
411
- const [liveMsg, dynamicMsg] = await this.checkIfNeedSub(options.live, options.dynamic, session, data);
420
+ const [liveMsg, dynamicMsg] = await this.checkIfNeedSub(options.live, options.dynamic, session, data.live_room);
412
421
  // 判断是否未订阅任何消息
413
- if (!liveMsg && !dynamicMsg) {
422
+ if (!liveMsg && !dynamicMsg)
414
423
  return '您未订阅该UP的任何消息';
415
- }
424
+ // 获取到对应的订阅对象
416
425
  const subUser = this.subManager.find(sub => sub.uid === mid);
417
426
  // 判断要订阅的用户是否已经存在于订阅管理对象中
418
427
  if (subUser) {
@@ -427,43 +436,22 @@ class ComRegister {
427
436
  }
428
437
  // 获取直播房间号
429
438
  const roomId = data.live_room?.roomid.toString();
430
- // 保存到数据库中
431
- const sub = await ctx.database.create('bilibili', {
432
- uid: mid,
433
- room_id: roomId,
434
- dynamic: dynamicMsg ? 1 : 0,
435
- video: 1,
436
- live: liveMsg ? 1 : 0,
437
- targetId,
438
- platform: session.event.platform,
439
- time: new Date()
440
- });
441
- // 订阅数+1
442
- this.num++;
443
- // 保存新订阅对象
444
- this.subManager.push({
445
- id: sub.id,
446
- uid: mid,
447
- targetIdArr,
448
- roomId,
449
- platform: session.event.platform,
450
- live: liveMsg,
451
- dynamic: dynamicMsg,
452
- liveDispose: null
453
- });
454
439
  // 获取用户信息
455
440
  let userData;
456
441
  try {
457
- const { data } = await ctx.ba.getMasterInfo(sub.uid);
442
+ const { data } = await ctx.ba.getMasterInfo(mid);
458
443
  userData = data;
459
444
  }
460
445
  catch (e) {
461
446
  this.logger.error('bili sub指令 getMasterInfo() 发生了错误,错误为:' + e.message);
462
447
  return '订阅出错啦,请重试';
463
448
  }
449
+ // 定义live销毁函数
450
+ let liveDispose;
464
451
  // 订阅直播
465
452
  if (liveMsg) {
466
- await session.execute(`bili live ${roomId} ${targetId.split(',').join(' ')}`);
453
+ // 开始循环检测
454
+ liveDispose = ctx.setInterval(this.liveDetect(ctx, roomId, target), config.liveLoopTime * 1000);
467
455
  // 发送订阅消息通知
468
456
  await session.send(`订阅${userData.info.uname}直播通知`);
469
457
  }
@@ -482,29 +470,50 @@ class ComRegister {
482
470
  // 发送订阅消息通知
483
471
  await session.send(`订阅${userData.info.uname}动态通知`);
484
472
  }
473
+ // 保存到数据库中
474
+ const sub = await ctx.database.create('bilibili', {
475
+ uid: mid,
476
+ room_id: roomId,
477
+ dynamic: dynamicMsg ? 1 : 0,
478
+ video: 1,
479
+ live: liveMsg ? 1 : 0,
480
+ target: JSON.stringify(target),
481
+ platform: session.event.platform,
482
+ time: new Date()
483
+ });
484
+ // 订阅数+1
485
+ this.num++;
486
+ // 保存新订阅对象
487
+ this.subManager.push({
488
+ id: sub.id,
489
+ uid: mid,
490
+ roomId,
491
+ target,
492
+ platform: session.event.platform,
493
+ live: liveMsg,
494
+ dynamic: dynamicMsg,
495
+ liveDispose
496
+ });
485
497
  // 新增订阅展示到控制台
486
498
  this.updateSubNotifier(ctx);
487
499
  });
488
- biliCom
500
+ /* biliCom
489
501
  .subcommand('.live <roomId:string> <...guildId:string>', '订阅主播开播通知', { hidden: true })
490
502
  .usage('订阅主播开播通知')
491
503
  .example('bili live 26316137 订阅房间号为26316137的直播间')
492
504
  .action(async (_, roomId, ...guildId) => {
493
- this.logger.info('调用bili.live指令');
494
- // 如果room_id为空则返回
495
- if (!roomId)
496
- return `${roomId}非法调用 dynamic 指令`; // 订阅主播房间号不能为空
497
- if (!guildId)
498
- return `${roomId}非法调用 dynamic 指令`; // 目标群组或频道不能为空
499
- // 要订阅的对象不在订阅管理对象中,直接返回
500
- const index = this.subManager.findIndex(sub => sub.roomId === roomId);
501
- if (index === -1)
502
- return '请勿直接调用该指令';
503
- // 开始循环检测
504
- const dispose = ctx.setInterval(this.liveDetect(ctx, roomId, guildId, this.subManager[index].platform), config.liveLoopTime * 1000);
505
- // 保存销毁函数
506
- this.subManager[index].liveDispose = dispose;
507
- });
505
+ this.logger.info('调用bili.live指令')
506
+ // 如果room_id为空则返回
507
+ if (!roomId) return `${roomId}非法调用 dynamic 指令` // 订阅主播房间号不能为空
508
+ if (!guildId) return `${roomId}非法调用 dynamic 指令` // 目标群组或频道不能为空
509
+ // 要订阅的对象不在订阅管理对象中,直接返回
510
+ const index = this.subManager.findIndex(sub => sub.roomId === roomId)
511
+ if (index === -1) return '请勿直接调用该指令'
512
+ // 开始循环检测
513
+ const dispose = ctx.setInterval(this.liveDetect(ctx, roomId, guildId, this.subManager[index].platform), config.liveLoopTime * 1000)
514
+ // 保存销毁函数
515
+ this.subManager[index].liveDispose = dispose
516
+ }) */
508
517
  biliCom
509
518
  .subcommand('.status <roomId:string>', '查询主播当前直播状态', { hidden: true })
510
519
  .usage('查询主播当前直播状态')
@@ -548,19 +557,6 @@ class ComRegister {
548
557
  // pic不存在,说明使用的是page模式
549
558
  await session.send(koishi_1.h.image(buffer, 'image/png'));
550
559
  });
551
- biliCom
552
- .subcommand('.bot', '查询当前拥有的机器人信息', { hidden: true })
553
- .usage('查询当前拥有的机器人信息')
554
- .example('bili bot 查询当前拥有的机器人信息')
555
- .action(() => {
556
- this.logger.info('开始输出BOT信息');
557
- ctx.bots.forEach(bot => {
558
- this.logger.info('--------------------------------');
559
- this.logger.info('平台:' + bot.platform);
560
- this.logger.info('名称:' + bot.user.name);
561
- this.logger.info('--------------------------------');
562
- });
563
- });
564
560
  biliCom
565
561
  .subcommand('.private', '向主人账号发送一条测试消息', { hidden: true })
566
562
  .usage('向主人账号发送一条测试消息')
@@ -572,6 +568,12 @@ class ComRegister {
572
568
  await session.send('已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误');
573
569
  });
574
570
  }
571
+ splitMultiPlatformStr(str) {
572
+ return str.split(';').map(cv => cv.split('.')).map(([idStr, platform]) => {
573
+ const idArr = idStr.split(',');
574
+ return { idArr, platform };
575
+ });
576
+ }
575
577
  getBot(ctx, pf) {
576
578
  return ctx.bots.find(bot => bot.platform === pf);
577
579
  }
@@ -628,24 +630,26 @@ class ComRegister {
628
630
  // 结束
629
631
  return;
630
632
  }
631
- async sendMsg(ctx, targets, content, platform) {
632
- // 获取机器人实例
633
- const bot = this.getBot(ctx, platform);
634
- // 定义需要发送的数组
635
- let sendArr = [];
636
- // 判断是否需要推送所有机器人加入的群
637
- if (targets[0] === 'all') {
638
- // 获取所有guild
639
- for (const guild of (await bot.getGuildList()).data) {
640
- sendArr.push(guild.id);
633
+ async sendMsg(ctx, targets, content) {
634
+ for (const target of targets) {
635
+ // 获取机器人实例
636
+ const bot = this.getBot(ctx, target.platform);
637
+ // 定义需要发送的数组
638
+ let sendArr = [];
639
+ // 判断是否需要推送所有机器人加入的群
640
+ if (target.idArr[0] === 'all') {
641
+ // 获取所有guild
642
+ for (const guild of (await bot.getGuildList()).data) {
643
+ sendArr.push(guild.id);
644
+ }
645
+ }
646
+ else {
647
+ sendArr = target.idArr;
648
+ }
649
+ // 循环给每个群组发送
650
+ for (const guild of sendArr) {
651
+ await this.sendMsgFunc(bot, guild, content);
641
652
  }
642
- }
643
- else {
644
- sendArr = targets;
645
- }
646
- // 循环给每个群组发送
647
- for (const guild of sendArr) {
648
- await this.sendMsgFunc(bot, guild, content);
649
653
  }
650
654
  }
651
655
  dynamicDetect(ctx) {
@@ -775,13 +779,13 @@ class ComRegister {
775
779
  if (e.message === '出现关键词,屏蔽该动态') {
776
780
  // 如果需要发送才发送
777
781
  if (this.config.filter.notify) {
778
- await this.sendMsg(ctx, sub.targetIdArr, `${upName}发布了一条含有屏蔽关键字的动态`, sub.platform);
782
+ await this.sendMsg(ctx, sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
779
783
  }
780
784
  return;
781
785
  }
782
786
  if (e.message === '已屏蔽转发动态') {
783
787
  if (this.config.filter.notify) {
784
- await this.sendMsg(ctx, sub.targetIdArr, `${upName}发布了一条转发动态,已屏蔽`, sub.platform);
788
+ await this.sendMsg(ctx, sub.target, `${upName}发布了一条转发动态,已屏蔽`);
785
789
  }
786
790
  return;
787
791
  }
@@ -799,12 +803,12 @@ class ComRegister {
799
803
  if (pic) {
800
804
  this.logger.info('推送动态中,使用render模式');
801
805
  // pic存在,使用的是render模式
802
- await this.sendMsg(ctx, sub.targetIdArr, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }), sub.platform);
806
+ await this.sendMsg(ctx, sub.target, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
803
807
  }
804
808
  else if (buffer) {
805
809
  this.logger.info('推送动态中,使用page模式');
806
810
  // pic不存在,说明使用的是page模式
807
- await this.sendMsg(ctx, sub.targetIdArr, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }), sub.platform);
811
+ await this.sendMsg(ctx, sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
808
812
  }
809
813
  else {
810
814
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -959,13 +963,13 @@ class ComRegister {
959
963
  if (e.message === '出现关键词,屏蔽该动态') {
960
964
  // 如果需要发送才发送
961
965
  if (this.config.filter.notify) {
962
- await this.sendMsg(ctx, sub.targetIdArr, `${upName}发布了一条含有屏蔽关键字的动态`, sub.platform);
966
+ await this.sendMsg(ctx, sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
963
967
  }
964
968
  return;
965
969
  }
966
970
  if (e.message === '已屏蔽转发动态') {
967
971
  if (this.config.filter.notify) {
968
- await this.sendMsg(ctx, sub.targetIdArr, `${upName}发布了一条转发动态,已屏蔽`, sub.platform);
972
+ await this.sendMsg(ctx, sub.target, `${upName}发布了一条转发动态,已屏蔽`);
969
973
  }
970
974
  return;
971
975
  }
@@ -983,12 +987,12 @@ class ComRegister {
983
987
  if (pic) {
984
988
  this.logger.info('推送动态中,使用render模式');
985
989
  // pic存在,使用的是render模式
986
- await this.sendMsg(ctx, sub.targetIdArr, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }), sub.platform);
990
+ await this.sendMsg(ctx, sub.target, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
987
991
  }
988
992
  else if (buffer) {
989
993
  this.logger.info('推送动态中,使用page模式');
990
994
  // pic不存在,说明使用的是page模式
991
- await this.sendMsg(ctx, sub.targetIdArr, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }), sub.platform);
995
+ await this.sendMsg(ctx, sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
992
996
  }
993
997
  else {
994
998
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -1002,7 +1006,7 @@ class ComRegister {
1002
1006
  }
1003
1007
  };
1004
1008
  }
1005
- liveDetect(ctx, roomId, guildId, platform) {
1009
+ liveDetect(ctx, roomId, target) {
1006
1010
  let firstSubscription = true;
1007
1011
  let timer = 0;
1008
1012
  let open = false;
@@ -1040,11 +1044,11 @@ class ComRegister {
1040
1044
  // pic 存在,使用的是render模式
1041
1045
  if (pic) {
1042
1046
  const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveNotifyMsg && liveNotifyMsg] });
1043
- return await this.sendMsg(ctx, guildId, pic + msg, platform);
1047
+ return await this.sendMsg(ctx, target, pic + msg);
1044
1048
  }
1045
1049
  // pic不存在,说明使用的是page模式
1046
1050
  const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveNotifyMsg && liveNotifyMsg] });
1047
- await this.sendMsg(ctx, guildId, msg, platform);
1051
+ await this.sendMsg(ctx, target, pic + msg);
1048
1052
  };
1049
1053
  // 定义获取主播信息方法
1050
1054
  let useMasterInfo;
@@ -1215,10 +1219,10 @@ class ComRegister {
1215
1219
  });
1216
1220
  return table ? table : '没有订阅任何UP';
1217
1221
  }
1218
- async checkIfNeedSub(liveSub, dynamicSub, session, data) {
1222
+ async checkIfNeedSub(liveSub, dynamicSub, session, liveRoomData) {
1219
1223
  // 定义方法:用户直播间是否存在
1220
1224
  const liveRoom = async () => {
1221
- if (!data.live_room) {
1225
+ if (!liveRoomData) {
1222
1226
  // 未开通直播间
1223
1227
  await session.send('该用户未开通直播间,无法订阅直播');
1224
1228
  // 返回false
@@ -1411,7 +1415,7 @@ class ComRegister {
1411
1415
  continue;
1412
1416
  }
1413
1417
  // 获取推送目标数组
1414
- const targetIdArr = sub.targetId.split(' ');
1418
+ const target = JSON.parse(sub.target);
1415
1419
  /* 判断数据库是否被篡改 */
1416
1420
  // 获取用户信息
1417
1421
  let content;
@@ -1475,7 +1479,7 @@ class ComRegister {
1475
1479
  id: sub.id,
1476
1480
  uid: sub.uid,
1477
1481
  roomId: sub.room_id,
1478
- targetIdArr,
1482
+ target,
1479
1483
  platform: sub.platform,
1480
1484
  live: +sub.live === 1 ? true : false,
1481
1485
  dynamic: +sub.dynamic === 1 ? true : false,
@@ -1495,7 +1499,7 @@ class ComRegister {
1495
1499
  // 直播订阅数+1
1496
1500
  liveSubNum++;
1497
1501
  // 订阅直播,开始循环检测
1498
- const dispose = ctx.setInterval(this.liveDetect(ctx, sub.room_id, targetIdArr, sub.platform), this.config.liveLoopTime * 1000);
1502
+ const dispose = ctx.setInterval(this.liveDetect(ctx, sub.room_id, target), this.config.liveLoopTime * 1000);
1499
1503
  // 保存销毁函数
1500
1504
  subManagerItem.liveDispose = dispose;
1501
1505
  }
package/lib/database.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface Bilibili {
12
12
  dynamic: number;
13
13
  video: number;
14
14
  live: number;
15
- targetId: string;
15
+ target: string;
16
16
  platform: string;
17
17
  time: Date;
18
18
  }
package/lib/database.js CHANGED
@@ -12,7 +12,7 @@ function apply(ctx) {
12
12
  dynamic: 'unsigned',
13
13
  video: 'unsigned',
14
14
  live: 'unsigned',
15
- targetId: 'string',
15
+ target: 'string',
16
16
  platform: 'string',
17
17
  time: 'timestamp'
18
18
  }, { autoInc: true });
package/lib/index.js CHANGED
@@ -358,6 +358,9 @@ function apply(ctx, config) {
358
358
  // 设置config
359
359
  globalConfig = config;
360
360
  // 设置提示
361
+ ctx.notifier.create({
362
+ content: '从2.0.0-alpha.7以前版本更新需重新订阅'
363
+ });
361
364
  ctx.notifier.create({
362
365
  content: '请使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令。'
363
366
  });
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": "2.0.0-alpha.6",
4
+ "version": "2.0.0-alpha.8",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],