koishi-plugin-bilibili-notify 3.0.0-alpha.15 → 3.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/comRegister.d.ts +4 -43
- package/lib/comRegister.js +204 -834
- package/lib/database.d.ts +0 -11
- package/lib/database.js +0 -11
- package/lib/generateImg.d.ts +2 -1
- package/lib/generateImg.js +31 -26
- package/lib/index.d.ts +1 -1
- package/lib/index.js +18 -22
- package/lib/type/index.d.ts +37 -0
- package/lib/type/index.js +11 -0
- package/package.json +1 -1
- package/readme.md +4 -34
package/lib/comRegister.js
CHANGED
|
@@ -7,16 +7,10 @@ const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
|
|
|
7
7
|
const koishi_1 = require("koishi");
|
|
8
8
|
// 导入qrcode
|
|
9
9
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
10
|
+
const type_1 = require("./type");
|
|
10
11
|
// 弹幕词云
|
|
11
12
|
// TODO:WorlCloud
|
|
12
13
|
// import { Segment } from "segmentit";
|
|
13
|
-
var LiveType;
|
|
14
|
-
(function (LiveType) {
|
|
15
|
-
LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
16
|
-
LiveType[LiveType["StartBroadcasting"] = 1] = "StartBroadcasting";
|
|
17
|
-
LiveType[LiveType["LiveBroadcast"] = 2] = "LiveBroadcast";
|
|
18
|
-
LiveType[LiveType["StopBroadcast"] = 3] = "StopBroadcast";
|
|
19
|
-
})(LiveType || (LiveType = {}));
|
|
20
14
|
class ComRegister {
|
|
21
15
|
// 必须服务
|
|
22
16
|
static inject = ["ba", "gi", "database", "bl", "sm"];
|
|
@@ -183,8 +177,6 @@ class ComRegister {
|
|
|
183
177
|
this.loginTimer();
|
|
184
178
|
// 订阅手动订阅中的订阅
|
|
185
179
|
await this.loadSubFromConfig(config.sub);
|
|
186
|
-
// 订阅之前的订阅
|
|
187
|
-
await this.loadSubFromDatabase();
|
|
188
180
|
// 清除控制台通知
|
|
189
181
|
ctx.ba.disposeNotifier();
|
|
190
182
|
// 发送成功登录推送
|
|
@@ -201,413 +193,13 @@ class ComRegister {
|
|
|
201
193
|
}, 1000);
|
|
202
194
|
});
|
|
203
195
|
biliCom
|
|
204
|
-
.subcommand(".
|
|
205
|
-
.usage("取消订阅,加-l为取消直播订阅,加-d为取消动态订阅,什么都不加则为全部取消")
|
|
206
|
-
.option("live", "-l")
|
|
207
|
-
.option("dynamic", "-d")
|
|
208
|
-
.example("bili unsub 用户UID -ld")
|
|
209
|
-
.action(async ({ session, options }, uid) => {
|
|
210
|
-
this.logger.info("调用bili.unsub指令");
|
|
211
|
-
// 若用户UID为空则直接返回
|
|
212
|
-
if (!uid)
|
|
213
|
-
return "用户UID不能为空";
|
|
214
|
-
// -d -l两个选项不能同时存在
|
|
215
|
-
if (options.dynamic && options.live)
|
|
216
|
-
return "需要取消订阅该UP主请直接使用指令bili unsub 用户UID";
|
|
217
|
-
// 定义是否存在
|
|
218
|
-
let exist;
|
|
219
|
-
await Promise.all(this.subManager.map(async (sub, i) => {
|
|
220
|
-
if (sub.uid === uid) {
|
|
221
|
-
// 取消单个订阅
|
|
222
|
-
if (options.live || options.dynamic) {
|
|
223
|
-
if (options.live)
|
|
224
|
-
await session.send(this.unsubSingle(sub.roomId, 0)); /* 0为取消订阅Live */
|
|
225
|
-
if (options.dynamic)
|
|
226
|
-
await session.send(this.unsubSingle(sub.uid, 1)); /* 1为取消订阅Dynamic */
|
|
227
|
-
// 将存在flag设置为true
|
|
228
|
-
exist = true;
|
|
229
|
-
// 结束循环
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
// 从数据库中删除订阅
|
|
233
|
-
await ctx.database.remove("bilibili", {
|
|
234
|
-
uid: this.subManager[i].uid,
|
|
235
|
-
});
|
|
236
|
-
// 将该订阅对象从订阅管理对象中移除
|
|
237
|
-
this.subManager.splice(i, 1);
|
|
238
|
-
// 将订阅对象移出订阅关注组
|
|
239
|
-
const removeUserFromGroupData = await ctx.ba.removeUserFromGroup(sub.uid);
|
|
240
|
-
// 判断是否移出成功 22105关注对象为自己
|
|
241
|
-
if (removeUserFromGroupData.code !== 0 &&
|
|
242
|
-
removeUserFromGroupData.code !== 22105) {
|
|
243
|
-
// 移出失败
|
|
244
|
-
await session.send("取消订阅对象失败,请稍后重试");
|
|
245
|
-
// 将存在flag设置为true
|
|
246
|
-
exist = true;
|
|
247
|
-
// 结束循环
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
// id--
|
|
251
|
-
this.num--;
|
|
252
|
-
// 判断是否还有动态订阅
|
|
253
|
-
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
254
|
-
// 发送成功通知
|
|
255
|
-
await session.send("已取消订阅该用户");
|
|
256
|
-
// 更新控制台提示
|
|
257
|
-
this.updateSubNotifier();
|
|
258
|
-
// 将存在flag设置为true
|
|
259
|
-
exist = true;
|
|
260
|
-
}
|
|
261
|
-
}));
|
|
262
|
-
// 未订阅该用户,无需取消订阅
|
|
263
|
-
if (!exist)
|
|
264
|
-
await session.send("未订阅该用户,无需取消订阅");
|
|
265
|
-
});
|
|
266
|
-
biliCom
|
|
267
|
-
.subcommand(".show", "展示订阅对象")
|
|
196
|
+
.subcommand(".list", "展示订阅对象")
|
|
268
197
|
.usage("展示订阅对象")
|
|
269
|
-
.example("bili
|
|
198
|
+
.example("bili list")
|
|
270
199
|
.action(() => {
|
|
271
200
|
const subTable = this.subShow();
|
|
272
201
|
return subTable;
|
|
273
202
|
});
|
|
274
|
-
biliCom
|
|
275
|
-
.subcommand(".sub <mid:string> [...groupId:string]", "订阅用户动态和直播通知")
|
|
276
|
-
.option("multiplatform", "-m <value:string>", {
|
|
277
|
-
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]+))*$/,
|
|
278
|
-
})
|
|
279
|
-
.option("live", "-l")
|
|
280
|
-
.option("dynamic", "-d")
|
|
281
|
-
.option("atAll", "-a")
|
|
282
|
-
.usage("订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d")
|
|
283
|
-
.example("bili sub 1194210119 目标群号或频道号 -l -d 订阅UID为1194210119的UP主的动态和直播")
|
|
284
|
-
.action(async ({ session, options }, mid, ...groupId) => {
|
|
285
|
-
this.logger.info("调用bili.sub指令");
|
|
286
|
-
// 先判断是否订阅直播,再判断是否解锁订阅限制,最后判断直播订阅是否已超三个
|
|
287
|
-
if (options.live &&
|
|
288
|
-
!this.config.unlockSubLimits &&
|
|
289
|
-
this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3) {
|
|
290
|
-
return "直播订阅已达上限,请取消部分直播订阅后再进行订阅";
|
|
291
|
-
}
|
|
292
|
-
// 检查是否登录
|
|
293
|
-
if (!(await this.checkIfIsLogin())) {
|
|
294
|
-
// 未登录直接返回
|
|
295
|
-
return "请使用指令bili login登录后再进行订阅操作";
|
|
296
|
-
}
|
|
297
|
-
// 检查必选参数是否已填
|
|
298
|
-
if (!mid)
|
|
299
|
-
return "请输入用户uid";
|
|
300
|
-
// 订阅对象
|
|
301
|
-
const subUserData = await this.subUserInBili(mid);
|
|
302
|
-
// 判断是否订阅对象存在
|
|
303
|
-
if (!subUserData.flag)
|
|
304
|
-
return "订阅对象失败,请稍后重试!";
|
|
305
|
-
// 定义目标变量
|
|
306
|
-
let target = [];
|
|
307
|
-
// 判断是否使用了多群组推送
|
|
308
|
-
if (groupId.length > 0) {
|
|
309
|
-
// 定义channelIdArr
|
|
310
|
-
const channelIdArr = [];
|
|
311
|
-
// 遍历输入的群组
|
|
312
|
-
for (const group of groupId) {
|
|
313
|
-
channelIdArr.push({
|
|
314
|
-
channelId: group,
|
|
315
|
-
dynamic: true,
|
|
316
|
-
live: true,
|
|
317
|
-
liveGuardBuy: false,
|
|
318
|
-
atAll: options.atAll,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
target.push({
|
|
322
|
-
channelIdArr,
|
|
323
|
-
platform: session.event.platform,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
// 判断是否使用多平台功能
|
|
328
|
-
if (options.multiplatform) {
|
|
329
|
-
// 分割字符串,赋值给target
|
|
330
|
-
target = this.splitMultiPlatformStr(options.multiplatform);
|
|
331
|
-
}
|
|
332
|
-
// 判断是否使用了多平台
|
|
333
|
-
if (target.length > 0) {
|
|
334
|
-
for (const [index, { channelIdArr, platform },] of target.entries()) {
|
|
335
|
-
if (channelIdArr.length > 0) {
|
|
336
|
-
// 输入了推送群号或频道号
|
|
337
|
-
// 拿到对应的bot
|
|
338
|
-
const bot = this.getBot(platform);
|
|
339
|
-
// 判断是否配置了对应平台的机器人
|
|
340
|
-
if (!ctx.bots.some((bot) => bot.platform === platform)) {
|
|
341
|
-
// 发送提示消息
|
|
342
|
-
await session.send("您未配置对应平台的机器人,不能在该平台进行订阅操作");
|
|
343
|
-
// 直接返回
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
// 判断是否需要加入的群全部推送
|
|
347
|
-
if (channelIdArr[0].channelId !== "all") {
|
|
348
|
-
// 定义满足条件的群组数组
|
|
349
|
-
const targetArr = [];
|
|
350
|
-
// 获取机器人加入的群组
|
|
351
|
-
const guildList = await bot.getGuildList();
|
|
352
|
-
// 遍历target数组
|
|
353
|
-
for (const channelId of channelIdArr) {
|
|
354
|
-
// 定义是否加入群组标志
|
|
355
|
-
let flag = false;
|
|
356
|
-
// 遍历群组
|
|
357
|
-
for (const guild of guildList.data) {
|
|
358
|
-
// 获取频道列表
|
|
359
|
-
const channelList = await bot.getChannelList(guild.id);
|
|
360
|
-
// 判断机器人是否加入群聊或频道
|
|
361
|
-
if (channelList.data.some((channel) => channel.id === channelId.channelId)) {
|
|
362
|
-
// 加入群聊或频道
|
|
363
|
-
targetArr.push(channelId);
|
|
364
|
-
// 设置标志位为true
|
|
365
|
-
flag = true;
|
|
366
|
-
// 结束循环
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if (!flag) {
|
|
371
|
-
// 不满足条件发送错误提示
|
|
372
|
-
await session.send(`您的机器未加入${channelId.channelId},无法对该群或频道进行推送`);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
// 判断targetArr是否为空
|
|
376
|
-
if (target.length === 0) {
|
|
377
|
-
// 为空则默认为当前环境
|
|
378
|
-
target = [
|
|
379
|
-
{
|
|
380
|
-
channelIdArr: [
|
|
381
|
-
{
|
|
382
|
-
channelId: session.event.channel.id,
|
|
383
|
-
dynamic: true,
|
|
384
|
-
live: true,
|
|
385
|
-
liveGuardBuy: false,
|
|
386
|
-
atAll: options.atAll ? options.atAll : false,
|
|
387
|
-
},
|
|
388
|
-
],
|
|
389
|
-
platform: session.event.platform,
|
|
390
|
-
},
|
|
391
|
-
];
|
|
392
|
-
// 没有满足条件的群组或频道
|
|
393
|
-
await session.send("没有满足条件的群组或频道,默认订阅到当前聊天环境");
|
|
394
|
-
}
|
|
395
|
-
// 将符合条件的群组添加到target中
|
|
396
|
-
target[index].channelIdArr = targetArr;
|
|
397
|
-
}
|
|
398
|
-
// 如果为all则全部推送,不需要进行处理
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
// 未填写群号或频道号,默认为当前环境
|
|
402
|
-
target = [
|
|
403
|
-
{
|
|
404
|
-
channelIdArr: [
|
|
405
|
-
{
|
|
406
|
-
channelId: session.event.channel.id,
|
|
407
|
-
dynamic: true,
|
|
408
|
-
live: true,
|
|
409
|
-
liveGuardBuy: false,
|
|
410
|
-
atAll: options.atAll ? options.atAll : false,
|
|
411
|
-
},
|
|
412
|
-
],
|
|
413
|
-
platform: session.event.platform,
|
|
414
|
-
},
|
|
415
|
-
];
|
|
416
|
-
// 发送提示消息
|
|
417
|
-
await session.send("没有填写群号或频道号,默认订阅到当前聊天环境");
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
// 用户直接订阅,将当前环境赋值给target
|
|
423
|
-
target = [
|
|
424
|
-
{
|
|
425
|
-
channelIdArr: [
|
|
426
|
-
{
|
|
427
|
-
channelId: session.event.channel.id,
|
|
428
|
-
dynamic: true,
|
|
429
|
-
live: true,
|
|
430
|
-
liveGuardBuy: false,
|
|
431
|
-
atAll: options.atAll ? options.atAll : false,
|
|
432
|
-
},
|
|
433
|
-
],
|
|
434
|
-
platform: session.event.platform,
|
|
435
|
-
},
|
|
436
|
-
];
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
// 定义外围变量
|
|
440
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
441
|
-
let content;
|
|
442
|
-
try {
|
|
443
|
-
// 获取用户信息
|
|
444
|
-
content = await ctx.ba.getUserInfo(mid);
|
|
445
|
-
}
|
|
446
|
-
catch (e) {
|
|
447
|
-
// 返回错误信息
|
|
448
|
-
return `bili sub getUserInfo() 发生了错误,错误为:${e.message}`;
|
|
449
|
-
}
|
|
450
|
-
// 判断是否成功获取用户信息
|
|
451
|
-
if (content.code !== 0) {
|
|
452
|
-
// 定义错误消息
|
|
453
|
-
let msg;
|
|
454
|
-
// 判断错误代码
|
|
455
|
-
switch (content.code) {
|
|
456
|
-
case -400:
|
|
457
|
-
msg = "请求错误";
|
|
458
|
-
break;
|
|
459
|
-
case -403:
|
|
460
|
-
msg = "访问权限不足,请尝试重新登录";
|
|
461
|
-
break;
|
|
462
|
-
case -404:
|
|
463
|
-
msg = "用户不存在";
|
|
464
|
-
break;
|
|
465
|
-
case -352:
|
|
466
|
-
msg = "风控校验失败,请尝试更换UA";
|
|
467
|
-
break;
|
|
468
|
-
default:
|
|
469
|
-
msg = `未知错误,错误信息:${content.message}`;
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
// 返回错误信息
|
|
473
|
-
return msg;
|
|
474
|
-
}
|
|
475
|
-
// 获取data
|
|
476
|
-
const { data } = content;
|
|
477
|
-
// 判断是否需要订阅直播和动态
|
|
478
|
-
const [liveMsg, dynamicMsg] = await this.checkIfNeedSub(options.live, options.dynamic, session, data.live_room);
|
|
479
|
-
// 判断是否未订阅任何消息
|
|
480
|
-
if (!liveMsg && !dynamicMsg)
|
|
481
|
-
return "您未订阅该UP的任何消息";
|
|
482
|
-
// 获取到对应的订阅对象
|
|
483
|
-
const subUser = this.subManager.find((sub) => sub.uid === mid);
|
|
484
|
-
// 判断要订阅的用户是否已经存在于订阅管理对象中
|
|
485
|
-
if (subUser) {
|
|
486
|
-
// 已存在,判断是否重复订阅直播通知
|
|
487
|
-
if (liveMsg && subUser.live) {
|
|
488
|
-
return "已订阅该用户直播通知,请勿重复订阅";
|
|
489
|
-
}
|
|
490
|
-
// 已存在,判断是否重复订阅动态通知
|
|
491
|
-
if (dynamicMsg && subUser.dynamic) {
|
|
492
|
-
return "已订阅该用户动态通知,请勿重复订阅";
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
// 获取直播房间号
|
|
496
|
-
const roomId = data.live_room?.roomid.toString();
|
|
497
|
-
// 获取用户信息
|
|
498
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
499
|
-
let userData;
|
|
500
|
-
try {
|
|
501
|
-
const { data } = await ctx.ba.getMasterInfo(mid);
|
|
502
|
-
userData = data;
|
|
503
|
-
}
|
|
504
|
-
catch (e) {
|
|
505
|
-
this.logger.error(`bili sub指令 getMasterInfo() 发生了错误,错误为:${e.message}`);
|
|
506
|
-
return "订阅出错啦,请重试";
|
|
507
|
-
}
|
|
508
|
-
const liveDetectModeSelector = {
|
|
509
|
-
API: async () => {
|
|
510
|
-
// 判断是否已开启直播检测
|
|
511
|
-
if (!this.liveDispose) {
|
|
512
|
-
// 未开启直播检测
|
|
513
|
-
// 开启直播检测并保存销毁函数
|
|
514
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
WS: async () => {
|
|
518
|
-
// 连接到服务器
|
|
519
|
-
await this.liveDetectWithListener(roomId, target);
|
|
520
|
-
},
|
|
521
|
-
};
|
|
522
|
-
// 订阅直播
|
|
523
|
-
if (liveMsg) {
|
|
524
|
-
// 判断直播订阅方式
|
|
525
|
-
await liveDetectModeSelector[this.config.liveDetectMode]();
|
|
526
|
-
// 发送订阅消息通知
|
|
527
|
-
await session.send(`订阅${userData.info.uname}直播通知`);
|
|
528
|
-
}
|
|
529
|
-
// 订阅动态
|
|
530
|
-
if (dynamicMsg) {
|
|
531
|
-
// 判断是否开启动态监测
|
|
532
|
-
if (!this.dynamicDispose) {
|
|
533
|
-
// 开启动态监测
|
|
534
|
-
this.enableDynamicDetect();
|
|
535
|
-
}
|
|
536
|
-
// 发送订阅消息通知
|
|
537
|
-
await session.send(`订阅${userData.info.uname}动态通知`);
|
|
538
|
-
}
|
|
539
|
-
// 保存到数据库中
|
|
540
|
-
const sub = await ctx.database.create("bilibili", {
|
|
541
|
-
uid: mid,
|
|
542
|
-
room_id: roomId,
|
|
543
|
-
dynamic: dynamicMsg ? 1 : 0,
|
|
544
|
-
live: liveMsg ? 1 : 0,
|
|
545
|
-
target: JSON.stringify(target),
|
|
546
|
-
platform: session.event.platform,
|
|
547
|
-
time: new Date(),
|
|
548
|
-
});
|
|
549
|
-
// 订阅数+1
|
|
550
|
-
this.num++;
|
|
551
|
-
// 保存新订阅对象
|
|
552
|
-
this.subManager.push({
|
|
553
|
-
id: sub.id,
|
|
554
|
-
uid: mid,
|
|
555
|
-
roomId,
|
|
556
|
-
target,
|
|
557
|
-
platform: session.event.platform,
|
|
558
|
-
live: liveMsg,
|
|
559
|
-
dynamic: dynamicMsg,
|
|
560
|
-
});
|
|
561
|
-
// 新增订阅展示到控制台
|
|
562
|
-
this.updateSubNotifier();
|
|
563
|
-
});
|
|
564
|
-
biliCom
|
|
565
|
-
.subcommand(".status <roomId:string>", "查询主播当前直播状态", {
|
|
566
|
-
hidden: true,
|
|
567
|
-
})
|
|
568
|
-
.usage("查询主播当前直播状态")
|
|
569
|
-
.example("bili status 732")
|
|
570
|
-
.action(async ({ session }, roomId) => {
|
|
571
|
-
this.logger.info("调用bili.status指令");
|
|
572
|
-
if (!roomId)
|
|
573
|
-
return session.send("请输入房间号!");
|
|
574
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
575
|
-
let content;
|
|
576
|
-
try {
|
|
577
|
-
content = await ctx.ba.getLiveRoomInfo(roomId);
|
|
578
|
-
}
|
|
579
|
-
catch (e) {
|
|
580
|
-
return `bili status指令 getLiveRoomInfo() 发生了错误,错误为:${e.message}`;
|
|
581
|
-
}
|
|
582
|
-
const { data } = content;
|
|
583
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
584
|
-
let userData;
|
|
585
|
-
try {
|
|
586
|
-
const { data: userInfo } = await ctx.ba.getMasterInfo(data.uid);
|
|
587
|
-
userData = userInfo;
|
|
588
|
-
}
|
|
589
|
-
catch (e) {
|
|
590
|
-
return `bili status指令 getMasterInfo() 发生了错误,错误为:${e.message}`;
|
|
591
|
-
}
|
|
592
|
-
// B站出问题了
|
|
593
|
-
if (content.code !== 0) {
|
|
594
|
-
if (content.msg === "未找到该房间") {
|
|
595
|
-
session.send("未找到该房间");
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
session.send(`未知错误,错误信息为:${content.message}`);
|
|
599
|
-
}
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1
|
|
603
|
-
? LiveType.NotLiveBroadcast
|
|
604
|
-
: LiveType.LiveBroadcast);
|
|
605
|
-
// pic 存在,使用的是render模式
|
|
606
|
-
if (pic)
|
|
607
|
-
return pic;
|
|
608
|
-
// pic不存在,说明使用的是page模式
|
|
609
|
-
await session.send(koishi_1.h.image(buffer, "image/png"));
|
|
610
|
-
});
|
|
611
203
|
biliCom
|
|
612
204
|
.subcommand(".private", "向主人账号发送一条测试消息", { hidden: true })
|
|
613
205
|
.usage("向主人账号发送一条测试消息")
|
|
@@ -630,7 +222,6 @@ class ComRegister {
|
|
|
630
222
|
this.ctx.notifier.create({
|
|
631
223
|
content: "您未配置私人机器人,将无法向您推送机器人状态!",
|
|
632
224
|
});
|
|
633
|
-
this.logger.error("您未配置私人机器人,将无法向您推送机器人状态!");
|
|
634
225
|
}
|
|
635
226
|
// 判断消息发送方式
|
|
636
227
|
if (config.automaticResend) {
|
|
@@ -689,8 +280,6 @@ class ComRegister {
|
|
|
689
280
|
}
|
|
690
281
|
// 从配置获取订阅
|
|
691
282
|
config.sub && (await this.loadSubFromConfig(config.sub));
|
|
692
|
-
// 从数据库获取订阅
|
|
693
|
-
await this.loadSubFromDatabase();
|
|
694
283
|
// 检查是否需要动态监测
|
|
695
284
|
this.checkIfDynamicDetectIsNeeded();
|
|
696
285
|
// 在控制台中显示订阅对象
|
|
@@ -714,25 +303,6 @@ class ComRegister {
|
|
|
714
303
|
const buffer = await this.ctx.gi.generateWordCloudImg();
|
|
715
304
|
this.sendMsg(testTarget, h.image(buffer, "image/png")); */
|
|
716
305
|
}
|
|
717
|
-
splitMultiPlatformStr(str) {
|
|
718
|
-
return str
|
|
719
|
-
.split(";")
|
|
720
|
-
.map((cv) => cv.split("."))
|
|
721
|
-
.map(([idStr, platform]) => {
|
|
722
|
-
const channelIdArr = idStr.split(",").map((id) => {
|
|
723
|
-
const atAll = /@$/.test(id); // 使用正则表达式检查 id 是否以 @ 结尾
|
|
724
|
-
const channelId = atAll ? id.slice(0, -1) : id; // 去除末尾的 @
|
|
725
|
-
return {
|
|
726
|
-
channelId,
|
|
727
|
-
dynamic: true,
|
|
728
|
-
live: true,
|
|
729
|
-
liveGuardBuy: false,
|
|
730
|
-
atAll,
|
|
731
|
-
};
|
|
732
|
-
});
|
|
733
|
-
return { channelIdArr, platform };
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
306
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
737
307
|
getBot(pf) {
|
|
738
308
|
return this.ctx.bots.find((bot) => bot.platform === pf);
|
|
@@ -1237,7 +807,7 @@ class ComRegister {
|
|
|
1237
807
|
};
|
|
1238
808
|
}
|
|
1239
809
|
// 定义发送直播通知卡片方法
|
|
1240
|
-
async sendLiveNotifyCard(info, liveType, liveNotifyMsg) {
|
|
810
|
+
async sendLiveNotifyCard(info, liveType, followerDisplay, liveNotifyMsg) {
|
|
1241
811
|
// 定义变量
|
|
1242
812
|
let pic;
|
|
1243
813
|
let buffer;
|
|
@@ -1246,7 +816,7 @@ class ComRegister {
|
|
|
1246
816
|
for (let i = 0; i < attempts; i++) {
|
|
1247
817
|
try {
|
|
1248
818
|
// 获取直播通知卡片
|
|
1249
|
-
const { pic: picv, buffer: bufferv } = await this.ctx.gi.generateLiveImg(info.data, info.username, info.userface, liveType);
|
|
819
|
+
const { pic: picv, buffer: bufferv } = await this.ctx.gi.generateLiveImg(info.data, info.username, info.userface, followerDisplay, liveType);
|
|
1250
820
|
// 赋值
|
|
1251
821
|
pic = picv;
|
|
1252
822
|
buffer = bufferv;
|
|
@@ -1266,7 +836,7 @@ class ComRegister {
|
|
|
1266
836
|
// pic 存在,使用的是render模式
|
|
1267
837
|
if (pic) {
|
|
1268
838
|
// 只有在开播时才艾特全体成员
|
|
1269
|
-
if (liveType === LiveType.StartBroadcasting) {
|
|
839
|
+
if (liveType === type_1.LiveType.StartBroadcasting) {
|
|
1270
840
|
return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ""), true);
|
|
1271
841
|
}
|
|
1272
842
|
// 正常不需要艾特全体成员
|
|
@@ -1275,19 +845,47 @@ class ComRegister {
|
|
|
1275
845
|
// pic不存在,说明使用的是page模式
|
|
1276
846
|
const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), liveNotifyMsg || ""] }));
|
|
1277
847
|
// 只有在开播时才艾特全体成员
|
|
1278
|
-
if (liveType === LiveType.StartBroadcasting) {
|
|
848
|
+
if (liveType === type_1.LiveType.StartBroadcasting) {
|
|
1279
849
|
return await this.sendMsg(info.target, msg, true);
|
|
1280
850
|
}
|
|
1281
851
|
// 正常不需要艾特全体成员
|
|
1282
852
|
return await this.sendMsg(info.target, msg);
|
|
1283
853
|
}
|
|
1284
854
|
// 定义获取主播信息方法
|
|
1285
|
-
async useMasterInfo(uid) {
|
|
855
|
+
async useMasterInfo(uid, masterInfo, liveType) {
|
|
856
|
+
// 获取主播信息
|
|
1286
857
|
const { data } = await this.ctx.ba.getMasterInfo(uid);
|
|
858
|
+
// 定义粉丝数变量
|
|
859
|
+
let liveOpenFollowerNum;
|
|
860
|
+
let liveEndFollowerNum;
|
|
861
|
+
let liveFollowerChange;
|
|
862
|
+
// 判断直播状态
|
|
863
|
+
if (liveType === type_1.LiveType.StartBroadcasting ||
|
|
864
|
+
liveType === type_1.LiveType.FirstLiveBroadcast) {
|
|
865
|
+
// 第一次启动或刚开播
|
|
866
|
+
// 将当前粉丝数赋值给liveOpenFollowerNum、liveEndFollowerNum
|
|
867
|
+
liveOpenFollowerNum = data.follower_num;
|
|
868
|
+
liveEndFollowerNum = data.follower_num;
|
|
869
|
+
// 将粉丝数变化赋值为0
|
|
870
|
+
liveFollowerChange = 0;
|
|
871
|
+
}
|
|
872
|
+
if (liveType === type_1.LiveType.StopBroadcast ||
|
|
873
|
+
liveType === type_1.LiveType.LiveBroadcast) {
|
|
874
|
+
// 将上一次的liveOpenFollowerNum赋值给本次的liveOpenFollowerNum
|
|
875
|
+
liveOpenFollowerNum = masterInfo.liveOpenFollowerNum;
|
|
876
|
+
// 将当前粉丝数赋值给liveEndFollowerNum
|
|
877
|
+
liveEndFollowerNum = data.follower_num;
|
|
878
|
+
// 计算粉丝数变化量
|
|
879
|
+
liveFollowerChange = liveEndFollowerNum - masterInfo.liveOpenFollowerNum;
|
|
880
|
+
}
|
|
881
|
+
// 返回值
|
|
1287
882
|
return {
|
|
1288
883
|
username: data.info.uname,
|
|
1289
884
|
userface: data.info.face,
|
|
1290
885
|
roomId: data.room_id,
|
|
886
|
+
liveOpenFollowerNum,
|
|
887
|
+
liveEndFollowerNum,
|
|
888
|
+
liveFollowerChange,
|
|
1291
889
|
};
|
|
1292
890
|
}
|
|
1293
891
|
async useLiveRoomInfo(roomId) {
|
|
@@ -1313,7 +911,7 @@ class ComRegister {
|
|
|
1313
911
|
}
|
|
1314
912
|
return content.data;
|
|
1315
913
|
}
|
|
1316
|
-
async liveDetectWithAPI() {
|
|
914
|
+
/* async liveDetectWithAPI() {
|
|
1317
915
|
// 定义变量:第一次订阅
|
|
1318
916
|
let liveDetectSetup = true;
|
|
1319
917
|
// 定义变量:timer计时器
|
|
@@ -1321,11 +919,19 @@ class ComRegister {
|
|
|
1321
919
|
// 相当于锁的作用,防止上一个循环没处理完
|
|
1322
920
|
let flag = true;
|
|
1323
921
|
// 定义订阅对象Record 0未开播 1正在直播 2轮播中
|
|
1324
|
-
const liveRecord
|
|
922
|
+
const liveRecord: Record<
|
|
923
|
+
number,
|
|
924
|
+
{
|
|
925
|
+
liveStatus: number;
|
|
926
|
+
liveTime: string;
|
|
927
|
+
target: Target;
|
|
928
|
+
}
|
|
929
|
+
> = {};
|
|
930
|
+
|
|
1325
931
|
// 定义函数: 发送请求获取直播状态
|
|
1326
|
-
const useLiveStatus = async (roomId) => {
|
|
932
|
+
const useLiveStatus = async (roomId: string) => {
|
|
1327
933
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1328
|
-
let content;
|
|
934
|
+
let content: any;
|
|
1329
935
|
const attempts = 3;
|
|
1330
936
|
for (let i = 0; i < attempts; i++) {
|
|
1331
937
|
try {
|
|
@@ -1333,9 +939,10 @@ class ComRegister {
|
|
|
1333
939
|
content = await this.ctx.ba.getLiveRoomInfo(roomId);
|
|
1334
940
|
// 成功则跳出循环
|
|
1335
941
|
break;
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
|
|
942
|
+
} catch (e) {
|
|
943
|
+
this.logger.error(
|
|
944
|
+
`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`,
|
|
945
|
+
);
|
|
1339
946
|
if (i === attempts - 1) {
|
|
1340
947
|
// 已尝试三次
|
|
1341
948
|
// 发送私聊消息并重启服务
|
|
@@ -1346,10 +953,10 @@ class ComRegister {
|
|
|
1346
953
|
// 返回data
|
|
1347
954
|
return content.data;
|
|
1348
955
|
};
|
|
956
|
+
|
|
1349
957
|
return async () => {
|
|
1350
958
|
// 如果flag为false则说明前面的代码还未执行完,则直接返回
|
|
1351
|
-
if (!flag)
|
|
1352
|
-
return;
|
|
959
|
+
if (!flag) return;
|
|
1353
960
|
// 将标志位置为false
|
|
1354
961
|
flag = false;
|
|
1355
962
|
try {
|
|
@@ -1386,18 +993,30 @@ class ComRegister {
|
|
|
1386
993
|
// 设置直播中消息
|
|
1387
994
|
const liveMsg = this.config.customLive
|
|
1388
995
|
? this.config.customLive
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
996
|
+
.replace("-name", item.uname)
|
|
997
|
+
.replace(
|
|
998
|
+
"-time",
|
|
999
|
+
await this.ctx.gi.getTimeDifference(
|
|
1000
|
+
liveRecord[item.mid].liveTime,
|
|
1001
|
+
),
|
|
1002
|
+
)
|
|
1003
|
+
.replace(
|
|
1004
|
+
"-link",
|
|
1005
|
+
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1006
|
+
)
|
|
1392
1007
|
: null;
|
|
1393
1008
|
// 发送直播通知卡片
|
|
1394
1009
|
if (this.config.restartPush)
|
|
1395
|
-
this.sendLiveNotifyCard(
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1010
|
+
this.sendLiveNotifyCard(
|
|
1011
|
+
{
|
|
1012
|
+
username: item.uname,
|
|
1013
|
+
userface: item.face,
|
|
1014
|
+
target: liveRecord[item.mid].target,
|
|
1015
|
+
data,
|
|
1016
|
+
},
|
|
1017
|
+
LiveType.LiveBroadcast,
|
|
1018
|
+
liveMsg,
|
|
1019
|
+
);
|
|
1401
1020
|
}
|
|
1402
1021
|
}
|
|
1403
1022
|
}
|
|
@@ -1444,9 +1063,13 @@ class ComRegister {
|
|
|
1444
1063
|
}
|
|
1445
1064
|
if (currentLiveRecordKeys.length > currentLiveSubs.length) {
|
|
1446
1065
|
// 创建Set
|
|
1447
|
-
const setCurrentLiveSubs = new Set(
|
|
1066
|
+
const setCurrentLiveSubs = new Set(
|
|
1067
|
+
currentLiveSubs.map((sub) => sub.uid),
|
|
1068
|
+
);
|
|
1448
1069
|
// 找出 currentLiveRecordKeys中比currentLiveSubs 多的元素
|
|
1449
|
-
const extraInCurrentLiveSubs = currentLiveRecordKeys.filter(
|
|
1070
|
+
const extraInCurrentLiveSubs = currentLiveRecordKeys.filter(
|
|
1071
|
+
(key) => !setCurrentLiveSubs.has(key),
|
|
1072
|
+
);
|
|
1450
1073
|
// 遍历 extraInCurrentLiveSubs
|
|
1451
1074
|
for (const subUID of extraInCurrentLiveSubs) {
|
|
1452
1075
|
// 删除记录
|
|
@@ -1470,17 +1093,29 @@ class ComRegister {
|
|
|
1470
1093
|
// 定义开播通知语
|
|
1471
1094
|
const liveStartMsg = this.config.customLiveStart
|
|
1472
1095
|
? this.config.customLiveStart
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1096
|
+
.replace("-name", item.uname)
|
|
1097
|
+
.replace(
|
|
1098
|
+
"-time",
|
|
1099
|
+
await this.ctx.gi.getTimeDifference(
|
|
1100
|
+
liveRecord[item.mid].liveTime,
|
|
1101
|
+
),
|
|
1102
|
+
)
|
|
1103
|
+
.replace(
|
|
1104
|
+
"-link",
|
|
1105
|
+
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1106
|
+
)
|
|
1476
1107
|
: null;
|
|
1477
1108
|
// 发送直播通知卡片
|
|
1478
|
-
await this.sendLiveNotifyCard(
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1109
|
+
await this.sendLiveNotifyCard(
|
|
1110
|
+
{
|
|
1111
|
+
username: item.uname,
|
|
1112
|
+
userface: item.face,
|
|
1113
|
+
target: liveRecord[item.mid].target,
|
|
1114
|
+
data,
|
|
1115
|
+
},
|
|
1116
|
+
LiveType.LiveBroadcast,
|
|
1117
|
+
liveStartMsg,
|
|
1118
|
+
);
|
|
1484
1119
|
// 改变开播状态
|
|
1485
1120
|
liveRecord[item.mid].liveStatus = 1;
|
|
1486
1121
|
// 结束
|
|
@@ -1498,17 +1133,29 @@ class ComRegister {
|
|
|
1498
1133
|
// 定义直播中通知消息
|
|
1499
1134
|
const liveMsg = this.config.customLive
|
|
1500
1135
|
? this.config.customLive
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1136
|
+
.replace("-name", item.uname)
|
|
1137
|
+
.replace(
|
|
1138
|
+
"-time",
|
|
1139
|
+
await this.ctx.gi.getTimeDifference(
|
|
1140
|
+
liveRecord[item.mid].liveTime,
|
|
1141
|
+
),
|
|
1142
|
+
)
|
|
1143
|
+
.replace(
|
|
1144
|
+
"-link",
|
|
1145
|
+
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1146
|
+
)
|
|
1504
1147
|
: null;
|
|
1505
1148
|
// 发送直播通知卡片
|
|
1506
|
-
this.sendLiveNotifyCard(
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1149
|
+
this.sendLiveNotifyCard(
|
|
1150
|
+
{
|
|
1151
|
+
username: item.uname,
|
|
1152
|
+
userface: item.face,
|
|
1153
|
+
target: liveRecord[item.mid].target,
|
|
1154
|
+
data,
|
|
1155
|
+
},
|
|
1156
|
+
LiveType.LiveBroadcast,
|
|
1157
|
+
liveMsg,
|
|
1158
|
+
);
|
|
1512
1159
|
}
|
|
1513
1160
|
}
|
|
1514
1161
|
}
|
|
@@ -1516,38 +1163,71 @@ class ComRegister {
|
|
|
1516
1163
|
}
|
|
1517
1164
|
}
|
|
1518
1165
|
// 找出liveRecord中liveStatus为1但liveUsers中没有的元素
|
|
1519
|
-
const extraInLiveRecord = currentLiveRecordKeys.filter(
|
|
1166
|
+
const extraInLiveRecord = currentLiveRecordKeys.filter(
|
|
1167
|
+
(key) => !liveUsers.items.some((item) => item.mid === Number(key)),
|
|
1168
|
+
);
|
|
1520
1169
|
// 遍历 extraInLiveRecord
|
|
1521
1170
|
for (const subUID of extraInLiveRecord) {
|
|
1522
1171
|
// 下播的主播
|
|
1523
1172
|
// 获取主播信息
|
|
1524
1173
|
const masterInfo = await this.useMasterInfo(subUID);
|
|
1525
1174
|
// 获取直播间消息
|
|
1526
|
-
const liveRoomInfo = await this.useLiveRoomInfo(
|
|
1175
|
+
const liveRoomInfo = await this.useLiveRoomInfo(
|
|
1176
|
+
masterInfo.roomId.toString(),
|
|
1177
|
+
);
|
|
1527
1178
|
// 设置开播时间
|
|
1528
1179
|
liveRoomInfo.live_time = liveRecord[subUID].liveTime;
|
|
1529
1180
|
// 定义下播播通知语
|
|
1530
1181
|
const liveEndMsg = this.config.customLiveEnd
|
|
1531
1182
|
? this.config.customLiveEnd
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1183
|
+
.replace("-name", masterInfo.username)
|
|
1184
|
+
.replace(
|
|
1185
|
+
"-time",
|
|
1186
|
+
await this.ctx.gi.getTimeDifference(
|
|
1187
|
+
liveRecord[subUID].liveTime,
|
|
1188
|
+
),
|
|
1189
|
+
)
|
|
1190
|
+
.replace(
|
|
1191
|
+
"-link",
|
|
1192
|
+
`https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`,
|
|
1193
|
+
)
|
|
1535
1194
|
: null;
|
|
1536
1195
|
// 发送下播通知
|
|
1537
|
-
this.sendLiveNotifyCard(
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1196
|
+
this.sendLiveNotifyCard(
|
|
1197
|
+
{
|
|
1198
|
+
username: masterInfo.username,
|
|
1199
|
+
userface: masterInfo.userface,
|
|
1200
|
+
target: liveRecord[subUID].target,
|
|
1201
|
+
data: liveRoomInfo,
|
|
1202
|
+
},
|
|
1203
|
+
LiveType.StopBroadcast,
|
|
1204
|
+
liveEndMsg,
|
|
1205
|
+
);
|
|
1543
1206
|
}
|
|
1544
|
-
}
|
|
1545
|
-
finally {
|
|
1207
|
+
} finally {
|
|
1546
1208
|
// 执行完方法体不论如何都把flag设置为true
|
|
1547
1209
|
flag = true;
|
|
1548
1210
|
}
|
|
1549
1211
|
};
|
|
1550
|
-
}
|
|
1212
|
+
} */
|
|
1213
|
+
// TODO:WordCloud
|
|
1214
|
+
/* // 定义获取弹幕权重Record函数
|
|
1215
|
+
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
1216
|
+
// 创建segmentit
|
|
1217
|
+
const segmentit = useDefault(new Segment());
|
|
1218
|
+
// 创建Record
|
|
1219
|
+
const danmakuWeightRecord: Record<string, number> = {};
|
|
1220
|
+
// 循环遍历currentLiveDanmakuArr
|
|
1221
|
+
for (const danmaku of currentLiveDanmakuArr) {
|
|
1222
|
+
// 遍历结果
|
|
1223
|
+
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
1224
|
+
// 定义权重
|
|
1225
|
+
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
// 返回Record
|
|
1229
|
+
return danmakuWeightRecord;
|
|
1230
|
+
}; */
|
|
1551
1231
|
async liveDetectWithListener(roomId, target) {
|
|
1552
1232
|
// 定义开播时间
|
|
1553
1233
|
let liveTime;
|
|
@@ -1564,6 +1244,7 @@ class ComRegister {
|
|
|
1564
1244
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1565
1245
|
let liveRoomInfo;
|
|
1566
1246
|
let masterInfo;
|
|
1247
|
+
let watchedNum;
|
|
1567
1248
|
// 找到频道/群组对应的
|
|
1568
1249
|
const liveGuardBuyPushTargetArr = target.map((channel) => {
|
|
1569
1250
|
// 获取符合条件的target
|
|
@@ -1579,17 +1260,20 @@ class ComRegister {
|
|
|
1579
1260
|
// 定义定时推送函数
|
|
1580
1261
|
const pushAtTimeFunc = async () => {
|
|
1581
1262
|
// 判断是否信息是否获取成功
|
|
1582
|
-
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1263
|
+
if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.LiveBroadcast))) {
|
|
1583
1264
|
// 未获取成功,直接返回
|
|
1584
1265
|
return this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1585
1266
|
}
|
|
1586
1267
|
// 设置开播时间
|
|
1587
1268
|
liveTime = liveRoomInfo.live_time;
|
|
1269
|
+
// 获取watched
|
|
1270
|
+
const watched = watchedNum?.toString() || '暂未获取到';
|
|
1588
1271
|
// 设置直播中消息
|
|
1589
1272
|
const liveMsg = this.config.customLive
|
|
1590
1273
|
? this.config.customLive
|
|
1591
1274
|
.replace("-name", masterInfo.username)
|
|
1592
1275
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1276
|
+
.replace("-watched", watched)
|
|
1593
1277
|
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1594
1278
|
: null;
|
|
1595
1279
|
// 发送直播通知卡片
|
|
@@ -1598,28 +1282,10 @@ class ComRegister {
|
|
|
1598
1282
|
userface: masterInfo.userface,
|
|
1599
1283
|
target,
|
|
1600
1284
|
data: liveRoomInfo,
|
|
1601
|
-
}, LiveType.LiveBroadcast, liveMsg);
|
|
1285
|
+
}, type_1.LiveType.LiveBroadcast, watched, liveMsg);
|
|
1602
1286
|
};
|
|
1603
|
-
// TODO:WordCloud
|
|
1604
|
-
/* // 定义获取弹幕权重Record函数
|
|
1605
|
-
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
1606
|
-
// 创建segmentit
|
|
1607
|
-
const segmentit = useDefault(new Segment());
|
|
1608
|
-
// 创建Record
|
|
1609
|
-
const danmakuWeightRecord: Record<string, number> = {};
|
|
1610
|
-
// 循环遍历currentLiveDanmakuArr
|
|
1611
|
-
for (const danmaku of currentLiveDanmakuArr) {
|
|
1612
|
-
// 遍历结果
|
|
1613
|
-
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
1614
|
-
// 定义权重
|
|
1615
|
-
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
1616
|
-
});
|
|
1617
|
-
}
|
|
1618
|
-
// 返回Record
|
|
1619
|
-
return danmakuWeightRecord;
|
|
1620
|
-
}; */
|
|
1621
1287
|
// 定义直播间信息获取函数
|
|
1622
|
-
const useMasterAndLiveRoomInfo = async () => {
|
|
1288
|
+
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1623
1289
|
// 定义函数是否执行成功flag
|
|
1624
1290
|
let flag = true;
|
|
1625
1291
|
// 获取直播间信息
|
|
@@ -1637,7 +1303,7 @@ class ComRegister {
|
|
|
1637
1303
|
return flag;
|
|
1638
1304
|
}
|
|
1639
1305
|
// 获取主播信息(需要满足flag为true,liveRoomInfo.uid有值)
|
|
1640
|
-
masterInfo = await this.useMasterInfo(liveRoomInfo.uid).catch(() => {
|
|
1306
|
+
masterInfo = await this.useMasterInfo(liveRoomInfo.uid, masterInfo, liveType).catch(() => {
|
|
1641
1307
|
// 设置flag为false
|
|
1642
1308
|
flag = false;
|
|
1643
1309
|
// 返回空
|
|
@@ -1646,19 +1312,8 @@ class ComRegister {
|
|
|
1646
1312
|
// 返回信息
|
|
1647
1313
|
return flag;
|
|
1648
1314
|
};
|
|
1649
|
-
// 判断是否信息是否获取成功
|
|
1650
|
-
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1651
|
-
// 未获取成功,直接返回
|
|
1652
|
-
return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1653
|
-
}
|
|
1654
1315
|
// 构建消息处理函数
|
|
1655
1316
|
const handler = {
|
|
1656
|
-
onOpen: () => {
|
|
1657
|
-
this.logger.info("直播间连接成功");
|
|
1658
|
-
},
|
|
1659
|
-
onClose: () => {
|
|
1660
|
-
this.logger.info("直播间连接已断开");
|
|
1661
|
-
},
|
|
1662
1317
|
onIncomeDanmu: ({ body }) => {
|
|
1663
1318
|
// 保存消息到数组
|
|
1664
1319
|
currentLiveDanmakuArr.push(body.content);
|
|
@@ -1667,6 +1322,10 @@ class ComRegister {
|
|
|
1667
1322
|
// 保存消息到数组
|
|
1668
1323
|
currentLiveDanmakuArr.push(body.content);
|
|
1669
1324
|
},
|
|
1325
|
+
onWatchedChange: ({ body }) => {
|
|
1326
|
+
// 保存观看人数到变量
|
|
1327
|
+
watchedNum = body.num;
|
|
1328
|
+
},
|
|
1670
1329
|
onGuardBuy: ({ body }) => {
|
|
1671
1330
|
// 定义消息
|
|
1672
1331
|
const content = `${body.user.uname}加入了大航海(${body.gift_name})`;
|
|
@@ -1680,7 +1339,7 @@ class ComRegister {
|
|
|
1680
1339
|
// 设置开播状态为true
|
|
1681
1340
|
liveStatus = true;
|
|
1682
1341
|
// 判断是否信息是否获取成功
|
|
1683
|
-
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1342
|
+
if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StartBroadcasting))) {
|
|
1684
1343
|
// 设置开播状态为false
|
|
1685
1344
|
liveStatus = false;
|
|
1686
1345
|
// 未获取成功,直接返回
|
|
@@ -1688,11 +1347,14 @@ class ComRegister {
|
|
|
1688
1347
|
}
|
|
1689
1348
|
// 设置开播时间
|
|
1690
1349
|
liveTime = liveRoomInfo.live_time;
|
|
1350
|
+
// 获取当前粉丝数
|
|
1351
|
+
const follower = masterInfo.liveOpenFollowerNum.toString();
|
|
1691
1352
|
// 定义开播通知语
|
|
1692
1353
|
const liveStartMsg = this.config.customLiveStart
|
|
1693
1354
|
? this.config.customLiveStart
|
|
1694
1355
|
.replace("-name", masterInfo.username)
|
|
1695
1356
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1357
|
+
.replace("-follower", follower)
|
|
1696
1358
|
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1697
1359
|
: null;
|
|
1698
1360
|
// 推送开播通知
|
|
@@ -1701,7 +1363,7 @@ class ComRegister {
|
|
|
1701
1363
|
userface: masterInfo.userface,
|
|
1702
1364
|
target,
|
|
1703
1365
|
data: liveRoomInfo,
|
|
1704
|
-
}, LiveType.StartBroadcasting, liveStartMsg);
|
|
1366
|
+
}, type_1.LiveType.StartBroadcasting, follower, liveStartMsg);
|
|
1705
1367
|
// 判断定时器是否已开启
|
|
1706
1368
|
if (!pushAtTimeTimer) {
|
|
1707
1369
|
// 开始直播,开启定时器
|
|
@@ -1712,17 +1374,20 @@ class ComRegister {
|
|
|
1712
1374
|
// 将直播状态设置为false
|
|
1713
1375
|
liveStatus = false;
|
|
1714
1376
|
// 判断是否信息是否获取成功
|
|
1715
|
-
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1377
|
+
if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast))) {
|
|
1716
1378
|
// 未获取成功,直接返回
|
|
1717
1379
|
return this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1718
1380
|
}
|
|
1719
1381
|
// 更改直播时长
|
|
1720
1382
|
liveRoomInfo.live_time = liveTime;
|
|
1383
|
+
// 获取粉丝数变化
|
|
1384
|
+
const followerChange = masterInfo.liveFollowerChange.toString();
|
|
1721
1385
|
// 定义下播播通知语
|
|
1722
1386
|
const liveEndMsg = this.config.customLiveEnd
|
|
1723
1387
|
? this.config.customLiveEnd
|
|
1724
1388
|
.replace("-name", masterInfo.username)
|
|
1725
1389
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1390
|
+
.replace("-follower_change", followerChange)
|
|
1726
1391
|
: null;
|
|
1727
1392
|
// 推送通知卡片
|
|
1728
1393
|
await this.sendLiveNotifyCard({
|
|
@@ -1730,7 +1395,7 @@ class ComRegister {
|
|
|
1730
1395
|
userface: masterInfo.userface,
|
|
1731
1396
|
target,
|
|
1732
1397
|
data: liveRoomInfo,
|
|
1733
|
-
}, LiveType.StopBroadcast, liveEndMsg);
|
|
1398
|
+
}, type_1.LiveType.StopBroadcast, followerChange, liveEndMsg);
|
|
1734
1399
|
// 关闭定时推送定时器
|
|
1735
1400
|
pushAtTimeTimer();
|
|
1736
1401
|
// 将推送定时器变量置空
|
|
@@ -1739,15 +1404,23 @@ class ComRegister {
|
|
|
1739
1404
|
};
|
|
1740
1405
|
// 启动直播间弹幕监测
|
|
1741
1406
|
await this.ctx.bl.startLiveRoomListener(roomId, handler);
|
|
1407
|
+
// 第一次启动获取信息并判信息是否获取成功
|
|
1408
|
+
if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.FirstLiveBroadcast))) {
|
|
1409
|
+
// 未获取成功,直接返回
|
|
1410
|
+
return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1411
|
+
}
|
|
1742
1412
|
// 判断直播状态
|
|
1743
1413
|
if (liveRoomInfo.live_status === 1) {
|
|
1744
1414
|
// 设置开播时间
|
|
1745
1415
|
liveTime = liveRoomInfo.live_time;
|
|
1416
|
+
// 获取当前累计观看人数
|
|
1417
|
+
const watched = watchedNum?.toString() || '暂未获取到';
|
|
1746
1418
|
// 定义直播中通知消息
|
|
1747
1419
|
const liveMsg = this.config.customLive
|
|
1748
1420
|
? this.config.customLive
|
|
1749
1421
|
.replace("-name", masterInfo.username)
|
|
1750
1422
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1423
|
+
.replace("-watched", watched)
|
|
1751
1424
|
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1752
1425
|
: null;
|
|
1753
1426
|
// 发送直播通知卡片
|
|
@@ -1757,7 +1430,7 @@ class ComRegister {
|
|
|
1757
1430
|
userface: masterInfo.userface,
|
|
1758
1431
|
target,
|
|
1759
1432
|
data: liveRoomInfo,
|
|
1760
|
-
}, LiveType.LiveBroadcast, liveMsg);
|
|
1433
|
+
}, type_1.LiveType.LiveBroadcast, watched, liveMsg);
|
|
1761
1434
|
}
|
|
1762
1435
|
// 正在直播,开启定时器
|
|
1763
1436
|
// 判断定时器是否已开启
|
|
@@ -1777,38 +1450,6 @@ class ComRegister {
|
|
|
1777
1450
|
}
|
|
1778
1451
|
return table ? table : "没有订阅任何UP";
|
|
1779
1452
|
}
|
|
1780
|
-
async checkIfNeedSub(liveSub, dynamicSub, session,
|
|
1781
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1782
|
-
liveRoomData) {
|
|
1783
|
-
// 定义方法:用户直播间是否存在
|
|
1784
|
-
const liveRoom = async () => {
|
|
1785
|
-
if (!liveRoomData) {
|
|
1786
|
-
// 未开通直播间
|
|
1787
|
-
await session.send("该用户未开通直播间,无法订阅直播");
|
|
1788
|
-
// 返回false
|
|
1789
|
-
return true;
|
|
1790
|
-
}
|
|
1791
|
-
return false;
|
|
1792
|
-
};
|
|
1793
|
-
// 如果两者都为true或者都为false则直接返回
|
|
1794
|
-
if ((liveSub && dynamicSub) || (!liveSub && !dynamicSub)) {
|
|
1795
|
-
// 判断是否存在直播间
|
|
1796
|
-
if (await liveRoom())
|
|
1797
|
-
return [false, true];
|
|
1798
|
-
// 返回
|
|
1799
|
-
return [true, true];
|
|
1800
|
-
}
|
|
1801
|
-
// 如果只订阅直播
|
|
1802
|
-
if (liveSub) {
|
|
1803
|
-
// 判断是否存在直播间
|
|
1804
|
-
if (await liveRoom())
|
|
1805
|
-
return [false, false];
|
|
1806
|
-
// 返回
|
|
1807
|
-
return [true, false];
|
|
1808
|
-
}
|
|
1809
|
-
// 只订阅动态
|
|
1810
|
-
return [false, true];
|
|
1811
|
-
}
|
|
1812
1453
|
updateSubNotifier() {
|
|
1813
1454
|
// 更新控制台提示
|
|
1814
1455
|
if (this.subNotifier)
|
|
@@ -1990,14 +1631,15 @@ class ComRegister {
|
|
|
1990
1631
|
// 发送提示
|
|
1991
1632
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1992
1633
|
}
|
|
1993
|
-
//
|
|
1634
|
+
// 直播类型模式匹配
|
|
1994
1635
|
const liveDetectModeSelector = {
|
|
1995
1636
|
API: async () => {
|
|
1996
1637
|
// 判断是否已开启直播检测
|
|
1997
1638
|
if (!this.liveDispose) {
|
|
1998
1639
|
// 未开启直播检测
|
|
1999
1640
|
// 开启直播检测并保存销毁函数
|
|
2000
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
1641
|
+
// this.liveDispose = await this.liveDetectWithAPI();
|
|
1642
|
+
this.logger.warn("API模式暂时不可用");
|
|
2001
1643
|
}
|
|
2002
1644
|
},
|
|
2003
1645
|
WS: async () => {
|
|
@@ -2028,147 +1670,6 @@ class ComRegister {
|
|
|
2028
1670
|
});
|
|
2029
1671
|
}
|
|
2030
1672
|
}
|
|
2031
|
-
async loadSubFromDatabase() {
|
|
2032
|
-
// 从数据库中获取数据
|
|
2033
|
-
const subData = await this.ctx.database.get("bilibili", { id: { $gt: 0 } });
|
|
2034
|
-
// 定义变量:订阅直播数
|
|
2035
|
-
let liveSubNum = 0;
|
|
2036
|
-
// 循环遍历
|
|
2037
|
-
for (const sub of subData) {
|
|
2038
|
-
// 判断是否存在没有任何订阅的数据
|
|
2039
|
-
if (!sub.dynamic && !sub.live) {
|
|
2040
|
-
// 存在未订阅任何项目的数据
|
|
2041
|
-
// 删除该条数据
|
|
2042
|
-
this.ctx.database.remove("bilibili", { id: sub.id });
|
|
2043
|
-
// log
|
|
2044
|
-
this.logger.warn(`UID:${sub.uid} 该条数据没有任何订阅数据,自动取消订阅`);
|
|
2045
|
-
// 跳过下面的步骤
|
|
2046
|
-
continue;
|
|
2047
|
-
}
|
|
2048
|
-
// 判断用户是否在B站中订阅了
|
|
2049
|
-
const subUserData = await this.subUserInBili(sub.uid);
|
|
2050
|
-
// 判断是否订阅
|
|
2051
|
-
if (!subUserData.flag) {
|
|
2052
|
-
// log
|
|
2053
|
-
this.logger.warn(`UID:${sub.uid} ${subUserData.msg},自动取消订阅`);
|
|
2054
|
-
// 发送私聊消息
|
|
2055
|
-
await this.sendPrivateMsg(`UID:${sub.uid} ${subUserData.msg},自动取消订阅`);
|
|
2056
|
-
// 删除该条数据
|
|
2057
|
-
await this.ctx.database.remove("bilibili", { id: sub.id });
|
|
2058
|
-
// 跳过下面的步骤
|
|
2059
|
-
continue;
|
|
2060
|
-
}
|
|
2061
|
-
// 获取推送目标数组
|
|
2062
|
-
const target = JSON.parse(sub.target);
|
|
2063
|
-
/* 判断数据库是否被篡改 */
|
|
2064
|
-
// 获取用户信息
|
|
2065
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
2066
|
-
let content;
|
|
2067
|
-
const attempts = 3;
|
|
2068
|
-
for (let i = 0; i < attempts; i++) {
|
|
2069
|
-
try {
|
|
2070
|
-
// 获取用户信息
|
|
2071
|
-
content = await this.ctx.ba.getUserInfo(sub.uid);
|
|
2072
|
-
// 成功则跳出循环
|
|
2073
|
-
break;
|
|
2074
|
-
}
|
|
2075
|
-
catch (e) {
|
|
2076
|
-
this.logger.error(`getSubFromDatabase() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
2077
|
-
if (i === attempts - 1) {
|
|
2078
|
-
// 已尝试三次
|
|
2079
|
-
// 发送私聊消息并重启服务
|
|
2080
|
-
return await this.sendPrivateMsgAndStopService();
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
// 获取data
|
|
2085
|
-
const { data } = content;
|
|
2086
|
-
// 定义函数删除数据和发送提示
|
|
2087
|
-
const deleteSub = async () => {
|
|
2088
|
-
// 从数据库删除该条数据
|
|
2089
|
-
await this.ctx.database.remove("bilibili", { id: sub.id });
|
|
2090
|
-
// 给用户发送提示
|
|
2091
|
-
await this.sendPrivateMsg(`UID:${sub.uid} 数据库内容被篡改,已取消对该UP主的订阅`);
|
|
2092
|
-
};
|
|
2093
|
-
// 判断是否有其他问题
|
|
2094
|
-
if (content.code !== 0) {
|
|
2095
|
-
switch (content.code) {
|
|
2096
|
-
case -352:
|
|
2097
|
-
case -403: {
|
|
2098
|
-
await this.sendPrivateMsg("你的登录信息已过期,请重新登录Bilibili");
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
default: {
|
|
2102
|
-
await deleteSub();
|
|
2103
|
-
// PrivateMsg
|
|
2104
|
-
await this.sendPrivateMsg(`UID:${sub.uid} 数据出现问题,自动取消订阅`);
|
|
2105
|
-
// log
|
|
2106
|
-
this.logger.info(`UID:${sub.uid} 数据出现问题,自动取消订阅`);
|
|
2107
|
-
return;
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
// 检测房间号是否被篡改
|
|
2112
|
-
if (sub.live &&
|
|
2113
|
-
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
|
|
2114
|
-
(!data.live_room || data.live_room.roomid != sub.room_id)) {
|
|
2115
|
-
// 房间号被篡改,删除该订阅
|
|
2116
|
-
await deleteSub();
|
|
2117
|
-
// log
|
|
2118
|
-
this.logger.info(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
2119
|
-
// Send msg
|
|
2120
|
-
await this.sendPrivateMsg(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
2121
|
-
// 直接返回
|
|
2122
|
-
return;
|
|
2123
|
-
}
|
|
2124
|
-
// 构建订阅对象
|
|
2125
|
-
const subManagerItem = {
|
|
2126
|
-
id: sub.id,
|
|
2127
|
-
uid: sub.uid,
|
|
2128
|
-
roomId: sub.room_id,
|
|
2129
|
-
target,
|
|
2130
|
-
platform: sub.platform,
|
|
2131
|
-
live: sub.live === 1,
|
|
2132
|
-
dynamic: sub.dynamic === 1,
|
|
2133
|
-
liveDispose: null,
|
|
2134
|
-
};
|
|
2135
|
-
// 定义直播模式监测器
|
|
2136
|
-
const liveDetectModeSelector = {
|
|
2137
|
-
API: async () => {
|
|
2138
|
-
// 判断是否已开启直播检测
|
|
2139
|
-
if (!this.liveDispose) {
|
|
2140
|
-
// 未开启直播检测
|
|
2141
|
-
// 开启直播检测并保存销毁函数
|
|
2142
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
2143
|
-
}
|
|
2144
|
-
},
|
|
2145
|
-
WS: async () => {
|
|
2146
|
-
// 判断订阅直播数是否超过限制
|
|
2147
|
-
if (!this.config.unlockSubLimits && liveSubNum >= 3) {
|
|
2148
|
-
// 将live改为false
|
|
2149
|
-
subManagerItem.live = false;
|
|
2150
|
-
// log
|
|
2151
|
-
this.logger.warn(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
2152
|
-
// 发送错误消息
|
|
2153
|
-
await this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
2154
|
-
}
|
|
2155
|
-
else {
|
|
2156
|
-
// 直播订阅数+1
|
|
2157
|
-
liveSubNum++;
|
|
2158
|
-
// 订阅直播,开始循环检测
|
|
2159
|
-
await this.liveDetectWithListener(sub.room_id, target);
|
|
2160
|
-
}
|
|
2161
|
-
},
|
|
2162
|
-
};
|
|
2163
|
-
// 判断是否订阅直播
|
|
2164
|
-
if (sub.live) {
|
|
2165
|
-
// 启动直播监测
|
|
2166
|
-
await liveDetectModeSelector[this.config.liveDetectMode]();
|
|
2167
|
-
}
|
|
2168
|
-
// 保存新订阅对象
|
|
2169
|
-
this.subManager.push(subManagerItem);
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
1673
|
checkIfDynamicDetectIsNeeded() {
|
|
2173
1674
|
// 检查是否有订阅对象需要动态监测
|
|
2174
1675
|
if (this.subManager.some((sub) => sub.dynamic))
|
|
@@ -2183,136 +1684,6 @@ class ComRegister {
|
|
|
2183
1684
|
this.dynamicDispose = this.ctx.setInterval(this.dynamicDetect(), this.config.dynamicLoopTime * 1000);
|
|
2184
1685
|
}
|
|
2185
1686
|
}
|
|
2186
|
-
unsubSingle(id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
|
|
2187
|
-
// 定义返回消息
|
|
2188
|
-
let msg;
|
|
2189
|
-
// 定义方法:检查是否没有任何订阅
|
|
2190
|
-
const checkIfNoSubExist = (sub) => !sub.dynamic && !sub.live;
|
|
2191
|
-
// 定义方法:将订阅对象从订阅管理对象中移除
|
|
2192
|
-
const removeSub = (index) => {
|
|
2193
|
-
// 从管理对象中移除
|
|
2194
|
-
this.subManager.splice(index, 1);
|
|
2195
|
-
// 从数据库中删除
|
|
2196
|
-
this.ctx.database.remove("bilibili", [this.subManager[index].id]);
|
|
2197
|
-
// num--
|
|
2198
|
-
this.num--;
|
|
2199
|
-
// 判断是否还存在订阅了动态的对象,不存在则停止动态监测
|
|
2200
|
-
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
2201
|
-
};
|
|
2202
|
-
try {
|
|
2203
|
-
switch (type) {
|
|
2204
|
-
case 0: {
|
|
2205
|
-
// 取消Live订阅
|
|
2206
|
-
// 获取订阅对象所在的索引
|
|
2207
|
-
const index = this.subManager.findIndex((sub) => sub.roomId === id);
|
|
2208
|
-
// 获取订阅对象
|
|
2209
|
-
const sub = this.subManager.find((sub) => sub.roomId === id);
|
|
2210
|
-
// 判断是否存在订阅对象
|
|
2211
|
-
if (!sub) {
|
|
2212
|
-
msg = "未订阅该用户,无需取消订阅";
|
|
2213
|
-
return msg;
|
|
2214
|
-
}
|
|
2215
|
-
// 取消订阅
|
|
2216
|
-
sub.live = false;
|
|
2217
|
-
// 判断直播检测方式
|
|
2218
|
-
switch (this.config.liveDetectMode) {
|
|
2219
|
-
case "API": {
|
|
2220
|
-
msg = "请手动删除订阅,并重启插件";
|
|
2221
|
-
break;
|
|
2222
|
-
}
|
|
2223
|
-
case "WS": {
|
|
2224
|
-
// 取消直播监听
|
|
2225
|
-
this.ctx.bl.closeListener(sub.roomId);
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
// 如果没有对这个UP的任何订阅,则移除
|
|
2229
|
-
if (checkIfNoSubExist(sub)) {
|
|
2230
|
-
// 从管理对象中移除
|
|
2231
|
-
removeSub(index);
|
|
2232
|
-
return "已取消订阅该用户";
|
|
2233
|
-
}
|
|
2234
|
-
// 更新数据库
|
|
2235
|
-
this.ctx.database.upsert("bilibili", [
|
|
2236
|
-
{
|
|
2237
|
-
id: +`${sub.id}`,
|
|
2238
|
-
live: 0,
|
|
2239
|
-
},
|
|
2240
|
-
]);
|
|
2241
|
-
return "已取消订阅Live";
|
|
2242
|
-
}
|
|
2243
|
-
case 1: {
|
|
2244
|
-
// 取消Dynamic订阅
|
|
2245
|
-
// 获取订阅对象所在的索引
|
|
2246
|
-
const index = this.subManager.findIndex((sub) => sub.uid === id);
|
|
2247
|
-
// 获取订阅对象
|
|
2248
|
-
const sub = this.subManager.find((sub) => sub.uid === id);
|
|
2249
|
-
// 判断是否存在订阅对象
|
|
2250
|
-
if (!sub) {
|
|
2251
|
-
msg = "未订阅该用户,无需取消订阅";
|
|
2252
|
-
return msg;
|
|
2253
|
-
}
|
|
2254
|
-
// 取消订阅
|
|
2255
|
-
this.subManager[index].dynamic = false;
|
|
2256
|
-
// 判断是否还存在订阅了动态的对象,不存在则停止动态监测
|
|
2257
|
-
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
2258
|
-
// 如果没有对这个UP的任何订阅,则移除
|
|
2259
|
-
if (checkIfNoSubExist(sub)) {
|
|
2260
|
-
// 从管理对象中移除
|
|
2261
|
-
removeSub(index);
|
|
2262
|
-
return "已取消订阅该用户";
|
|
2263
|
-
}
|
|
2264
|
-
// 更新数据库
|
|
2265
|
-
this.ctx.database.upsert("bilibili", [
|
|
2266
|
-
{
|
|
2267
|
-
id: sub.id,
|
|
2268
|
-
dynamic: 0,
|
|
2269
|
-
},
|
|
2270
|
-
]);
|
|
2271
|
-
return "已取消订阅Dynamic";
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
finally {
|
|
2276
|
-
// 执行完该方法后,保证执行一次updateSubNotifier()
|
|
2277
|
-
this.updateSubNotifier();
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
checkIfUserIsTheLastOneWhoSubDyn() {
|
|
2281
|
-
if (this.dynamicDispose && !this.subManager.some((sub) => sub.dynamic)) {
|
|
2282
|
-
// 停止动态监测
|
|
2283
|
-
this.dynamicDispose();
|
|
2284
|
-
this.dynamicDispose = null;
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
unsubAll(uid) {
|
|
2288
|
-
this.subManager
|
|
2289
|
-
.filter((sub) => sub.uid === uid)
|
|
2290
|
-
.map(async (sub, i) => {
|
|
2291
|
-
// 判断是否还存在订阅了动态的对象,不存在则停止动态监测
|
|
2292
|
-
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
2293
|
-
switch (this.config.liveDetectMode) {
|
|
2294
|
-
case "API": {
|
|
2295
|
-
break;
|
|
2296
|
-
}
|
|
2297
|
-
case "WS": {
|
|
2298
|
-
// 停止直播检测
|
|
2299
|
-
this.ctx.bl.closeListener(sub.roomId);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
// 从数据库中删除订阅
|
|
2303
|
-
await this.ctx.database.remove("bilibili", {
|
|
2304
|
-
uid: this.subManager[i].uid,
|
|
2305
|
-
});
|
|
2306
|
-
// 将该订阅对象从订阅管理对象中移除
|
|
2307
|
-
this.subManager.splice(i, 1);
|
|
2308
|
-
// id--
|
|
2309
|
-
this.num--;
|
|
2310
|
-
// 发送成功通知
|
|
2311
|
-
this.sendPrivateMsg(`UID:${uid},已取消订阅该用户`);
|
|
2312
|
-
// 更新控制台提示
|
|
2313
|
-
this.updateSubNotifier();
|
|
2314
|
-
});
|
|
2315
|
-
}
|
|
2316
1687
|
async checkIfIsLogin() {
|
|
2317
1688
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
2318
1689
|
// 数据库中有数据
|
|
@@ -2350,7 +1721,6 @@ class ComRegister {
|
|
|
2350
1721
|
masterAccount: koishi_1.Schema.string(),
|
|
2351
1722
|
masterAccountGuildId: koishi_1.Schema.string(),
|
|
2352
1723
|
}),
|
|
2353
|
-
unlockSubLimits: koishi_1.Schema.boolean().required(),
|
|
2354
1724
|
automaticResend: koishi_1.Schema.boolean().required(),
|
|
2355
1725
|
liveDetectMode: koishi_1.Schema.union([
|
|
2356
1726
|
koishi_1.Schema.const("API"),
|