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