koishi-plugin-bilibili-notify 3.0.0-alpha.1 → 3.0.0-alpha.3
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.js +1 -0
- package/lib/blive.d.ts +3 -2
- package/lib/blive.js +14 -7
- package/lib/comRegister.d.ts +26 -24
- package/lib/comRegister.js +247 -337
- package/lib/generateImg.js +2 -2
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -8
- package/package.json +1 -1
- package/readme.md +3 -1
package/lib/biliAPI.js
CHANGED
package/lib/blive.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ declare module 'koishi' {
|
|
|
7
7
|
}
|
|
8
8
|
declare class BLive extends Service {
|
|
9
9
|
static inject: string[];
|
|
10
|
+
private blConfig;
|
|
10
11
|
private listenerRecord;
|
|
11
12
|
private timerRecord;
|
|
12
|
-
constructor(ctx: Context);
|
|
13
|
+
constructor(ctx: Context, config: BLive.Config);
|
|
13
14
|
protected stop(): Awaitable<void>;
|
|
14
|
-
startLiveRoomListener(roomId: string, handler: MsgHandler,
|
|
15
|
+
startLiveRoomListener(roomId: string, handler: MsgHandler, danmakuPushTime: () => void): Promise<void>;
|
|
15
16
|
closeListener(roomId: string): void;
|
|
16
17
|
}
|
|
17
18
|
declare namespace BLive {
|
package/lib/blive.js
CHANGED
|
@@ -5,11 +5,16 @@ const blive_message_listener_1 = require("blive-message-listener");
|
|
|
5
5
|
class BLive extends koishi_1.Service {
|
|
6
6
|
// 必要服务
|
|
7
7
|
static inject = ['ba'];
|
|
8
|
+
// 配置
|
|
9
|
+
blConfig;
|
|
8
10
|
// 定义类属性
|
|
9
11
|
listenerRecord = {};
|
|
10
12
|
timerRecord = {};
|
|
11
|
-
constructor(ctx) {
|
|
13
|
+
constructor(ctx, config) {
|
|
14
|
+
// Extends super
|
|
12
15
|
super(ctx, 'bl');
|
|
16
|
+
// 将config赋值给类属性
|
|
17
|
+
this.blConfig = config;
|
|
13
18
|
}
|
|
14
19
|
// 注册插件dispose逻辑
|
|
15
20
|
stop() {
|
|
@@ -18,7 +23,7 @@ class BLive extends koishi_1.Service {
|
|
|
18
23
|
this.closeListener(key);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
async startLiveRoomListener(roomId, handler,
|
|
26
|
+
async startLiveRoomListener(roomId, handler, danmakuPushTime) {
|
|
22
27
|
// 获取cookieStr
|
|
23
28
|
const cookiesStr = await this.ctx.ba.getCookiesForHeader();
|
|
24
29
|
// 获取自身信息
|
|
@@ -33,18 +38,20 @@ class BLive extends koishi_1.Service {
|
|
|
33
38
|
}
|
|
34
39
|
});
|
|
35
40
|
// 默认30s推送一次弹幕消息到群组并将dispose函数保存到Record中
|
|
36
|
-
this.timerRecord[roomId] = this.ctx.setInterval(
|
|
41
|
+
this.timerRecord[roomId] = this.ctx.setInterval(danmakuPushTime, this.blConfig.danmakuPushTime * 1000 * 60);
|
|
42
|
+
// logger
|
|
43
|
+
this.logger.info(`${roomId}直播间弹幕监听已开启`);
|
|
37
44
|
}
|
|
38
45
|
closeListener(roomId) {
|
|
39
46
|
// 判断直播间监听器是否关闭
|
|
40
47
|
if (!this.listenerRecord || !this.listenerRecord[roomId] || !this.listenerRecord[roomId].closed) {
|
|
41
48
|
// 输出logger
|
|
42
|
-
this.logger.info(
|
|
49
|
+
this.logger.info(`${roomId}直播间弹幕监听器无需关闭`);
|
|
43
50
|
}
|
|
44
51
|
// 判断消息发送定时器是否关闭
|
|
45
52
|
if (!this.timerRecord || !this.timerRecord[roomId]) {
|
|
46
53
|
// 输出logger
|
|
47
|
-
this.logger.info(
|
|
54
|
+
this.logger.info(`${roomId}直播间消息发送定时器无需关闭`);
|
|
48
55
|
}
|
|
49
56
|
// 关闭直播间监听器
|
|
50
57
|
this.listenerRecord[roomId].close();
|
|
@@ -57,12 +64,12 @@ class BLive extends koishi_1.Service {
|
|
|
57
64
|
// 删除消息发送定时器
|
|
58
65
|
delete this.timerRecord[roomId];
|
|
59
66
|
// 输出logger
|
|
60
|
-
this.logger.info(
|
|
67
|
+
this.logger.info(`${roomId}直播间弹幕监听已关闭`);
|
|
61
68
|
// 直接返回
|
|
62
69
|
return;
|
|
63
70
|
}
|
|
64
71
|
// 未关闭成功
|
|
65
|
-
this.logger.warn(
|
|
72
|
+
this.logger.warn(`${roomId}直播间弹幕监听未成功关闭`);
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type ChannelIdArr = Array<{
|
|
|
11
11
|
channelId: string;
|
|
12
12
|
dynamic: boolean;
|
|
13
13
|
live: boolean;
|
|
14
|
+
liveDanmaku: boolean;
|
|
14
15
|
atAll: boolean;
|
|
15
16
|
}>;
|
|
16
17
|
type TargetItem = {
|
|
@@ -26,7 +27,6 @@ type SubItem = {
|
|
|
26
27
|
platform: string;
|
|
27
28
|
live: boolean;
|
|
28
29
|
dynamic: boolean;
|
|
29
|
-
liveDispose: Function;
|
|
30
30
|
};
|
|
31
31
|
type SubManager = Array<SubItem>;
|
|
32
32
|
declare class ComRegister {
|
|
@@ -38,50 +38,52 @@ declare class ComRegister {
|
|
|
38
38
|
num: number;
|
|
39
39
|
rebootCount: number;
|
|
40
40
|
subNotifier: Notifier;
|
|
41
|
+
ctx: Context;
|
|
41
42
|
subManager: SubManager;
|
|
42
43
|
loginDBData: FlatPick<LoginBili, "dynamic_group_id">;
|
|
43
44
|
privateBot: Bot<Context>;
|
|
44
45
|
dynamicDispose: Function;
|
|
45
46
|
sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
|
|
46
47
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
47
|
-
init(
|
|
48
|
+
init(config: ComRegister.Config): Promise<void>;
|
|
48
49
|
splitMultiPlatformStr(str: string): Target;
|
|
49
|
-
getBot(
|
|
50
|
+
getBot(pf: string): Bot<Context, any>;
|
|
50
51
|
sendPrivateMsg(content: string): Promise<void>;
|
|
51
|
-
sendPrivateMsgAndRebootService(
|
|
52
|
-
sendPrivateMsgAndStopService(
|
|
53
|
-
sendMsg(
|
|
54
|
-
dynamicDetect(
|
|
55
|
-
debug_dynamicDetect(
|
|
56
|
-
sendLiveNotifyCard(
|
|
52
|
+
sendPrivateMsgAndRebootService(): Promise<void>;
|
|
53
|
+
sendPrivateMsgAndStopService(): Promise<void>;
|
|
54
|
+
sendMsg(targets: Target, content: any, live?: boolean): Promise<void>;
|
|
55
|
+
dynamicDetect(): () => Promise<void>;
|
|
56
|
+
debug_dynamicDetect(): () => Promise<void>;
|
|
57
|
+
sendLiveNotifyCard(info: {
|
|
57
58
|
username: string;
|
|
58
59
|
userface: string;
|
|
59
60
|
target: Target;
|
|
60
61
|
data: any;
|
|
61
62
|
}, liveType: LiveType, liveNotifyMsg?: string): Promise<void>;
|
|
62
|
-
useMasterInfo(
|
|
63
|
+
useMasterInfo(uid: string): Promise<{
|
|
63
64
|
username: string;
|
|
64
65
|
userface: string;
|
|
66
|
+
roomId: number;
|
|
65
67
|
}>;
|
|
66
|
-
useLiveRoomInfo(
|
|
67
|
-
liveDetectWithAPI(
|
|
68
|
-
liveDetectWithListener(
|
|
68
|
+
useLiveRoomInfo(roomId: string): Promise<any>;
|
|
69
|
+
liveDetectWithAPI(): Promise<() => Promise<void>>;
|
|
70
|
+
liveDetectWithListener(roomId: string, target: Target): Promise<void>;
|
|
69
71
|
subShow(): string;
|
|
70
72
|
checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session, liveRoomData: any): Promise<Array<boolean>>;
|
|
71
|
-
updateSubNotifier(
|
|
72
|
-
checkIfLoginInfoIsLoaded(
|
|
73
|
-
subUserInBili(
|
|
73
|
+
updateSubNotifier(): void;
|
|
74
|
+
checkIfLoginInfoIsLoaded(): Promise<unknown>;
|
|
75
|
+
subUserInBili(mid: string): Promise<{
|
|
74
76
|
flag: boolean;
|
|
75
77
|
msg: string;
|
|
76
78
|
}>;
|
|
77
|
-
loadSubFromConfig(
|
|
78
|
-
loadSubFromDatabase(
|
|
79
|
-
checkIfDynamicDetectIsNeeded(
|
|
80
|
-
enableDynamicDetect(
|
|
81
|
-
unsubSingle(
|
|
79
|
+
loadSubFromConfig(subs: ComRegister.Config["sub"]): Promise<void>;
|
|
80
|
+
loadSubFromDatabase(): Promise<void>;
|
|
81
|
+
checkIfDynamicDetectIsNeeded(): void;
|
|
82
|
+
enableDynamicDetect(): void;
|
|
83
|
+
unsubSingle(id: string, type: number): string;
|
|
82
84
|
checkIfUserIsTheLastOneWhoSubDyn(): void;
|
|
83
|
-
unsubAll(
|
|
84
|
-
checkIfIsLogin(
|
|
85
|
+
unsubAll(uid: string): void;
|
|
86
|
+
checkIfIsLogin(): Promise<boolean>;
|
|
85
87
|
}
|
|
86
88
|
declare namespace ComRegister {
|
|
87
89
|
interface Config {
|
|
@@ -94,6 +96,7 @@ declare namespace ComRegister {
|
|
|
94
96
|
channelId: string;
|
|
95
97
|
dynamic: boolean;
|
|
96
98
|
live: boolean;
|
|
99
|
+
liveDanmaku: boolean;
|
|
97
100
|
atAll: boolean;
|
|
98
101
|
}>;
|
|
99
102
|
platform: string;
|
|
@@ -107,7 +110,6 @@ declare namespace ComRegister {
|
|
|
107
110
|
};
|
|
108
111
|
unlockSubLimits: boolean;
|
|
109
112
|
automaticResend: boolean;
|
|
110
|
-
changeMasterInfoApi: boolean;
|
|
111
113
|
restartPush: boolean;
|
|
112
114
|
pushTime: number;
|
|
113
115
|
liveLoopTime: number;
|