koishi-plugin-bilibili-notify 2.0.0-alpha.10 → 2.0.0-alpha.12

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.
@@ -292,14 +292,14 @@ class ComRegister {
292
292
  return subTable;
293
293
  });
294
294
  biliCom
295
- .subcommand('.sub <mid:string>', '订阅用户动态和直播通知')
295
+ .subcommand('.sub <mid:string> [...groupId:string]', '订阅用户动态和直播通知')
296
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]+)*$/ })
297
297
  .option('live', '-l')
298
298
  .option('dynamic', '-d')
299
299
  .option('atAll', '-a')
300
300
  .usage('订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d')
301
301
  .example('bili sub 1194210119 目标群号或频道号 -l -d 订阅UID为1194210119的UP主的动态和直播')
302
- .action(async ({ session, options }, mid) => {
302
+ .action(async ({ session, options }, mid, ...groupId) => {
303
303
  this.logger.info('调用bili.sub指令');
304
304
  // 先判断是否订阅直播,再判断是否解锁订阅限制,最后判断直播订阅是否已超三个
305
305
  if (options.live && !this.config.unlockSubLimits && (this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3)) {
@@ -320,73 +320,91 @@ class ComRegister {
320
320
  return '订阅对象失败,请稍后重试!';
321
321
  // 定义目标变量
322
322
  let target = [];
323
- // 判断是否使用多平台功能
324
- if (options.multiplatform) {
325
- // 分割字符串,赋值给target
326
- target = this.splitMultiPlatformStr(options.multiplatform);
323
+ // 判断是否使用了多群组推送
324
+ if (groupId.length > 0) {
325
+ // 定义channelIdArr
326
+ const channelIdArr = [];
327
+ // 遍历输入的群组
328
+ groupId.forEach(group => {
329
+ channelIdArr.push({
330
+ channelId: group,
331
+ atAll: options.atAll
332
+ });
333
+ });
334
+ target.push({
335
+ channelIdArr,
336
+ platform: session.event.platform
337
+ });
327
338
  }
328
- // 判断是否使用了多平台
329
- if (target) {
330
- target.forEach(async ({ channelIdArr, platform }, index) => {
331
- if (channelIdArr.length > 0) { // 输入了推送群号或频道号
332
- // 拿到对应的bot
333
- const bot = this.getBot(ctx, platform);
334
- // 判断是否配置了对应平台的机器人
335
- if (!ctx.bots.some(bot => bot.platform === platform)) {
336
- await session.send('您未配置对应平台的机器人,不能在该平台进行订阅操作');
337
- }
338
- // 判断是否需要加入的群全部推送
339
- if (channelIdArr[0].channelId !== 'all') {
340
- // 定义满足条件的群组数组
341
- const targetArr = [];
342
- // 获取机器人加入的群组
343
- const guildList = await bot.getGuildList();
344
- // 遍历target数组
345
- for (const channelId of channelIdArr) {
346
- // 定义是否加入群组标志
347
- let flag = false;
348
- // 遍历群组
349
- for (const guild of guildList.data) {
350
- // 获取频道列表
351
- const channelList = await bot.getChannelList(guild.id);
352
- // 判断机器人是否加入群聊或频道
353
- if (channelList.data.some(channel => channel.id === channelId.channelId)) {
354
- // 加入群聊或频道
355
- targetArr.push(channelId);
356
- // 设置标志位为true
357
- flag = true;
358
- // 结束循环
359
- break;
339
+ else {
340
+ // 判断是否使用多平台功能
341
+ if (options.multiplatform) {
342
+ // 分割字符串,赋值给target
343
+ target = this.splitMultiPlatformStr(options.multiplatform);
344
+ }
345
+ // 判断是否使用了多平台
346
+ if (target) {
347
+ target.forEach(async ({ channelIdArr, platform }, index) => {
348
+ if (channelIdArr.length > 0) { // 输入了推送群号或频道号
349
+ // 拿到对应的bot
350
+ const bot = this.getBot(ctx, platform);
351
+ // 判断是否配置了对应平台的机器人
352
+ if (!ctx.bots.some(bot => bot.platform === platform)) {
353
+ await session.send('您未配置对应平台的机器人,不能在该平台进行订阅操作');
354
+ }
355
+ // 判断是否需要加入的群全部推送
356
+ if (channelIdArr[0].channelId !== 'all') {
357
+ // 定义满足条件的群组数组
358
+ const targetArr = [];
359
+ // 获取机器人加入的群组
360
+ const guildList = await bot.getGuildList();
361
+ // 遍历target数组
362
+ for (const channelId of channelIdArr) {
363
+ // 定义是否加入群组标志
364
+ let flag = false;
365
+ // 遍历群组
366
+ for (const guild of guildList.data) {
367
+ // 获取频道列表
368
+ const channelList = await bot.getChannelList(guild.id);
369
+ // 判断机器人是否加入群聊或频道
370
+ if (channelList.data.some(channel => channel.id === channelId.channelId)) {
371
+ // 加入群聊或频道
372
+ targetArr.push(channelId);
373
+ // 设置标志位为true
374
+ flag = true;
375
+ // 结束循环
376
+ break;
377
+ }
378
+ }
379
+ if (!flag) {
380
+ // 不满足条件发送错误提示
381
+ await session.send(`您的机器未加入${channelId.channelId},无法对该群或频道进行推送`);
360
382
  }
361
383
  }
362
- if (!flag) {
363
- // 不满足条件发送错误提示
364
- await session.send(`您的机器未加入${channelId.channelId},无法对该群或频道进行推送`);
384
+ // 判断targetArr是否为空
385
+ if (target.length === 0) {
386
+ // 为空则默认为当前环境
387
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
388
+ // 没有满足条件的群组或频道
389
+ await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
365
390
  }
391
+ // 将符合条件的群组添加到target中
392
+ target[index].channelIdArr = targetArr;
366
393
  }
367
- // 判断targetArr是否为空
368
- if (target.length === 0) {
369
- // 为空则默认为当前环境
370
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
371
- // 没有满足条件的群组或频道
372
- await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
373
- }
374
- // 将符合条件的群组添加到target中
375
- target[index].channelIdArr = targetArr;
394
+ // 如果为all则全部推送,不需要进行处理
376
395
  }
377
- // 如果为all则全部推送,不需要进行处理
378
- }
379
- else {
380
- // 未填写群号或频道号,默认为当前环境
381
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
382
- // 发送提示消息
383
- await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
384
- }
385
- });
386
- }
387
- else {
388
- // 用户直接订阅,将当前环境赋值给target
389
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
396
+ else {
397
+ // 未填写群号或频道号,默认为当前环境
398
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
399
+ // 发送提示消息
400
+ await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
401
+ }
402
+ });
403
+ }
404
+ else {
405
+ // 用户直接订阅,将当前环境赋值给target
406
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
407
+ }
390
408
  }
391
409
  // 定义外围变量
392
410
  let content;
@@ -645,7 +663,7 @@ class ComRegister {
645
663
  if (live) {
646
664
  // 直播推送,需要判断是否为
647
665
  for (const channel of sendArr) {
648
- await this.sendMsgFunc(bot, channel.channelId, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [channel.atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), content] }));
666
+ await this.sendMsgFunc(bot, channel.channelId, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [content, channel.atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" })] }));
649
667
  }
650
668
  }
651
669
  else {
@@ -1046,12 +1064,22 @@ class ComRegister {
1046
1064
  // 推送直播信息
1047
1065
  // pic 存在,使用的是render模式
1048
1066
  if (pic) {
1049
- const msg = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: liveNotifyMsg && liveNotifyMsg });
1050
- return await this.sendMsg(ctx, target, pic + msg, true);
1067
+ const msg = liveNotifyMsg ? liveNotifyMsg : '';
1068
+ // 只有在开播时才艾特全体成员
1069
+ if (liveType === LiveType.StartBroadcasting) {
1070
+ return await this.sendMsg(ctx, target, pic + msg, true);
1071
+ }
1072
+ // 正常不需要艾特全体成员
1073
+ return await this.sendMsg(ctx, target, pic + msg);
1051
1074
  }
1052
1075
  // pic不存在,说明使用的是page模式
1053
1076
  const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), liveNotifyMsg && liveNotifyMsg] });
1054
- await this.sendMsg(ctx, target, msg, true);
1077
+ // 只有在开播时才艾特全体成员
1078
+ if (liveType === LiveType.StartBroadcasting) {
1079
+ return await this.sendMsg(ctx, target, msg, true);
1080
+ }
1081
+ // 正常不需要艾特全体成员
1082
+ return await this.sendMsg(ctx, target, msg);
1055
1083
  };
1056
1084
  // 定义获取主播信息方法
1057
1085
  let useMasterInfo;
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.10",
4
+ "version": "2.0.0-alpha.12",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -53,9 +53,10 @@
53
53
 
54
54
  订阅UP主:订阅你想要推送的UP主
55
55
 
56
- - 使用指令 `bili sub <uid>` 订阅需要订阅的UP主
56
+ - 使用指令 `bili sub <uid> [...groupId]` 订阅需要订阅的UP主
57
57
  - 参数说明:
58
58
  - `uid` 为必填参数,为 `up主` 的 `uid`
59
+ - `groupId` 为可选参数,为需要推送的群号/频道号,可输入多个群号
59
60
  - 选项说明:`bili sub <uid>` 有四个选项:-l -d -m -a
60
61
  - `-l` 为订阅UP主直播间,包括直播开播通知,定时推送直播内容,下播通知
61
62
  - `-d` 为订阅UP主动态推送,目前实现推送的动态类型有:普通图文动态,转发动态,直播预约动态
@@ -196,6 +197,8 @@
196
197
  - ver 2.0.0-alpha.8 新增:重新订阅提示
197
198
  - ver 2.0.0-alpha.9 修复:订阅反复提示未加入群组的bug,实际已加入
198
199
  - ver 2.0.0-alpha.10 新增:可对每个群聊针对性设置是否艾特全体成员 优化:直播下播通知
200
+ - ver 2.0.0-alpha.11 回档:订阅时可直接接收群号/频道号 修复:直播过程推送消息不成功的bug
201
+ - ver 2.0.0-alpha.12 更改:开启艾特全体成员后,只有在开播时才艾特全体成员
199
202
 
200
203
  ## 交流群
201
204