koishi-plugin-bilibili-notify 2.0.0-alpha.16 → 2.0.0-alpha.18
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 +1 -0
- package/lib/biliAPI.js +13 -0
- package/lib/comRegister.js +12 -9
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/readme.md +2 -0
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);
|
package/lib/comRegister.js
CHANGED
|
@@ -293,7 +293,7 @@ class ComRegister {
|
|
|
293
293
|
target = this.splitMultiPlatformStr(options.multiplatform);
|
|
294
294
|
}
|
|
295
295
|
// 判断是否使用了多平台
|
|
296
|
-
if (target) {
|
|
296
|
+
if (target.length > 0) {
|
|
297
297
|
for (const [index, { channelIdArr, platform }] of target.entries()) {
|
|
298
298
|
if (channelIdArr.length > 0) { // 输入了推送群号或频道号
|
|
299
299
|
// 拿到对应的bot
|
|
@@ -337,7 +337,7 @@ class ComRegister {
|
|
|
337
337
|
// 判断targetArr是否为空
|
|
338
338
|
if (target.length === 0) {
|
|
339
339
|
// 为空则默认为当前环境
|
|
340
|
-
target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, 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 }];
|
|
341
341
|
// 没有满足条件的群组或频道
|
|
342
342
|
await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
|
|
343
343
|
}
|
|
@@ -348,7 +348,7 @@ class ComRegister {
|
|
|
348
348
|
}
|
|
349
349
|
else {
|
|
350
350
|
// 未填写群号或频道号,默认为当前环境
|
|
351
|
-
target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, 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 }];
|
|
352
352
|
// 发送提示消息
|
|
353
353
|
await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
|
|
354
354
|
}
|
|
@@ -356,7 +356,7 @@ class ComRegister {
|
|
|
356
356
|
}
|
|
357
357
|
else {
|
|
358
358
|
// 用户直接订阅,将当前环境赋值给target
|
|
359
|
-
target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, 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 }];
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
// 定义外围变量
|
|
@@ -1165,9 +1165,14 @@ class ComRegister {
|
|
|
1165
1165
|
if (data.live_status === 1) { // 当前正在直播
|
|
1166
1166
|
// 设置开播时间
|
|
1167
1167
|
liveTime = data.live_time;
|
|
1168
|
+
// 设置直播中消息
|
|
1169
|
+
const liveMsg = this.config.customLive ? this.config.customLive
|
|
1170
|
+
.replace('-name', username)
|
|
1171
|
+
.replace('-time', await ctx.gi.getTimeDifference(liveTime))
|
|
1172
|
+
.replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`) : '';
|
|
1168
1173
|
// 发送直播通知卡片
|
|
1169
1174
|
if (this.config.restartPush)
|
|
1170
|
-
sendLiveNotifyCard(data, LiveType.LiveBroadcast);
|
|
1175
|
+
sendLiveNotifyCard(data, LiveType.LiveBroadcast, liveMsg);
|
|
1171
1176
|
// 改变开播状态
|
|
1172
1177
|
open = true;
|
|
1173
1178
|
} // 未开播,直接返回
|
|
@@ -1218,7 +1223,7 @@ class ComRegister {
|
|
|
1218
1223
|
}
|
|
1219
1224
|
}
|
|
1220
1225
|
}
|
|
1221
|
-
// 定义开播通知语
|
|
1226
|
+
// 定义开播通知语
|
|
1222
1227
|
const liveStartMsg = this.config.customLiveStart
|
|
1223
1228
|
.replace('-name', username)
|
|
1224
1229
|
.replace('-time', await ctx.gi.getTimeDifference(liveTime))
|
|
@@ -1455,9 +1460,7 @@ class ComRegister {
|
|
|
1455
1460
|
// 判断是否订阅直播
|
|
1456
1461
|
if (sub.live) {
|
|
1457
1462
|
// 订阅直播
|
|
1458
|
-
liveDispose = ctx.setInterval(()
|
|
1459
|
-
this.liveDetect(ctx, data.live_room.room_id, sub.target);
|
|
1460
|
-
}, this.config.liveLoopTime * 1000);
|
|
1463
|
+
liveDispose = ctx.setInterval(this.liveDetect(ctx, data.live_room.roomid, sub.target), this.config.liveLoopTime * 1000);
|
|
1461
1464
|
}
|
|
1462
1465
|
}
|
|
1463
1466
|
// 在B站中订阅该对象
|
package/lib/index.js
CHANGED
|
@@ -314,6 +314,7 @@ class ServerManager extends koishi_1.Service {
|
|
|
314
314
|
restartPush: globalConfig.restartPush,
|
|
315
315
|
pushTime: globalConfig.pushTime,
|
|
316
316
|
customLiveStart: globalConfig.customLiveStart,
|
|
317
|
+
customLive: globalConfig.customLive,
|
|
317
318
|
customLiveEnd: globalConfig.customLiveEnd,
|
|
318
319
|
dynamicCheckNumber: globalConfig.dynamicCheckNumber,
|
|
319
320
|
dynamicLoopTime: this.dynamicLoopTime,
|
package/package.json
CHANGED
package/readme.md
CHANGED