koishi-plugin-bilibili-notify 2.0.0-alpha.14 → 2.0.0-alpha.16
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/blive.d.ts +9 -0
- package/lib/blive.js +21 -0
- package/lib/comRegister.d.ts +21 -1
- package/lib/comRegister.js +181 -86
- package/lib/index.d.ts +15 -0
- package/lib/index.js +16 -0
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/blive.d.ts
ADDED
package/lib/blive.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class BLive {
|
|
4
|
+
// 必须服务
|
|
5
|
+
static inject = [''];
|
|
6
|
+
// 定义类属性
|
|
7
|
+
ctx;
|
|
8
|
+
logger;
|
|
9
|
+
// 构造函数
|
|
10
|
+
constructor(ctx) {
|
|
11
|
+
// 将Context赋值给类属性
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
// 将logger赋值给类属性
|
|
14
|
+
this.logger = ctx.logger('bl');
|
|
15
|
+
}
|
|
16
|
+
// 定义方法
|
|
17
|
+
connectToLiveBroadcastRoom(roomId) {
|
|
18
|
+
console.log(roomId);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = BLive;
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -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 = {
|
|
@@ -36,6 +38,7 @@ declare class ComRegister {
|
|
|
36
38
|
dynamicDispose: Function;
|
|
37
39
|
sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
|
|
38
40
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
41
|
+
init(ctx: Context, config: ComRegister.Config): Promise<void>;
|
|
39
42
|
splitMultiPlatformStr(str: string): Target;
|
|
40
43
|
getBot(ctx: Context, pf: string): Bot<Context, any>;
|
|
41
44
|
sendPrivateMsg(content: string): Promise<void>;
|
|
@@ -53,7 +56,10 @@ declare class ComRegister {
|
|
|
53
56
|
flag: boolean;
|
|
54
57
|
msg: string;
|
|
55
58
|
}>;
|
|
56
|
-
|
|
59
|
+
loadSubFromConfig(ctx: Context, subs: ComRegister.Config["sub"]): Promise<void>;
|
|
60
|
+
loadSubFromDatabase(ctx: Context): Promise<void>;
|
|
61
|
+
checkIfDynamicDetectIsNeeded(ctx: Context): void;
|
|
62
|
+
enableDynamicDetect(ctx: Context): void;
|
|
57
63
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
58
64
|
checkIfUserIsTheLastOneWhoSubDyn(): void;
|
|
59
65
|
unsubAll(ctx: Context, uid: string): void;
|
|
@@ -61,6 +67,20 @@ declare class ComRegister {
|
|
|
61
67
|
}
|
|
62
68
|
declare namespace ComRegister {
|
|
63
69
|
interface Config {
|
|
70
|
+
sub: Array<{
|
|
71
|
+
uid: string;
|
|
72
|
+
dynamic: boolean;
|
|
73
|
+
live: boolean;
|
|
74
|
+
target: Array<{
|
|
75
|
+
channelIdArr: Array<{
|
|
76
|
+
channelId: string;
|
|
77
|
+
dynamic: boolean;
|
|
78
|
+
live: boolean;
|
|
79
|
+
atAll: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
platform: string;
|
|
82
|
+
}>;
|
|
83
|
+
}>;
|
|
64
84
|
master: {
|
|
65
85
|
enable: boolean;
|
|
66
86
|
platform: string;
|
package/lib/comRegister.js
CHANGED
|
@@ -37,56 +37,9 @@ class ComRegister {
|
|
|
37
37
|
sendMsgFunc;
|
|
38
38
|
// 构造函数
|
|
39
39
|
constructor(ctx, config) {
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
//
|
|
43
|
-
this.privateBot = ctx.bots.find(bot => bot.platform === config.master.platform);
|
|
44
|
-
if (!this.privateBot) {
|
|
45
|
-
ctx.notifier.create({
|
|
46
|
-
content: '您未配置私人机器人,将无法向您推送机器人状态!'
|
|
47
|
-
});
|
|
48
|
-
this.logger.error('您未配置私人机器人,将无法向您推送机器人状态!');
|
|
49
|
-
}
|
|
50
|
-
// 检查登录数据库是否有数据
|
|
51
|
-
ctx.database.get('loginBili', 1, ['dynamic_group_id']).then(data => this.loginDBData = data[0]);
|
|
52
|
-
// 从数据库获取订阅
|
|
53
|
-
this.getSubFromDatabase(ctx);
|
|
54
|
-
// 判断消息发送方式
|
|
55
|
-
if (config.automaticResend) {
|
|
56
|
-
this.sendMsgFunc = async (bot, channelId, content) => {
|
|
57
|
-
// 多次尝试发送消息
|
|
58
|
-
const attempts = 3;
|
|
59
|
-
for (let i = 0; i < attempts; i++) {
|
|
60
|
-
try {
|
|
61
|
-
// 发送消息
|
|
62
|
-
await bot.sendMessage(channelId, content);
|
|
63
|
-
// 防止消息发送速度过快被忽略
|
|
64
|
-
await ctx.sleep(500);
|
|
65
|
-
// 成功发送消息,跳出循环
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
if (i === attempts - 1) { // 已尝试三次
|
|
70
|
-
this.logger.error(`发送群组ID:${channelId}消息失败!原因: ` + e.message);
|
|
71
|
-
console.log(e);
|
|
72
|
-
this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.sendMsgFunc = async (bot, guild, content) => {
|
|
80
|
-
try {
|
|
81
|
-
// 发送消息
|
|
82
|
-
await bot.sendMessage(guild, content);
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
this.logger.error(`发送群组ID:${guild}消息失败!原因: ` + e.message);
|
|
86
|
-
await this.sendPrivateMsg(`发送群组ID:${guild}消息失败,请查看日志`);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
40
|
+
// 初始化
|
|
41
|
+
this.init(ctx, config);
|
|
42
|
+
// 注册指令
|
|
90
43
|
const statusCom = ctx.command('status', '插件状态相关指令', { permissions: ['authority:5'] });
|
|
91
44
|
statusCom.subcommand('.dyn', '查看动态监测运行状态')
|
|
92
45
|
.usage('查看动态监测运行状态')
|
|
@@ -198,7 +151,7 @@ class ComRegister {
|
|
|
198
151
|
// 销毁定时器
|
|
199
152
|
this.loginTimer();
|
|
200
153
|
// 订阅之前的订阅
|
|
201
|
-
await this.
|
|
154
|
+
await this.loadSubFromDatabase(ctx);
|
|
202
155
|
// 清除控制台通知
|
|
203
156
|
ctx.ba.disposeNotifier();
|
|
204
157
|
// 发送成功登录推送
|
|
@@ -265,12 +218,7 @@ class ComRegister {
|
|
|
265
218
|
// id--
|
|
266
219
|
this.num--;
|
|
267
220
|
// 判断是否还有动态订阅
|
|
268
|
-
|
|
269
|
-
// 将动态检测关闭
|
|
270
|
-
this.dynamicDispose();
|
|
271
|
-
// 将动态监测置为空
|
|
272
|
-
this.dynamicDispose = null;
|
|
273
|
-
}
|
|
221
|
+
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
274
222
|
// 发送成功通知
|
|
275
223
|
await session.send('已取消订阅该用户');
|
|
276
224
|
// 更新控制台提示
|
|
@@ -328,6 +276,8 @@ class ComRegister {
|
|
|
328
276
|
groupId.forEach(group => {
|
|
329
277
|
channelIdArr.push({
|
|
330
278
|
channelId: group,
|
|
279
|
+
dynamic: true,
|
|
280
|
+
live: true,
|
|
331
281
|
atAll: options.atAll
|
|
332
282
|
});
|
|
333
283
|
});
|
|
@@ -387,7 +337,7 @@ class ComRegister {
|
|
|
387
337
|
// 判断targetArr是否为空
|
|
388
338
|
if (target.length === 0) {
|
|
389
339
|
// 为空则默认为当前环境
|
|
390
|
-
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 }], platform: session.event.platform }];
|
|
391
341
|
// 没有满足条件的群组或频道
|
|
392
342
|
await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
|
|
393
343
|
}
|
|
@@ -398,7 +348,7 @@ class ComRegister {
|
|
|
398
348
|
}
|
|
399
349
|
else {
|
|
400
350
|
// 未填写群号或频道号,默认为当前环境
|
|
401
|
-
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 }], platform: session.event.platform }];
|
|
402
352
|
// 发送提示消息
|
|
403
353
|
await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
|
|
404
354
|
}
|
|
@@ -406,7 +356,7 @@ class ComRegister {
|
|
|
406
356
|
}
|
|
407
357
|
else {
|
|
408
358
|
// 用户直接订阅,将当前环境赋值给target
|
|
409
|
-
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 }], platform: session.event.platform }];
|
|
410
360
|
}
|
|
411
361
|
}
|
|
412
362
|
// 定义外围变量
|
|
@@ -489,13 +439,7 @@ class ComRegister {
|
|
|
489
439
|
if (dynamicMsg) {
|
|
490
440
|
// 判断是否开启动态监测
|
|
491
441
|
if (!this.dynamicDispose) {
|
|
492
|
-
|
|
493
|
-
if (this.config.dynamicDebugMode) {
|
|
494
|
-
this.dynamicDispose = ctx.setInterval(this.debug_dynamicDetect(ctx), config.dynamicLoopTime * 1000);
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
this.dynamicDispose = ctx.setInterval(this.dynamicDetect(ctx), config.dynamicLoopTime * 1000);
|
|
498
|
-
}
|
|
442
|
+
this.enableDynamicDetect(ctx);
|
|
499
443
|
}
|
|
500
444
|
// 发送订阅消息通知
|
|
501
445
|
await session.send(`订阅${userData.info.uname}动态通知`);
|
|
@@ -580,12 +524,72 @@ class ComRegister {
|
|
|
580
524
|
await session.send('已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误');
|
|
581
525
|
});
|
|
582
526
|
}
|
|
527
|
+
async init(ctx, config) {
|
|
528
|
+
// 设置logger
|
|
529
|
+
this.logger = ctx.logger('cr');
|
|
530
|
+
// 将config设置给类属性
|
|
531
|
+
this.config = config;
|
|
532
|
+
// 拿到私人机器人实例
|
|
533
|
+
this.privateBot = ctx.bots.find(bot => bot.platform === config.master.platform);
|
|
534
|
+
if (!this.privateBot) {
|
|
535
|
+
ctx.notifier.create({
|
|
536
|
+
content: '您未配置私人机器人,将无法向您推送机器人状态!'
|
|
537
|
+
});
|
|
538
|
+
this.logger.error('您未配置私人机器人,将无法向您推送机器人状态!');
|
|
539
|
+
}
|
|
540
|
+
// 检查登录数据库是否有数据
|
|
541
|
+
this.loginDBData = (await ctx.database.get('loginBili', 1, ['dynamic_group_id']))[0];
|
|
542
|
+
// 从配置获取订阅
|
|
543
|
+
config.sub && await this.loadSubFromConfig(ctx, config.sub);
|
|
544
|
+
// 从数据库获取订阅
|
|
545
|
+
await this.loadSubFromDatabase(ctx);
|
|
546
|
+
// 判断消息发送方式
|
|
547
|
+
if (config.automaticResend) {
|
|
548
|
+
this.sendMsgFunc = async (bot, channelId, content) => {
|
|
549
|
+
// 多次尝试发送消息
|
|
550
|
+
const attempts = 3;
|
|
551
|
+
for (let i = 0; i < attempts; i++) {
|
|
552
|
+
try {
|
|
553
|
+
// 发送消息
|
|
554
|
+
await bot.sendMessage(channelId, content);
|
|
555
|
+
// 防止消息发送速度过快被忽略
|
|
556
|
+
await ctx.sleep(500);
|
|
557
|
+
// 成功发送消息,跳出循环
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
catch (e) {
|
|
561
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
562
|
+
this.logger.error(`发送群组ID:${channelId}消息失败!原因: ` + e.message);
|
|
563
|
+
console.log(e);
|
|
564
|
+
this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
this.sendMsgFunc = async (bot, guild, content) => {
|
|
572
|
+
try {
|
|
573
|
+
// 发送消息
|
|
574
|
+
await bot.sendMessage(guild, content);
|
|
575
|
+
}
|
|
576
|
+
catch (e) {
|
|
577
|
+
this.logger.error(`发送群组ID:${guild}消息失败!原因: ` + e.message);
|
|
578
|
+
await this.sendPrivateMsg(`发送群组ID:${guild}消息失败,请查看日志`);
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
// 检查是否需要动态监测
|
|
583
|
+
this.checkIfDynamicDetectIsNeeded(ctx);
|
|
584
|
+
// 在控制台中显示订阅对象
|
|
585
|
+
this.updateSubNotifier(ctx);
|
|
586
|
+
}
|
|
583
587
|
splitMultiPlatformStr(str) {
|
|
584
588
|
return str.split(';').map(cv => cv.split('.')).map(([idStr, platform]) => {
|
|
585
589
|
const channelIdArr = idStr.split(',').map(id => {
|
|
586
590
|
const atAll = /@$/.test(id); // 使用正则表达式检查 id 是否以 @ 结尾
|
|
587
591
|
const channelId = atAll ? id.slice(0, -1) : id; // 去除末尾的 @
|
|
588
|
-
return { channelId, atAll };
|
|
592
|
+
return { channelId, dynamic: true, live: true, atAll };
|
|
589
593
|
});
|
|
590
594
|
return { channelIdArr, platform };
|
|
591
595
|
});
|
|
@@ -656,22 +660,33 @@ class ComRegister {
|
|
|
656
660
|
if (target.channelIdArr[0].channelId === 'all') {
|
|
657
661
|
// 获取所有guild
|
|
658
662
|
for (const guild of (await bot.getGuildList()).data) {
|
|
659
|
-
sendArr.push({
|
|
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
|
+
});
|
|
660
669
|
}
|
|
661
670
|
}
|
|
662
671
|
else {
|
|
663
672
|
sendArr = target.channelIdArr;
|
|
664
673
|
}
|
|
665
|
-
//
|
|
674
|
+
// 判断是否是直播推送,如果是则需要进一步判断是否需要艾特群体成员
|
|
666
675
|
if (live) {
|
|
667
|
-
//
|
|
676
|
+
// 直播开播推送,判断是否需要艾特全体成员
|
|
668
677
|
for (const channel of sendArr) {
|
|
669
|
-
|
|
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
|
+
}
|
|
670
682
|
}
|
|
671
683
|
}
|
|
672
684
|
else {
|
|
673
685
|
for (const channel of sendArr) {
|
|
674
|
-
|
|
686
|
+
// 判断是否需要推送动态消息和直播消息
|
|
687
|
+
if (channel.dynamic || channel.live) {
|
|
688
|
+
await this.sendMsgFunc(bot, channel.channelId, content);
|
|
689
|
+
}
|
|
675
690
|
}
|
|
676
691
|
}
|
|
677
692
|
}
|
|
@@ -1401,7 +1416,69 @@ class ComRegister {
|
|
|
1401
1416
|
// 订阅成功
|
|
1402
1417
|
return { flag: true, msg: '用户订阅成功' };
|
|
1403
1418
|
}
|
|
1404
|
-
async
|
|
1419
|
+
async loadSubFromConfig(ctx, subs) {
|
|
1420
|
+
for (const sub of subs) {
|
|
1421
|
+
// 定义Data
|
|
1422
|
+
let data;
|
|
1423
|
+
// 定义直播销毁函数
|
|
1424
|
+
let liveDispose;
|
|
1425
|
+
// 判断是否需要订阅直播
|
|
1426
|
+
if (sub.live) {
|
|
1427
|
+
// 获取用户信息
|
|
1428
|
+
let content;
|
|
1429
|
+
// 设置重试次数
|
|
1430
|
+
const attempts = 3;
|
|
1431
|
+
for (let i = 0; i < attempts; i++) {
|
|
1432
|
+
try {
|
|
1433
|
+
// 获取用户信息
|
|
1434
|
+
content = await ctx.ba.getUserInfo(sub.uid);
|
|
1435
|
+
// 成功则跳出循环
|
|
1436
|
+
break;
|
|
1437
|
+
}
|
|
1438
|
+
catch (e) {
|
|
1439
|
+
this.logger.error('getSubFromDatabase() getUserInfo() 发生了错误,错误为:' + e.message);
|
|
1440
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
1441
|
+
// 发送私聊消息并重启服务
|
|
1442
|
+
return await this.sendPrivateMsgAndStopService(ctx);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
// 获取data
|
|
1447
|
+
data = content.data;
|
|
1448
|
+
// 检查roomid是否存在
|
|
1449
|
+
if (!data.live_room) {
|
|
1450
|
+
// 用户没有开通直播间,无法订阅直播
|
|
1451
|
+
sub.live = false;
|
|
1452
|
+
// 发送提示
|
|
1453
|
+
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1454
|
+
}
|
|
1455
|
+
// 判断是否订阅直播
|
|
1456
|
+
if (sub.live) {
|
|
1457
|
+
// 订阅直播
|
|
1458
|
+
liveDispose = ctx.setInterval(() => {
|
|
1459
|
+
this.liveDetect(ctx, data.live_room.room_id, sub.target);
|
|
1460
|
+
}, this.config.liveLoopTime * 1000);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
// 在B站中订阅该对象
|
|
1464
|
+
const subInfo = await this.subUserInBili(ctx, sub.uid);
|
|
1465
|
+
// 判断订阅是否成功
|
|
1466
|
+
if (!subInfo.flag)
|
|
1467
|
+
this.logger.warn(subInfo.msg);
|
|
1468
|
+
// 将该订阅添加到sm中
|
|
1469
|
+
this.subManager.push({
|
|
1470
|
+
id: +sub.uid,
|
|
1471
|
+
uid: sub.uid,
|
|
1472
|
+
roomId: sub.live ? data.live_room.roomid : '',
|
|
1473
|
+
target: sub.target,
|
|
1474
|
+
platform: '',
|
|
1475
|
+
live: sub.live,
|
|
1476
|
+
dynamic: sub.dynamic,
|
|
1477
|
+
liveDispose
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
async loadSubFromDatabase(ctx) {
|
|
1405
1482
|
// 判断登录信息是否已加载完毕
|
|
1406
1483
|
await this.checkIfLoginInfoIsLoaded(ctx);
|
|
1407
1484
|
// 如果未登录,则直接返回
|
|
@@ -1499,6 +1576,7 @@ class ComRegister {
|
|
|
1499
1576
|
this.logger.info(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
1500
1577
|
// Send msg
|
|
1501
1578
|
await this.sendPrivateMsg(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
1579
|
+
// 直接返回
|
|
1502
1580
|
return;
|
|
1503
1581
|
}
|
|
1504
1582
|
// 构建订阅对象
|
|
@@ -1516,11 +1594,12 @@ class ComRegister {
|
|
|
1516
1594
|
if (sub.live) {
|
|
1517
1595
|
// 判断订阅直播数是否超过限制
|
|
1518
1596
|
if (!this.config.unlockSubLimits && liveSubNum >= 3) {
|
|
1597
|
+
// 将live改为false
|
|
1519
1598
|
subManagerItem.live = false;
|
|
1520
1599
|
// log
|
|
1521
1600
|
this.logger.warn(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
1522
1601
|
// 发送错误消息
|
|
1523
|
-
this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
1602
|
+
await this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
1524
1603
|
}
|
|
1525
1604
|
else {
|
|
1526
1605
|
// 直播订阅数+1
|
|
@@ -1534,18 +1613,20 @@ class ComRegister {
|
|
|
1534
1613
|
// 保存新订阅对象
|
|
1535
1614
|
this.subManager.push(subManagerItem);
|
|
1536
1615
|
}
|
|
1616
|
+
}
|
|
1617
|
+
checkIfDynamicDetectIsNeeded(ctx) {
|
|
1537
1618
|
// 检查是否有订阅对象需要动态监测
|
|
1538
|
-
if (this.subManager.some(sub => sub.dynamic))
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1619
|
+
if (this.subManager.some(sub => sub.dynamic))
|
|
1620
|
+
this.enableDynamicDetect(ctx);
|
|
1621
|
+
}
|
|
1622
|
+
enableDynamicDetect(ctx) {
|
|
1623
|
+
// 开始动态监测
|
|
1624
|
+
if (this.config.dynamicDebugMode) {
|
|
1625
|
+
this.dynamicDispose = ctx.setInterval(this.debug_dynamicDetect(ctx), this.config.dynamicLoopTime * 1000);
|
|
1626
|
+
}
|
|
1627
|
+
else {
|
|
1628
|
+
this.dynamicDispose = ctx.setInterval(this.dynamicDetect(ctx), this.config.dynamicLoopTime * 1000);
|
|
1546
1629
|
}
|
|
1547
|
-
// 在控制台中显示订阅对象
|
|
1548
|
-
this.updateSubNotifier(ctx);
|
|
1549
1630
|
}
|
|
1550
1631
|
unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
|
|
1551
1632
|
// 定义返回消息
|
|
@@ -1628,7 +1709,7 @@ class ComRegister {
|
|
|
1628
1709
|
}
|
|
1629
1710
|
}
|
|
1630
1711
|
checkIfUserIsTheLastOneWhoSubDyn() {
|
|
1631
|
-
if (this.subManager.some(sub => sub.dynamic)) {
|
|
1712
|
+
if (this.dynamicDispose && !this.subManager.some(sub => sub.dynamic)) {
|
|
1632
1713
|
// 停止动态监测
|
|
1633
1714
|
this.dynamicDispose();
|
|
1634
1715
|
this.dynamicDispose = null;
|
|
@@ -1665,6 +1746,20 @@ class ComRegister {
|
|
|
1665
1746
|
}
|
|
1666
1747
|
(function (ComRegister) {
|
|
1667
1748
|
ComRegister.Config = koishi_1.Schema.object({
|
|
1749
|
+
sub: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
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: 是否需要订阅直播'),
|
|
1668
1763
|
master: koishi_1.Schema.object({
|
|
1669
1764
|
enable: koishi_1.Schema.boolean(),
|
|
1670
1765
|
platform: koishi_1.Schema.string(),
|
package/lib/index.d.ts
CHANGED
|
@@ -15,6 +15,21 @@ export interface Config {
|
|
|
15
15
|
automaticResend: boolean;
|
|
16
16
|
renderType: 'render' | 'page';
|
|
17
17
|
userAgent: string;
|
|
18
|
+
subTitle: {};
|
|
19
|
+
sub: Array<{
|
|
20
|
+
uid: string;
|
|
21
|
+
dynamic: boolean;
|
|
22
|
+
live: boolean;
|
|
23
|
+
target: Array<{
|
|
24
|
+
channelIdArr: Array<{
|
|
25
|
+
channelId: string;
|
|
26
|
+
dynamic: boolean;
|
|
27
|
+
live: boolean;
|
|
28
|
+
atAll: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
platform: string;
|
|
31
|
+
}>;
|
|
32
|
+
}>;
|
|
18
33
|
dynamic: {};
|
|
19
34
|
dynamicUrl: boolean;
|
|
20
35
|
dynamicCheckNumber: number;
|
package/lib/index.js
CHANGED
|
@@ -93,6 +93,21 @@ exports.Config = koishi_1.Schema.object({
|
|
|
93
93
|
userAgent: koishi_1.Schema.string()
|
|
94
94
|
.required()
|
|
95
95
|
.description('设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111'),
|
|
96
|
+
subTitle: koishi_1.Schema.object({}).description('手动订阅'),
|
|
97
|
+
sub: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
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: 是否需要订阅直播'),
|
|
96
111
|
dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
|
|
97
112
|
dynamicUrl: koishi_1.Schema.boolean()
|
|
98
113
|
.default(false)
|
|
@@ -290,6 +305,7 @@ class ServerManager extends koishi_1.Service {
|
|
|
290
305
|
});
|
|
291
306
|
// CR = ComRegister
|
|
292
307
|
const cr = this.ctx.plugin(comRegister_1.default, {
|
|
308
|
+
sub: globalConfig.sub,
|
|
293
309
|
master: globalConfig.master,
|
|
294
310
|
unlockSubLimits: globalConfig.unlockSubLimits,
|
|
295
311
|
automaticResend: globalConfig.automaticResend,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -201,6 +201,8 @@
|
|
|
201
201
|
- ver 2.0.0-alpha.12 更改:开启艾特全体成员后,只有在开播时才艾特全体成员
|
|
202
202
|
- ver 2.0.0-alpha.13 修复:无法对TG群组的特殊频道号进行订阅处理;提示 `您未配置对应平台的机器人,不能在该平台进行订阅操作` 仍进行订阅操作
|
|
203
203
|
- ver 2.0.0-alpha.14 修复:订阅TG群组时提示输入无效
|
|
204
|
+
- ver 2.0.0-alpha.15 新增:手动订阅功能 修复:一些潜在的bug
|
|
205
|
+
- ver 2.0.0-alpha.16 优化:手动订阅功能
|
|
204
206
|
|
|
205
207
|
## 交流群
|
|
206
208
|
|