koishi-plugin-bilibili-notify 1.2.2-alpha.0 → 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 -0
- package/lib/biliAPI.js +6 -0
- package/lib/comRegister.d.ts +2 -0
- package/lib/comRegister.js +51 -5
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ 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
19
|
getServerUTCTime(): Promise<number>;
|
|
@@ -29,6 +30,7 @@ declare class BiliAPI extends Service {
|
|
|
29
30
|
createNewClient(): void;
|
|
30
31
|
getTimeOfUTC8(): number;
|
|
31
32
|
getCookies(): string;
|
|
33
|
+
getLoginInfoIsLoaded(): boolean;
|
|
32
34
|
getLoginInfoFromDB(): Promise<{
|
|
33
35
|
cookies: any;
|
|
34
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
|
}
|
|
@@ -165,6 +166,9 @@ class BiliAPI extends koishi_1.Service {
|
|
|
165
166
|
cookies = JSON.stringify(this.jar.serializeSync().cookies);
|
|
166
167
|
return cookies;
|
|
167
168
|
}
|
|
169
|
+
getLoginInfoIsLoaded() {
|
|
170
|
+
return this.loginInfoIsLoaded;
|
|
171
|
+
}
|
|
168
172
|
async getLoginInfoFromDB() {
|
|
169
173
|
// 读取数据库获取cookies
|
|
170
174
|
const data = (await this.ctx.database.get('loginBili', 1))[0];
|
|
@@ -229,6 +233,8 @@ class BiliAPI extends koishi_1.Service {
|
|
|
229
233
|
});
|
|
230
234
|
this.jar.setCookieSync(cookie, `http${cookie.secure ? 's' : ''}://${cookie.domain}${cookie.path}`, {});
|
|
231
235
|
});
|
|
236
|
+
// Login info is loaded
|
|
237
|
+
this.loginInfoIsLoaded = true;
|
|
232
238
|
// restart plugin check
|
|
233
239
|
this.checkIfTokenNeedRefresh(refresh_token, csrf);
|
|
234
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,15 +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('开始执行数据库读取操作');
|
|
971
|
-
//
|
|
972
|
-
|
|
973
|
-
// log
|
|
974
|
-
this.logger.info(`登录状态:${isLogin}`);
|
|
1013
|
+
// 判断登录信息是否已加载完毕
|
|
1014
|
+
await this.checkIfLoginInfoIsLoaded(ctx);
|
|
975
1015
|
// 如果未登录,则直接返回
|
|
976
|
-
if (!(await this.checkIfIsLogin(ctx)))
|
|
1016
|
+
if (!(await this.checkIfIsLogin(ctx))) {
|
|
1017
|
+
// log
|
|
1018
|
+
this.logger.info(`账号未登录,请登录`);
|
|
977
1019
|
return;
|
|
1020
|
+
}
|
|
978
1021
|
this.logger.info('已登录账号');
|
|
979
1022
|
// 已存在订阅管理对象,不再进行订阅操作
|
|
980
1023
|
if (this.subManager.length !== 0)
|
|
@@ -1028,6 +1071,9 @@ class ComRegister {
|
|
|
1028
1071
|
case 'satori':
|
|
1029
1072
|
bot = this.satoriBot;
|
|
1030
1073
|
break;
|
|
1074
|
+
case 'chronocat':
|
|
1075
|
+
bot = this.chronocatBot;
|
|
1076
|
+
break;
|
|
1031
1077
|
default: {
|
|
1032
1078
|
// 本条数据被篡改,删除该条订阅
|
|
1033
1079
|
ctx.database.remove('bilibili', { id: sub.id });
|
package/package.json
CHANGED
package/readme.md
CHANGED