koishi-plugin-bilibili-notify 1.2.1 → 1.2.2-beta.0
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 +2 -1
- package/lib/biliAPI.js +6 -44
- package/lib/comRegister.d.ts +2 -0
- package/lib/comRegister.js +51 -1
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ declare class BiliAPI extends Service {
|
|
|
13
13
|
loginData: any;
|
|
14
14
|
loginNotifier: Notifier;
|
|
15
15
|
refreshCookieTimer: Function;
|
|
16
|
+
loginInfoIsLoaded: boolean;
|
|
16
17
|
constructor(ctx: Context);
|
|
17
18
|
protected start(): void | Promise<void>;
|
|
18
|
-
test_refresh_token(): Promise<void>;
|
|
19
19
|
getServerUTCTime(): Promise<number>;
|
|
20
20
|
getTimeNow(): Promise<any>;
|
|
21
21
|
getUserSpaceDynamic(mid: string): Promise<any>;
|
|
@@ -30,6 +30,7 @@ declare class BiliAPI extends Service {
|
|
|
30
30
|
createNewClient(): void;
|
|
31
31
|
getTimeOfUTC8(): number;
|
|
32
32
|
getCookies(): string;
|
|
33
|
+
getLoginInfoIsLoaded(): boolean;
|
|
33
34
|
getLoginInfoFromDB(): Promise<{
|
|
34
35
|
cookies: any;
|
|
35
36
|
refresh_token: string;
|
package/lib/biliAPI.js
CHANGED
|
@@ -29,6 +29,7 @@ class BiliAPI extends koishi_1.Service {
|
|
|
29
29
|
loginData;
|
|
30
30
|
loginNotifier;
|
|
31
31
|
refreshCookieTimer;
|
|
32
|
+
loginInfoIsLoaded = false;
|
|
32
33
|
constructor(ctx) {
|
|
33
34
|
super(ctx, 'biliAPI');
|
|
34
35
|
}
|
|
@@ -39,50 +40,6 @@ class BiliAPI extends koishi_1.Service {
|
|
|
39
40
|
this.loadCookiesFromDatabase();
|
|
40
41
|
// this.logger.info('BiliAPI已被注册到Context中')
|
|
41
42
|
}
|
|
42
|
-
async test_refresh_token() {
|
|
43
|
-
const publicKey = await crypto.subtle.importKey("jwk", {
|
|
44
|
-
kty: "RSA",
|
|
45
|
-
n: "y4HdjgJHBlbaBN04VERG4qNBIFHP6a3GozCl75AihQloSWCXC5HDNgyinEnhaQ_4-gaMud_GF50elYXLlCToR9se9Z8z433U3KjM-3Yx7ptKkmQNAMggQwAVKgq3zYAoidNEWuxpkY_mAitTSRLnsJW-NCTa0bqBFF6Wm1MxgfE",
|
|
46
|
-
e: "AQAB",
|
|
47
|
-
}, { name: "RSA-OAEP", hash: "SHA-256" }, true, ["encrypt"]);
|
|
48
|
-
async function getCorrespondPath(timestamp) {
|
|
49
|
-
const data = new TextEncoder().encode(`refresh_${timestamp}`);
|
|
50
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
|
|
51
|
-
return encrypted.reduce((str, c) => str + c.toString(16).padStart(2, "0"), "");
|
|
52
|
-
}
|
|
53
|
-
const ts = Date.now();
|
|
54
|
-
const correspondPath = await getCorrespondPath(ts);
|
|
55
|
-
const { data } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
|
|
56
|
-
// 创建一个虚拟的DOM元素
|
|
57
|
-
const { document } = new jsdom_1.JSDOM(data).window;
|
|
58
|
-
// 提取标签name为1-name的内容
|
|
59
|
-
const targetElement = document.getElementById('1-name');
|
|
60
|
-
const refresh_csrf = targetElement ? targetElement.textContent : null;
|
|
61
|
-
// 获取csrf
|
|
62
|
-
let csrf;
|
|
63
|
-
const cookies = JSON.parse(this.getCookies());
|
|
64
|
-
cookies.forEach(cookie => {
|
|
65
|
-
if (cookie.key === 'bili_jct')
|
|
66
|
-
csrf = cookie.value;
|
|
67
|
-
});
|
|
68
|
-
// 读取数据库获取cookies
|
|
69
|
-
const database = (await this.ctx.database.get('loginBili', 1))[0];
|
|
70
|
-
// 获取refreshToken
|
|
71
|
-
const refresh_token = this.ctx.wbi.decrypt(database.bili_refresh_token);
|
|
72
|
-
// 发送请求
|
|
73
|
-
// const { data: refreshData } = await this.client.post(`https://passport.bilibili.com/x/passport-login/web/cookie/refresh?csrf=${csrf}&refresh_csrf=${refresh_csrf}&source=main_web&refresh_token=${refresh_token}`)
|
|
74
|
-
const { data: refreshData } = await this.client.post('https://passport.bilibili.com/x/passport-login/web/cookie/refresh', {
|
|
75
|
-
csrf,
|
|
76
|
-
refresh_csrf,
|
|
77
|
-
source: 'main_web',
|
|
78
|
-
refresh_token
|
|
79
|
-
}, {
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
console.log(refreshData);
|
|
85
|
-
}
|
|
86
43
|
async getServerUTCTime() {
|
|
87
44
|
try {
|
|
88
45
|
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
|
@@ -209,6 +166,9 @@ class BiliAPI extends koishi_1.Service {
|
|
|
209
166
|
cookies = JSON.stringify(this.jar.serializeSync().cookies);
|
|
210
167
|
return cookies;
|
|
211
168
|
}
|
|
169
|
+
getLoginInfoIsLoaded() {
|
|
170
|
+
return this.loginInfoIsLoaded;
|
|
171
|
+
}
|
|
212
172
|
async getLoginInfoFromDB() {
|
|
213
173
|
// 读取数据库获取cookies
|
|
214
174
|
const data = (await this.ctx.database.get('loginBili', 1))[0];
|
|
@@ -273,6 +233,8 @@ class BiliAPI extends koishi_1.Service {
|
|
|
273
233
|
});
|
|
274
234
|
this.jar.setCookieSync(cookie, `http${cookie.secure ? 's' : ''}://${cookie.domain}${cookie.path}`, {});
|
|
275
235
|
});
|
|
236
|
+
// Login info is loaded
|
|
237
|
+
this.loginInfoIsLoaded = true;
|
|
276
238
|
// restart plugin check
|
|
277
239
|
this.checkIfTokenNeedRefresh(refresh_token, csrf);
|
|
278
240
|
// enable refresh cookies detect
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare class ComRegister {
|
|
|
24
24
|
redBot: Bot<Context>;
|
|
25
25
|
telegramBot: Bot<Context>;
|
|
26
26
|
satoriBot: Bot<Context>;
|
|
27
|
+
chronocatBot: Bot<Context>;
|
|
27
28
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
28
29
|
dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
|
|
29
30
|
sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
|
|
@@ -31,6 +32,7 @@ declare class ComRegister {
|
|
|
31
32
|
subShow(): string;
|
|
32
33
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
|
33
34
|
updateSubNotifier(ctx: Context): void;
|
|
35
|
+
checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
|
|
34
36
|
getSubFromDatabase(ctx: Context): Promise<void>;
|
|
35
37
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
36
38
|
checkIfIsLogin(ctx: Context): Promise<boolean>;
|
package/lib/comRegister.js
CHANGED
|
@@ -33,6 +33,8 @@ class ComRegister {
|
|
|
33
33
|
telegramBot;
|
|
34
34
|
// Satori机器人
|
|
35
35
|
satoriBot;
|
|
36
|
+
// Chronocat机器人
|
|
37
|
+
chronocatBot;
|
|
36
38
|
constructor(ctx, config) {
|
|
37
39
|
this.logger = ctx.logger('commandRegister');
|
|
38
40
|
this.config = config;
|
|
@@ -57,6 +59,9 @@ class ComRegister {
|
|
|
57
59
|
case 'satori':
|
|
58
60
|
this.satoriBot = bot;
|
|
59
61
|
break;
|
|
62
|
+
case 'chronocat':
|
|
63
|
+
this.chronocatBot = bot;
|
|
64
|
+
break;
|
|
60
65
|
}
|
|
61
66
|
});
|
|
62
67
|
// 从数据库获取订阅
|
|
@@ -311,6 +316,7 @@ class ComRegister {
|
|
|
311
316
|
case 'onebot':
|
|
312
317
|
case 'telegram':
|
|
313
318
|
case 'satori':
|
|
319
|
+
case 'chronocat':
|
|
314
320
|
case 'qq':
|
|
315
321
|
case 'qqguild': break;
|
|
316
322
|
default: return '暂不支持该平台';
|
|
@@ -404,6 +410,10 @@ class ComRegister {
|
|
|
404
410
|
okGuild = await checkIfGuildHasJoined(this.satoriBot);
|
|
405
411
|
break;
|
|
406
412
|
}
|
|
413
|
+
case 'chronocat': {
|
|
414
|
+
okGuild = await checkIfGuildHasJoined(this.chronocatBot);
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
407
417
|
default: {
|
|
408
418
|
// 发送错误提示并返回
|
|
409
419
|
session.send('您尚未配置任何QQ群相关机器人,不能对QQ群进行操作');
|
|
@@ -517,6 +527,9 @@ class ComRegister {
|
|
|
517
527
|
case 'satori':
|
|
518
528
|
bot = this.satoriBot;
|
|
519
529
|
break;
|
|
530
|
+
case 'chronocat':
|
|
531
|
+
bot = this.chronocatBot;
|
|
532
|
+
break;
|
|
520
533
|
default: {
|
|
521
534
|
this.logger.warn(`${uid}非法调用 dynamic 指令,不支持该平台`);
|
|
522
535
|
return '非法调用';
|
|
@@ -563,6 +576,9 @@ class ComRegister {
|
|
|
563
576
|
case 'satori':
|
|
564
577
|
bot = this.satoriBot;
|
|
565
578
|
break;
|
|
579
|
+
case 'chronocat':
|
|
580
|
+
bot = this.chronocatBot;
|
|
581
|
+
break;
|
|
566
582
|
default: {
|
|
567
583
|
this.logger.warn(`${roomId}非法调用 dynamic 指令,不支持该平台`);
|
|
568
584
|
return `${roomId}非法调用 dynamic 指令`;
|
|
@@ -616,6 +632,19 @@ class ComRegister {
|
|
|
616
632
|
// pic不存在,说明使用的是page模式
|
|
617
633
|
await session.send(koishi_1.h.image(buffer, 'image/png'));
|
|
618
634
|
});
|
|
635
|
+
biliCom
|
|
636
|
+
.subcommand('.bot', '查询当前拥有的机器人信息', { hidden: true })
|
|
637
|
+
.usage('查询当前拥有的机器人信息')
|
|
638
|
+
.example('bili bot 查询当前拥有的机器人信息')
|
|
639
|
+
.action(() => {
|
|
640
|
+
this.logger.info('开始输出BOT信息');
|
|
641
|
+
ctx.bots.forEach(bot => {
|
|
642
|
+
this.logger.info('--------------------------------');
|
|
643
|
+
this.logger.info('平台:' + bot.platform);
|
|
644
|
+
this.logger.info('名称:' + bot.user.name);
|
|
645
|
+
this.logger.info('--------------------------------');
|
|
646
|
+
});
|
|
647
|
+
});
|
|
619
648
|
}
|
|
620
649
|
dynamicDetect(ctx, bot, uid, guildId) {
|
|
621
650
|
let firstSubscription = true;
|
|
@@ -966,11 +995,29 @@ class ComRegister {
|
|
|
966
995
|
// 设置更新后的提示
|
|
967
996
|
this.subNotifier = ctx.notifier.create(table);
|
|
968
997
|
}
|
|
998
|
+
async checkIfLoginInfoIsLoaded(ctx) {
|
|
999
|
+
return new Promise(resolve => {
|
|
1000
|
+
const check = () => {
|
|
1001
|
+
if (!ctx.biliAPI.getLoginInfoIsLoaded()) {
|
|
1002
|
+
ctx.setTimeout(check, 500);
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
resolve('success');
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
check();
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
969
1011
|
async getSubFromDatabase(ctx) {
|
|
970
1012
|
this.logger.info('开始执行数据库读取操作');
|
|
1013
|
+
// 判断登录信息是否已加载完毕
|
|
1014
|
+
await this.checkIfLoginInfoIsLoaded(ctx);
|
|
971
1015
|
// 如果未登录,则直接返回
|
|
972
|
-
if (!(await this.checkIfIsLogin(ctx)))
|
|
1016
|
+
if (!(await this.checkIfIsLogin(ctx))) {
|
|
1017
|
+
// log
|
|
1018
|
+
this.logger.info(`账号未登录,请登录`);
|
|
973
1019
|
return;
|
|
1020
|
+
}
|
|
974
1021
|
this.logger.info('已登录账号');
|
|
975
1022
|
// 已存在订阅管理对象,不再进行订阅操作
|
|
976
1023
|
if (this.subManager.length !== 0)
|
|
@@ -1024,6 +1071,9 @@ class ComRegister {
|
|
|
1024
1071
|
case 'satori':
|
|
1025
1072
|
bot = this.satoriBot;
|
|
1026
1073
|
break;
|
|
1074
|
+
case 'chronocat':
|
|
1075
|
+
bot = this.chronocatBot;
|
|
1076
|
+
break;
|
|
1027
1077
|
default: {
|
|
1028
1078
|
// 本条数据被篡改,删除该条订阅
|
|
1029
1079
|
ctx.database.remove('bilibili', { id: sub.id });
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -115,6 +115,8 @@
|
|
|
115
115
|
- ver 1.2.0-rc.5 屏蔽动态设置新增是否发送动态被屏蔽消息的选项
|
|
116
116
|
- ver 1.2.0 添加屏蔽转发动态功能,添加发送动态卡片时附带文本信息和动态链接功能,支持订阅哔哩哔哩番剧出差
|
|
117
117
|
- ver 1.2.1 现已支持Satori平台(实验性)
|
|
118
|
+
- ver 1.2.2-alpha.0 bug测试
|
|
119
|
+
- ver 1.2.2-beta.0 修复重启koishi后,提示没有任何订阅的bug,新增对chronocat的支持(实验性)
|
|
118
120
|
|
|
119
121
|
## 交流群
|
|
120
122
|
801338523 使用问题或bug都可以在群里提出
|