koishi-plugin-bilibili-notify 2.0.0-alpha.15 → 2.0.0-alpha.17

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.
package/lib/biliAPI.d.ts CHANGED
@@ -26,6 +26,7 @@ declare class BiliAPI extends Service {
26
26
  }): Promise<string>;
27
27
  encrypt(text: string): string;
28
28
  decrypt(text: string): string;
29
+ getLiveRoomInfoStreamKey(roomId: string): Promise<any>;
29
30
  getServerUTCTime(): Promise<number>;
30
31
  getTimeNow(): Promise<any>;
31
32
  getAllGroup(): Promise<any>;
package/lib/biliAPI.js CHANGED
@@ -41,6 +41,8 @@ const MODIFY_GROUP_MEMBER = 'https://api.bilibili.com/x/relation/tags/addUsers';
41
41
  const GET_ALL_GROUP = 'https://api.bilibili.com/x/relation/tags';
42
42
  const COPY_USER_TO_GROUP = 'https://api.bilibili.com/x/relation/tags/copyUsers';
43
43
  const GET_RELATION_GROUP_DETAIL = 'https://api.bilibili.com/x/relation/tag';
44
+ // 直播
45
+ const GET_LIVE_ROOM_INFO_STREAM_KEY = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo';
44
46
  class BiliAPI extends koishi_1.Service {
45
47
  static inject = ['database', 'notifier'];
46
48
  jar;
@@ -103,6 +105,17 @@ class BiliAPI extends koishi_1.Service {
103
105
  return decrypted.toString();
104
106
  }
105
107
  // BA API
108
+ async getLiveRoomInfoStreamKey(roomId) {
109
+ try {
110
+ // 获取直播间信息流密钥
111
+ const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
112
+ // 返回data
113
+ return data;
114
+ }
115
+ catch (e) {
116
+ throw new Error('网络异常,本次请求失败!');
117
+ }
118
+ }
106
119
  async getServerUTCTime() {
107
120
  try {
108
121
  const { data } = await this.client.get(GET_SERVER_UTC_TIME);
@@ -3,6 +3,8 @@ import { Notifier } from "@koishijs/plugin-notifier";
3
3
  import { LoginBili } from "./database";
4
4
  type ChannelIdArr = Array<{
5
5
  channelId: string;
6
+ dynamic: boolean;
7
+ live: boolean;
6
8
  atAll: boolean;
7
9
  }>;
8
10
  type TargetItem = {
@@ -69,7 +71,15 @@ declare namespace ComRegister {
69
71
  uid: string;
70
72
  dynamic: boolean;
71
73
  live: boolean;
72
- target: string;
74
+ target: Array<{
75
+ channelIdArr: Array<{
76
+ channelId: string;
77
+ dynamic: boolean;
78
+ live: boolean;
79
+ atAll: boolean;
80
+ }>;
81
+ platform: string;
82
+ }>;
73
83
  }>;
74
84
  master: {
75
85
  enable: boolean;
@@ -276,6 +276,8 @@ class ComRegister {
276
276
  groupId.forEach(group => {
277
277
  channelIdArr.push({
278
278
  channelId: group,
279
+ dynamic: true,
280
+ live: true,
279
281
  atAll: options.atAll
280
282
  });
281
283
  });
@@ -291,7 +293,7 @@ class ComRegister {
291
293
  target = this.splitMultiPlatformStr(options.multiplatform);
292
294
  }
293
295
  // 判断是否使用了多平台
294
- if (target) {
296
+ if (target.length > 0) {
295
297
  for (const [index, { channelIdArr, platform }] of target.entries()) {
296
298
  if (channelIdArr.length > 0) { // 输入了推送群号或频道号
297
299
  // 拿到对应的bot
@@ -335,7 +337,7 @@ class ComRegister {
335
337
  // 判断targetArr是否为空
336
338
  if (target.length === 0) {
337
339
  // 为空则默认为当前环境
338
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
340
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
339
341
  // 没有满足条件的群组或频道
340
342
  await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
341
343
  }
@@ -346,7 +348,7 @@ class ComRegister {
346
348
  }
347
349
  else {
348
350
  // 未填写群号或频道号,默认为当前环境
349
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
351
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
350
352
  // 发送提示消息
351
353
  await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
352
354
  }
@@ -354,7 +356,7 @@ class ComRegister {
354
356
  }
355
357
  else {
356
358
  // 用户直接订阅,将当前环境赋值给target
357
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, atAll: options.atAll }], platform: session.event.platform }];
359
+ target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
358
360
  }
359
361
  }
360
362
  // 定义外围变量
@@ -587,7 +589,7 @@ class ComRegister {
587
589
  const channelIdArr = idStr.split(',').map(id => {
588
590
  const atAll = /@$/.test(id); // 使用正则表达式检查 id 是否以 @ 结尾
589
591
  const channelId = atAll ? id.slice(0, -1) : id; // 去除末尾的 @
590
- return { channelId, atAll };
592
+ return { channelId, dynamic: true, live: true, atAll };
591
593
  });
592
594
  return { channelIdArr, platform };
593
595
  });
@@ -658,22 +660,33 @@ class ComRegister {
658
660
  if (target.channelIdArr[0].channelId === 'all') {
659
661
  // 获取所有guild
660
662
  for (const guild of (await bot.getGuildList()).data) {
661
- sendArr.push({ channelId: guild.id, atAll: target.channelIdArr[0].atAll });
663
+ sendArr.push({
664
+ channelId: guild.id,
665
+ dynamic: target.channelIdArr[0].dynamic,
666
+ live: target.channelIdArr[0].live,
667
+ atAll: target.channelIdArr[0].atAll
668
+ });
662
669
  }
663
670
  }
664
671
  else {
665
672
  sendArr = target.channelIdArr;
666
673
  }
667
- // 循环给每个群组发送
674
+ // 判断是否是直播推送,如果是则需要进一步判断是否需要艾特群体成员
668
675
  if (live) {
669
- // 直播推送,需要判断是否为
676
+ // 直播开播推送,判断是否需要艾特全体成员
670
677
  for (const channel of sendArr) {
671
- 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" })] }));
678
+ // 判断是否需要推送直播消息
679
+ if (channel.live) {
680
+ 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" })] }));
681
+ }
672
682
  }
673
683
  }
674
684
  else {
675
685
  for (const channel of sendArr) {
676
- await this.sendMsgFunc(bot, channel.channelId, content);
686
+ // 判断是否需要推送动态消息和直播消息
687
+ if (channel.dynamic || channel.live) {
688
+ await this.sendMsgFunc(bot, channel.channelId, content);
689
+ }
677
690
  }
678
691
  }
679
692
  }
@@ -1405,8 +1418,6 @@ class ComRegister {
1405
1418
  }
1406
1419
  async loadSubFromConfig(ctx, subs) {
1407
1420
  for (const sub of subs) {
1408
- // 整理target
1409
- const target = this.splitMultiPlatformStr(sub.target);
1410
1421
  // 定义Data
1411
1422
  let data;
1412
1423
  // 定义直播销毁函数
@@ -1445,7 +1456,7 @@ class ComRegister {
1445
1456
  if (sub.live) {
1446
1457
  // 订阅直播
1447
1458
  liveDispose = ctx.setInterval(() => {
1448
- this.liveDetect(ctx, data.live_room.room_id, target);
1459
+ this.liveDetect(ctx, data.live_room.room_id, sub.target);
1449
1460
  }, this.config.liveLoopTime * 1000);
1450
1461
  }
1451
1462
  }
@@ -1459,7 +1470,7 @@ class ComRegister {
1459
1470
  id: +sub.uid,
1460
1471
  uid: sub.uid,
1461
1472
  roomId: sub.live ? data.live_room.roomid : '',
1462
- target,
1473
+ target: sub.target,
1463
1474
  platform: '',
1464
1475
  live: sub.live,
1465
1476
  dynamic: sub.dynamic,
@@ -1736,12 +1747,19 @@ class ComRegister {
1736
1747
  (function (ComRegister) {
1737
1748
  ComRegister.Config = koishi_1.Schema.object({
1738
1749
  sub: koishi_1.Schema.array(koishi_1.Schema.object({
1739
- uid: koishi_1.Schema.string(),
1740
- roomid: koishi_1.Schema.string(),
1741
- dynamic: koishi_1.Schema.boolean(),
1742
- live: koishi_1.Schema.boolean(),
1743
- target: koishi_1.Schema.string(),
1744
- })),
1750
+ uid: koishi_1.Schema.string().description('订阅用户UID'),
1751
+ dynamic: koishi_1.Schema.boolean().description('是否订阅用户动态'),
1752
+ live: koishi_1.Schema.boolean().description('是否订阅用户直播'),
1753
+ target: koishi_1.Schema.array(koishi_1.Schema.object({
1754
+ channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
1755
+ channelId: koishi_1.Schema.string().description('频道/群组号'),
1756
+ dynamic: koishi_1.Schema.boolean().description('该频道/群组是否推送动态信息'),
1757
+ live: koishi_1.Schema.boolean().description('该频道/群组是否推送直播通知'),
1758
+ atAll: koishi_1.Schema.boolean().description('推送开播通知时是否艾特全体成员')
1759
+ })).description('频道/群组信息'),
1760
+ platform: koishi_1.Schema.string().description('推送平台')
1761
+ })).description('订阅用户需要发送的频道/群组信息')
1762
+ })).role('table').description('手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播'),
1745
1763
  master: koishi_1.Schema.object({
1746
1764
  enable: koishi_1.Schema.boolean(),
1747
1765
  platform: koishi_1.Schema.string(),
package/lib/index.d.ts CHANGED
@@ -20,7 +20,15 @@ export interface Config {
20
20
  uid: string;
21
21
  dynamic: boolean;
22
22
  live: boolean;
23
- target: string;
23
+ target: Array<{
24
+ channelIdArr: Array<{
25
+ channelId: string;
26
+ dynamic: boolean;
27
+ live: boolean;
28
+ atAll: boolean;
29
+ }>;
30
+ platform: string;
31
+ }>;
24
32
  }>;
25
33
  dynamic: {};
26
34
  dynamicUrl: boolean;
package/lib/index.js CHANGED
@@ -95,11 +95,19 @@ exports.Config = koishi_1.Schema.object({
95
95
  .description('设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111'),
96
96
  subTitle: koishi_1.Schema.object({}).description('手动订阅'),
97
97
  sub: koishi_1.Schema.array(koishi_1.Schema.object({
98
- uid: koishi_1.Schema.string(),
99
- dynamic: koishi_1.Schema.boolean(),
100
- live: koishi_1.Schema.boolean(),
101
- target: koishi_1.Schema.string()
102
- })).role('table').description('手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播,target:推送目标群组/频道号,若有多个请用逗号分隔'),
98
+ uid: koishi_1.Schema.string().description('订阅用户UID'),
99
+ dynamic: koishi_1.Schema.boolean().description('是否订阅用户动态'),
100
+ live: koishi_1.Schema.boolean().description('是否订阅用户直播'),
101
+ target: koishi_1.Schema.array(koishi_1.Schema.object({
102
+ channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
103
+ channelId: koishi_1.Schema.string().description('频道/群组号'),
104
+ dynamic: koishi_1.Schema.boolean().description('该频道/群组是否推送动态信息'),
105
+ live: koishi_1.Schema.boolean().description('该频道/群组是否推送直播通知'),
106
+ atAll: koishi_1.Schema.boolean().description('推送开播通知时是否艾特全体成员')
107
+ })).description('频道/群组信息'),
108
+ platform: koishi_1.Schema.string().description('推送平台')
109
+ })).description('订阅用户需要发送的频道/群组信息')
110
+ })).role('table').description('手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播'),
103
111
  dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
104
112
  dynamicUrl: koishi_1.Schema.boolean()
105
113
  .default(false)
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.15",
4
+ "version": "2.0.0-alpha.17",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -202,6 +202,8 @@
202
202
  - ver 2.0.0-alpha.13 修复:无法对TG群组的特殊频道号进行订阅处理;提示 `您未配置对应平台的机器人,不能在该平台进行订阅操作` 仍进行订阅操作
203
203
  - ver 2.0.0-alpha.14 修复:订阅TG群组时提示输入无效
204
204
  - ver 2.0.0-alpha.15 新增:手动订阅功能 修复:一些潜在的bug
205
+ - ver 2.0.0-alpha.16 优化:手动订阅功能
206
+ - ver 2.0.0-alpha.17 修复:直接订阅当前环境不会推送
205
207
 
206
208
  ## 交流群
207
209