koishi-plugin-bilibili-notify 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +3 -0
- package/lib/biliAPI.js +38 -0
- package/lib/blive.d.ts +9 -0
- package/lib/blive.js +51 -0
- package/lib/comRegister.d.ts +49 -12
- package/lib/comRegister.js +559 -406
- package/lib/database.d.ts +1 -2
- package/lib/database.js +1 -2
- package/lib/generateImg.js +1 -1
- package/lib/index.d.ts +16 -2
- package/lib/index.js +30 -11
- package/package.json +2 -1
- package/{README.md → readme.md} +39 -11
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>;
|
|
@@ -36,6 +37,7 @@ declare class BiliAPI extends Service {
|
|
|
36
37
|
getAllDynamic(updateBaseline?: string): Promise<any>;
|
|
37
38
|
hasNewDynamic(updateBaseline: string): Promise<any>;
|
|
38
39
|
follow(fid: string): Promise<any>;
|
|
40
|
+
getRelationGroupDetail(tagid: string): Promise<any>;
|
|
39
41
|
getCookieInfo(refreshToken: string): Promise<any>;
|
|
40
42
|
getUserInfo(mid: string): Promise<any>;
|
|
41
43
|
getWbiKeys(): Promise<{
|
|
@@ -52,6 +54,7 @@ declare class BiliAPI extends Service {
|
|
|
52
54
|
createNewClient(): void;
|
|
53
55
|
getTimeOfUTC8(): number;
|
|
54
56
|
getCookies(): string;
|
|
57
|
+
getCookiesForHeader(): Promise<string>;
|
|
55
58
|
getLoginInfoIsLoaded(): boolean;
|
|
56
59
|
getLoginInfoFromDB(): Promise<{
|
|
57
60
|
cookies: any;
|
package/lib/biliAPI.js
CHANGED
|
@@ -40,6 +40,9 @@ const CREATE_GROUP = 'https://api.bilibili.com/x/relation/tag/create';
|
|
|
40
40
|
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
|
+
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';
|
|
43
46
|
class BiliAPI extends koishi_1.Service {
|
|
44
47
|
static inject = ['database', 'notifier'];
|
|
45
48
|
jar;
|
|
@@ -102,6 +105,17 @@ class BiliAPI extends koishi_1.Service {
|
|
|
102
105
|
return decrypted.toString();
|
|
103
106
|
}
|
|
104
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
|
+
}
|
|
105
119
|
async getServerUTCTime() {
|
|
106
120
|
try {
|
|
107
121
|
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
|
@@ -240,6 +254,15 @@ class BiliAPI extends koishi_1.Service {
|
|
|
240
254
|
throw new Error('网络异常,本次请求失败!');
|
|
241
255
|
}
|
|
242
256
|
}
|
|
257
|
+
async getRelationGroupDetail(tagid) {
|
|
258
|
+
try {
|
|
259
|
+
const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
|
|
260
|
+
return data;
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
throw new Error('网络异常,本次请求失败!');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
243
266
|
// Check if Token need refresh
|
|
244
267
|
async getCookieInfo(refreshToken) {
|
|
245
268
|
try {
|
|
@@ -352,6 +375,21 @@ class BiliAPI extends koishi_1.Service {
|
|
|
352
375
|
const cookies = JSON.stringify(this.jar.serializeSync().cookies);
|
|
353
376
|
return cookies;
|
|
354
377
|
}
|
|
378
|
+
async getCookiesForHeader() {
|
|
379
|
+
try {
|
|
380
|
+
// 获取cookies对象
|
|
381
|
+
const cookies = this.jar.serializeSync().cookies;
|
|
382
|
+
// 将每个 cookie 对象转换为 "key=value" 形式,并用 "; " 连接起来
|
|
383
|
+
const cookieHeader = cookies
|
|
384
|
+
.map(cookie => `${cookie.key}=${cookie.value}`)
|
|
385
|
+
.join('; ');
|
|
386
|
+
return cookieHeader;
|
|
387
|
+
}
|
|
388
|
+
catch (e) {
|
|
389
|
+
console.error("无效的 JSON 格式:", e);
|
|
390
|
+
return "";
|
|
391
|
+
}
|
|
392
|
+
}
|
|
355
393
|
getLoginInfoIsLoaded() {
|
|
356
394
|
return this.loginInfoIsLoaded;
|
|
357
395
|
}
|
package/lib/blive.d.ts
ADDED
package/lib/blive.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const blive_message_listener_1 = require("blive-message-listener");
|
|
4
|
+
class BLive {
|
|
5
|
+
// 必要服务
|
|
6
|
+
static inject = ['ba'];
|
|
7
|
+
// 定义类属性
|
|
8
|
+
ctx;
|
|
9
|
+
logger;
|
|
10
|
+
constructor(ctx) {
|
|
11
|
+
// 将ctx赋值给类属性
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
// 创建logger
|
|
14
|
+
this.logger = ctx.logger('bl');
|
|
15
|
+
// TEST
|
|
16
|
+
ctx.setTimeout(() => {
|
|
17
|
+
this.startLiveRoomListener(732);
|
|
18
|
+
}, 1000);
|
|
19
|
+
}
|
|
20
|
+
async startLiveRoomListener(roomId) {
|
|
21
|
+
// 获取cookieStr
|
|
22
|
+
const cookiesStr = await this.ctx.ba.getCookiesForHeader();
|
|
23
|
+
// 构建消息处理函数
|
|
24
|
+
const handler = {
|
|
25
|
+
onOpen: () => {
|
|
26
|
+
this.logger.info('服务器连接成功');
|
|
27
|
+
},
|
|
28
|
+
onClose: () => {
|
|
29
|
+
this.logger.info('服务器连接已断开');
|
|
30
|
+
},
|
|
31
|
+
onIncomeDanmu: (msg) => {
|
|
32
|
+
console.log(msg.id, msg.body);
|
|
33
|
+
},
|
|
34
|
+
onIncomeSuperChat: (msg) => {
|
|
35
|
+
console.log(msg.id, msg.body);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// 获取自身信息
|
|
39
|
+
const mySelfInfo = await this.ctx.ba.getMyselfInfo();
|
|
40
|
+
// 创建实例
|
|
41
|
+
(0, blive_message_listener_1.startListen)(roomId, handler, {
|
|
42
|
+
ws: {
|
|
43
|
+
headers: {
|
|
44
|
+
Cookie: cookiesStr
|
|
45
|
+
},
|
|
46
|
+
uid: mySelfInfo.data.mid
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = BLive;
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import { Bot, Context, Logger, Schema, Session } from "koishi";
|
|
1
|
+
import { Bot, Context, FlatPick, Logger, Schema, Session } from "koishi";
|
|
2
2
|
import { Notifier } from "@koishijs/plugin-notifier";
|
|
3
|
+
import { LoginBili } from "./database";
|
|
4
|
+
type ChannelIdArr = Array<{
|
|
5
|
+
channelId: string;
|
|
6
|
+
dynamic: boolean;
|
|
7
|
+
live: boolean;
|
|
8
|
+
atAll: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
type TargetItem = {
|
|
11
|
+
channelIdArr: ChannelIdArr;
|
|
12
|
+
platform: string;
|
|
13
|
+
};
|
|
14
|
+
type Target = Array<TargetItem>;
|
|
3
15
|
type SubItem = {
|
|
4
16
|
id: number;
|
|
5
17
|
uid: string;
|
|
6
18
|
roomId: string;
|
|
7
|
-
|
|
19
|
+
target: Target;
|
|
8
20
|
platform: string;
|
|
9
21
|
live: boolean;
|
|
10
22
|
dynamic: boolean;
|
|
@@ -13,6 +25,7 @@ type SubItem = {
|
|
|
13
25
|
type SubManager = Array<SubItem>;
|
|
14
26
|
declare class ComRegister {
|
|
15
27
|
static inject: string[];
|
|
28
|
+
qqRelatedBotList: Array<string>;
|
|
16
29
|
logger: Logger;
|
|
17
30
|
config: ComRegister.Config;
|
|
18
31
|
loginTimer: Function;
|
|
@@ -20,44 +33,68 @@ declare class ComRegister {
|
|
|
20
33
|
rebootCount: number;
|
|
21
34
|
subNotifier: Notifier;
|
|
22
35
|
subManager: SubManager;
|
|
23
|
-
|
|
36
|
+
loginDBData: FlatPick<LoginBili, "dynamic_group_id">;
|
|
37
|
+
privateBot: Bot<Context>;
|
|
24
38
|
dynamicDispose: Function;
|
|
25
|
-
sendMsgFunc: (
|
|
39
|
+
sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
|
|
26
40
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
41
|
+
init(ctx: Context, config: ComRegister.Config): Promise<void>;
|
|
42
|
+
splitMultiPlatformStr(str: string): Target;
|
|
43
|
+
getBot(ctx: Context, pf: string): Bot<Context, any>;
|
|
27
44
|
sendPrivateMsg(content: string): Promise<void>;
|
|
28
45
|
sendPrivateMsgAndRebootService(ctx: Context): Promise<void>;
|
|
29
46
|
sendPrivateMsgAndStopService(ctx: Context): Promise<void>;
|
|
30
|
-
sendMsg(targets:
|
|
47
|
+
sendMsg(ctx: Context, targets: Target, content: any, live?: boolean): Promise<void>;
|
|
31
48
|
dynamicDetect(ctx: Context): () => Promise<void>;
|
|
32
49
|
debug_dynamicDetect(ctx: Context): () => Promise<void>;
|
|
33
|
-
liveDetect(ctx: Context, roomId: string,
|
|
50
|
+
liveDetect(ctx: Context, roomId: string, target: Target): () => Promise<void>;
|
|
34
51
|
subShow(): string;
|
|
35
|
-
checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session,
|
|
52
|
+
checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session, liveRoomData: any): Promise<Array<boolean>>;
|
|
36
53
|
updateSubNotifier(ctx: Context): void;
|
|
37
54
|
checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
|
|
38
|
-
|
|
55
|
+
subUserInBili(ctx: Context, mid: string): Promise<{
|
|
56
|
+
flag: boolean;
|
|
57
|
+
msg: string;
|
|
58
|
+
}>;
|
|
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;
|
|
39
63
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
40
|
-
|
|
64
|
+
checkIfUserIsTheLastOneWhoSubDyn(): void;
|
|
41
65
|
unsubAll(ctx: Context, uid: string): void;
|
|
42
66
|
checkIfIsLogin(ctx: Context): Promise<boolean>;
|
|
43
67
|
}
|
|
44
68
|
declare namespace ComRegister {
|
|
45
69
|
interface Config {
|
|
46
|
-
|
|
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
|
+
}>;
|
|
47
84
|
master: {
|
|
48
85
|
enable: boolean;
|
|
86
|
+
platform: string;
|
|
49
87
|
masterAccount: string;
|
|
50
88
|
masterAccountGuildId: string;
|
|
51
89
|
};
|
|
52
90
|
unlockSubLimits: boolean;
|
|
53
91
|
automaticResend: boolean;
|
|
54
92
|
changeMasterInfoApi: boolean;
|
|
55
|
-
liveStartAtAll: boolean;
|
|
56
93
|
restartPush: boolean;
|
|
57
|
-
pushUrl: boolean;
|
|
58
94
|
pushTime: number;
|
|
59
95
|
liveLoopTime: number;
|
|
60
96
|
customLiveStart: string;
|
|
97
|
+
customLive: string;
|
|
61
98
|
customLiveEnd: string;
|
|
62
99
|
dynamicUrl: boolean;
|
|
63
100
|
dynamicLoopTime: number;
|