koishi-plugin-bilibili-notify 1.3.7 → 2.0.0-alpha.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 +8 -0
- package/lib/biliAPI.js +115 -0
- package/lib/comRegister.d.ts +26 -30
- package/lib/comRegister.js +528 -669
- package/lib/database.d.ts +1 -0
- package/lib/database.js +7 -6
- package/lib/generateImg.d.ts +2 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +31 -16
- package/package.json +8 -8
- package/readme.md +3 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -28,7 +28,14 @@ declare class BiliAPI extends Service {
|
|
|
28
28
|
decrypt(text: string): string;
|
|
29
29
|
getServerUTCTime(): Promise<number>;
|
|
30
30
|
getTimeNow(): Promise<any>;
|
|
31
|
+
getAllGroup(): Promise<any>;
|
|
32
|
+
removeUserFromGroup(mid: string): Promise<any>;
|
|
33
|
+
copyUserToGroup(mid: string, groupId: string): Promise<any>;
|
|
31
34
|
getUserSpaceDynamic(mid: string): Promise<any>;
|
|
35
|
+
createGroup(tag: string): Promise<any>;
|
|
36
|
+
getAllDynamic(updateBaseline?: string): Promise<any>;
|
|
37
|
+
hasNewDynamic(updateBaseline: string): Promise<any>;
|
|
38
|
+
follow(fid: string): Promise<any>;
|
|
32
39
|
getCookieInfo(refreshToken: string): Promise<any>;
|
|
33
40
|
getUserInfo(mid: string): Promise<any>;
|
|
34
41
|
getWbiKeys(): Promise<{
|
|
@@ -50,6 +57,7 @@ declare class BiliAPI extends Service {
|
|
|
50
57
|
cookies: any;
|
|
51
58
|
refresh_token: string;
|
|
52
59
|
}>;
|
|
60
|
+
getCSRF(): any;
|
|
53
61
|
loadCookiesFromDatabase(): Promise<void>;
|
|
54
62
|
enableRefreshCookiesDetect(): void;
|
|
55
63
|
checkIfTokenNeedRefresh(refreshToken: string, csrf: string, times?: number): Promise<void>;
|
package/lib/biliAPI.js
CHANGED
|
@@ -23,6 +23,8 @@ const mixinKeyEncTab = [
|
|
|
23
23
|
// 在getUserInfo中检测到番剧出差的UID时,要传回的数据:
|
|
24
24
|
const bangumiTripData = { "code": 0, "data": { "live_room": { "roomid": 931774 } } };
|
|
25
25
|
const GET_USER_SPACE_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
|
|
26
|
+
const GET_ALL_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all';
|
|
27
|
+
const HAS_NEW_DYNAMIC = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all/update';
|
|
26
28
|
const GET_COOKIES_INFO = 'https://passport.bilibili.com/x/passport-login/web/cookie/info';
|
|
27
29
|
const GET_USER_INFO = 'https://api.bilibili.com/x/space/wbi/acc/info';
|
|
28
30
|
const GET_MYSELF_INFO = 'https://api.bilibili.com/x/member/web/account';
|
|
@@ -32,6 +34,12 @@ const GET_LIVE_ROOM_INFO = 'https://api.live.bilibili.com/room/v1/Room/get_info'
|
|
|
32
34
|
const GET_MASTER_INFO = 'https://api.live.bilibili.com/live_user/v1/Master/info';
|
|
33
35
|
const GET_TIME_NOW = 'https://api.bilibili.com/x/report/click/now';
|
|
34
36
|
const GET_SERVER_UTC_TIME = 'https://interface.bilibili.com/serverdate.js';
|
|
37
|
+
// 操作
|
|
38
|
+
const MODIFY_RELATION = 'https://api.bilibili.com/x/relation/modify';
|
|
39
|
+
const CREATE_GROUP = 'https://api.bilibili.com/x/relation/tag/create';
|
|
40
|
+
const MODIFY_GROUP_MEMBER = 'https://api.bilibili.com/x/relation/tags/addUsers';
|
|
41
|
+
const GET_ALL_GROUP = 'https://api.bilibili.com/x/relation/tags';
|
|
42
|
+
const COPY_USER_TO_GROUP = 'https://api.bilibili.com/x/relation/tags/copyUsers';
|
|
35
43
|
class BiliAPI extends koishi_1.Service {
|
|
36
44
|
static inject = ['database', 'notifier'];
|
|
37
45
|
jar;
|
|
@@ -120,6 +128,55 @@ class BiliAPI extends koishi_1.Service {
|
|
|
120
128
|
throw new Error('网络异常,本次请求失败!');
|
|
121
129
|
}
|
|
122
130
|
}
|
|
131
|
+
async getAllGroup() {
|
|
132
|
+
try {
|
|
133
|
+
const { data } = await this.client.get(GET_ALL_GROUP);
|
|
134
|
+
return data;
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
throw new Error('网络异常,本次请求失败!');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async removeUserFromGroup(mid) {
|
|
141
|
+
// 获取csrf
|
|
142
|
+
const csrf = this.getCSRF();
|
|
143
|
+
try {
|
|
144
|
+
// 将用户mid添加到groupId
|
|
145
|
+
const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
|
|
146
|
+
fids: mid,
|
|
147
|
+
tagids: 0,
|
|
148
|
+
csrf
|
|
149
|
+
}, {
|
|
150
|
+
headers: {
|
|
151
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
throw new Error('网络异常,本次请求失败!');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async copyUserToGroup(mid, groupId) {
|
|
161
|
+
// 获取csrf
|
|
162
|
+
const csrf = this.getCSRF();
|
|
163
|
+
try {
|
|
164
|
+
// 将用户mid添加到groupId
|
|
165
|
+
const { data } = await this.client.post(COPY_USER_TO_GROUP, {
|
|
166
|
+
fids: mid,
|
|
167
|
+
tagids: groupId,
|
|
168
|
+
csrf
|
|
169
|
+
}, {
|
|
170
|
+
headers: {
|
|
171
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return data;
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
throw new Error('网络异常,本次请求失败!');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
123
180
|
async getUserSpaceDynamic(mid) {
|
|
124
181
|
try {
|
|
125
182
|
const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}?host_mid=${mid}`);
|
|
@@ -129,6 +186,60 @@ class BiliAPI extends koishi_1.Service {
|
|
|
129
186
|
throw new Error('网络异常,本次请求失败!');
|
|
130
187
|
}
|
|
131
188
|
}
|
|
189
|
+
async createGroup(tag) {
|
|
190
|
+
try {
|
|
191
|
+
const { data } = await this.client.post(CREATE_GROUP, {
|
|
192
|
+
tag,
|
|
193
|
+
csrf: this.getCSRF()
|
|
194
|
+
}, {
|
|
195
|
+
headers: {
|
|
196
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return data;
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
throw new Error('网络异常,本次请求失败!');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async getAllDynamic(updateBaseline) {
|
|
206
|
+
let url = GET_ALL_DYNAMIC_LIST;
|
|
207
|
+
updateBaseline && (url += `?update_baseline=${updateBaseline}`);
|
|
208
|
+
try {
|
|
209
|
+
const { data } = await this.client.get(url);
|
|
210
|
+
return data;
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
throw new Error('网络异常,本次请求失败!');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async hasNewDynamic(updateBaseline) {
|
|
217
|
+
try {
|
|
218
|
+
const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
|
|
219
|
+
return data;
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
throw new Error('网络异常,本次请求失败!');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async follow(fid) {
|
|
226
|
+
try {
|
|
227
|
+
const { data } = await this.client.post(MODIFY_RELATION, {
|
|
228
|
+
fid,
|
|
229
|
+
act: 1,
|
|
230
|
+
re_src: 11,
|
|
231
|
+
csrf: this.getCSRF()
|
|
232
|
+
}, {
|
|
233
|
+
headers: {
|
|
234
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
return data;
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
throw new Error('网络异常,本次请求失败!');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
132
243
|
// Check if Token need refresh
|
|
133
244
|
async getCookieInfo(refreshToken) {
|
|
134
245
|
try {
|
|
@@ -289,6 +400,10 @@ class BiliAPI extends koishi_1.Service {
|
|
|
289
400
|
};
|
|
290
401
|
}
|
|
291
402
|
}
|
|
403
|
+
getCSRF() {
|
|
404
|
+
// 获取csrf
|
|
405
|
+
return this.jar.serializeSync().cookies.find(cookie => cookie.key === 'bili_jct').value;
|
|
406
|
+
}
|
|
292
407
|
async loadCookiesFromDatabase() {
|
|
293
408
|
// Get login info from db
|
|
294
409
|
const { cookies, refresh_token } = await this.getLoginInfoFromDB();
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { Bot, Context, Logger, Schema, Session } from "koishi";
|
|
2
2
|
import { Notifier } from "@koishijs/plugin-notifier";
|
|
3
|
+
type SubItem = {
|
|
4
|
+
id: number;
|
|
5
|
+
uid: string;
|
|
6
|
+
roomId: string;
|
|
7
|
+
targetIdArr: Array<string>;
|
|
8
|
+
platform: string;
|
|
9
|
+
live: boolean;
|
|
10
|
+
dynamic: boolean;
|
|
11
|
+
liveDispose: Function;
|
|
12
|
+
};
|
|
13
|
+
type SubManager = Array<SubItem>;
|
|
3
14
|
declare class ComRegister {
|
|
4
15
|
static inject: string[];
|
|
5
16
|
logger: Logger;
|
|
@@ -8,46 +19,31 @@ declare class ComRegister {
|
|
|
8
19
|
num: number;
|
|
9
20
|
rebootCount: number;
|
|
10
21
|
subNotifier: Notifier;
|
|
11
|
-
subManager:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
targetId: string;
|
|
16
|
-
platform: string;
|
|
17
|
-
live: boolean;
|
|
18
|
-
dynamic: boolean;
|
|
19
|
-
liveDispose: Function;
|
|
20
|
-
dynamicDispose: Function;
|
|
21
|
-
}[];
|
|
22
|
-
qqBot: Bot<Context>;
|
|
23
|
-
qqguildBot: Bot<Context>;
|
|
24
|
-
oneBot: Bot<Context>;
|
|
25
|
-
redBot: Bot<Context>;
|
|
26
|
-
telegramBot: Bot<Context>;
|
|
27
|
-
satoriBot: Bot<Context>;
|
|
28
|
-
chronocatBot: Bot<Context>;
|
|
29
|
-
larkBot: Bot<Context>;
|
|
30
|
-
sendMsgFunc: (guild: string, bot: Bot<Context>, content: any) => Promise<void>;
|
|
22
|
+
subManager: SubManager;
|
|
23
|
+
bot: Bot<Context>;
|
|
24
|
+
dynamicDispose: Function;
|
|
25
|
+
sendMsgFunc: (guild: string, content: any) => Promise<void>;
|
|
31
26
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
liveDetect(ctx: Context, bot: Bot<Context>, roomId: string, guildId: Array<string>): () => Promise<void>;
|
|
27
|
+
sendPrivateMsg(content: string): Promise<void>;
|
|
28
|
+
sendPrivateMsgAndRebootService(ctx: Context): Promise<void>;
|
|
29
|
+
sendPrivateMsgAndStopService(ctx: Context): Promise<void>;
|
|
30
|
+
sendMsg(targets: Array<string>, content: any): Promise<void>;
|
|
31
|
+
dynamicDetect(ctx: Context): () => Promise<void>;
|
|
32
|
+
debug_dynamicDetect(ctx: Context): () => Promise<void>;
|
|
33
|
+
liveDetect(ctx: Context, roomId: string, guildId: Array<string>): () => Promise<void>;
|
|
40
34
|
subShow(): string;
|
|
41
|
-
checkIfNeedSub(
|
|
35
|
+
checkIfNeedSub(liveSub: boolean, dynamicSub: boolean, session: Session, data?: any): Promise<Array<boolean>>;
|
|
42
36
|
updateSubNotifier(ctx: Context): void;
|
|
43
37
|
checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
|
|
44
38
|
getSubFromDatabase(ctx: Context): Promise<void>;
|
|
45
39
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
46
|
-
|
|
40
|
+
checkIfUserThatIsSubDynAndUnsub(): void;
|
|
41
|
+
unsubAll(ctx: Context, uid: string): void;
|
|
47
42
|
checkIfIsLogin(ctx: Context): Promise<boolean>;
|
|
48
43
|
}
|
|
49
44
|
declare namespace ComRegister {
|
|
50
45
|
interface Config {
|
|
46
|
+
platform: string;
|
|
51
47
|
master: {
|
|
52
48
|
enable: boolean;
|
|
53
49
|
masterAccount: string;
|