koishi-plugin-bilibili-notify 1.2.0 → 1.2.2-alpha.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 +0 -1
- package/lib/biliAPI.js +0 -44
- package/lib/comRegister.d.ts +1 -0
- package/lib/comRegister.js +54 -2
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ declare class BiliAPI extends Service {
|
|
|
15
15
|
refreshCookieTimer: Function;
|
|
16
16
|
constructor(ctx: Context);
|
|
17
17
|
protected start(): void | Promise<void>;
|
|
18
|
-
test_refresh_token(): Promise<void>;
|
|
19
18
|
getServerUTCTime(): Promise<number>;
|
|
20
19
|
getTimeNow(): Promise<any>;
|
|
21
20
|
getUserSpaceDynamic(mid: string): Promise<any>;
|
package/lib/biliAPI.js
CHANGED
|
@@ -39,50 +39,6 @@ class BiliAPI extends koishi_1.Service {
|
|
|
39
39
|
this.loadCookiesFromDatabase();
|
|
40
40
|
// this.logger.info('BiliAPI已被注册到Context中')
|
|
41
41
|
}
|
|
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
42
|
async getServerUTCTime() {
|
|
87
43
|
try {
|
|
88
44
|
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare class ComRegister {
|
|
|
23
23
|
oneBot: Bot<Context>;
|
|
24
24
|
redBot: Bot<Context>;
|
|
25
25
|
telegramBot: Bot<Context>;
|
|
26
|
+
satoriBot: Bot<Context>;
|
|
26
27
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
27
28
|
dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
|
|
28
29
|
sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
|
package/lib/comRegister.js
CHANGED
|
@@ -31,6 +31,8 @@ class ComRegister {
|
|
|
31
31
|
redBot;
|
|
32
32
|
// Telegram机器人
|
|
33
33
|
telegramBot;
|
|
34
|
+
// Satori机器人
|
|
35
|
+
satoriBot;
|
|
34
36
|
constructor(ctx, config) {
|
|
35
37
|
this.logger = ctx.logger('commandRegister');
|
|
36
38
|
this.config = config;
|
|
@@ -52,6 +54,9 @@ class ComRegister {
|
|
|
52
54
|
case 'telegram':
|
|
53
55
|
this.telegramBot = bot;
|
|
54
56
|
break;
|
|
57
|
+
case 'satori':
|
|
58
|
+
this.satoriBot = bot;
|
|
59
|
+
break;
|
|
55
60
|
}
|
|
56
61
|
});
|
|
57
62
|
// 从数据库获取订阅
|
|
@@ -305,6 +310,7 @@ class ComRegister {
|
|
|
305
310
|
case 'red':
|
|
306
311
|
case 'onebot':
|
|
307
312
|
case 'telegram':
|
|
313
|
+
case 'satori':
|
|
308
314
|
case 'qq':
|
|
309
315
|
case 'qqguild': break;
|
|
310
316
|
default: return '暂不支持该平台';
|
|
@@ -394,6 +400,10 @@ class ComRegister {
|
|
|
394
400
|
okGuild = await checkIfGuildHasJoined(this.redBot);
|
|
395
401
|
break;
|
|
396
402
|
}
|
|
403
|
+
case 'satori': {
|
|
404
|
+
okGuild = await checkIfGuildHasJoined(this.satoriBot);
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
397
407
|
default: {
|
|
398
408
|
// 发送错误提示并返回
|
|
399
409
|
session.send('您尚未配置任何QQ群相关机器人,不能对QQ群进行操作');
|
|
@@ -504,6 +514,9 @@ class ComRegister {
|
|
|
504
514
|
case 'telegram':
|
|
505
515
|
bot = this.telegramBot;
|
|
506
516
|
break;
|
|
517
|
+
case 'satori':
|
|
518
|
+
bot = this.satoriBot;
|
|
519
|
+
break;
|
|
507
520
|
default: {
|
|
508
521
|
this.logger.warn(`${uid}非法调用 dynamic 指令,不支持该平台`);
|
|
509
522
|
return '非法调用';
|
|
@@ -547,6 +560,9 @@ class ComRegister {
|
|
|
547
560
|
case 'telegram':
|
|
548
561
|
bot = this.telegramBot;
|
|
549
562
|
break;
|
|
563
|
+
case 'satori':
|
|
564
|
+
bot = this.satoriBot;
|
|
565
|
+
break;
|
|
550
566
|
default: {
|
|
551
567
|
this.logger.warn(`${roomId}非法调用 dynamic 指令,不支持该平台`);
|
|
552
568
|
return `${roomId}非法调用 dynamic 指令`;
|
|
@@ -951,14 +967,23 @@ class ComRegister {
|
|
|
951
967
|
this.subNotifier = ctx.notifier.create(table);
|
|
952
968
|
}
|
|
953
969
|
async getSubFromDatabase(ctx) {
|
|
970
|
+
this.logger.info('开始执行数据库读取操作');
|
|
971
|
+
// 检查登录状态
|
|
972
|
+
const isLogin = await this.checkIfIsLogin(ctx);
|
|
973
|
+
// log
|
|
974
|
+
this.logger.info(`登录状态:${isLogin}`);
|
|
954
975
|
// 如果未登录,则直接返回
|
|
955
976
|
if (!(await this.checkIfIsLogin(ctx)))
|
|
956
977
|
return;
|
|
978
|
+
this.logger.info('已登录账号');
|
|
957
979
|
// 已存在订阅管理对象,不再进行订阅操作
|
|
958
980
|
if (this.subManager.length !== 0)
|
|
959
981
|
return;
|
|
982
|
+
this.logger.info('不存在订阅管理对象');
|
|
960
983
|
// 从数据库中获取数据
|
|
961
984
|
const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
|
|
985
|
+
this.logger.info('已从数据库获取到数据,数据为:');
|
|
986
|
+
this.logger.info(subData);
|
|
962
987
|
// 设定订阅数量
|
|
963
988
|
this.num = subData.length;
|
|
964
989
|
// 如果订阅数量超过三个则数据库被非法修改
|
|
@@ -978,6 +1003,8 @@ class ComRegister {
|
|
|
978
1003
|
if (!sub.dynamic && !sub.live) { // 存在未订阅任何项目的数据
|
|
979
1004
|
// 删除该条数据
|
|
980
1005
|
ctx.database.remove('bilibili', { id: sub.id });
|
|
1006
|
+
// log
|
|
1007
|
+
this.logger.warn(`UID:${sub.uid} 该条数据没有任何订阅数据,自动取消订阅`);
|
|
981
1008
|
// 跳过下面的步骤
|
|
982
1009
|
continue;
|
|
983
1010
|
}
|
|
@@ -998,9 +1025,14 @@ class ComRegister {
|
|
|
998
1025
|
case 'telegram':
|
|
999
1026
|
bot = this.telegramBot;
|
|
1000
1027
|
break;
|
|
1028
|
+
case 'satori':
|
|
1029
|
+
bot = this.satoriBot;
|
|
1030
|
+
break;
|
|
1001
1031
|
default: {
|
|
1002
1032
|
// 本条数据被篡改,删除该条订阅
|
|
1003
1033
|
ctx.database.remove('bilibili', { id: sub.id });
|
|
1034
|
+
// 不支持的协议
|
|
1035
|
+
this.logger.info(`UID:${sub.uid} 出现不支持的协议,该条数据被篡改,自动取消订阅`);
|
|
1004
1036
|
// 继续下个循环
|
|
1005
1037
|
continue;
|
|
1006
1038
|
}
|
|
@@ -1013,7 +1045,10 @@ class ComRegister {
|
|
|
1013
1045
|
let attempts = 3;
|
|
1014
1046
|
for (let i = 0; i < attempts; i++) {
|
|
1015
1047
|
try {
|
|
1048
|
+
// 获取用户信息
|
|
1016
1049
|
content = await ctx.biliAPI.getUserInfo(sub.uid);
|
|
1050
|
+
// log
|
|
1051
|
+
this.logger.info(`UID:${sub.uid} 获取到用户信息`);
|
|
1017
1052
|
// 成功则跳出循环
|
|
1018
1053
|
break;
|
|
1019
1054
|
}
|
|
@@ -1043,17 +1078,24 @@ class ComRegister {
|
|
|
1043
1078
|
}
|
|
1044
1079
|
case -400:
|
|
1045
1080
|
case -404:
|
|
1046
|
-
default:
|
|
1081
|
+
default: {
|
|
1047
1082
|
await deleteSub();
|
|
1083
|
+
// log
|
|
1084
|
+
this.logger.info(`UID:${sub.uid} 数据出现问题,自动取消订阅`);
|
|
1048
1085
|
return;
|
|
1086
|
+
}
|
|
1049
1087
|
}
|
|
1050
1088
|
}
|
|
1051
1089
|
// 检测房间号是否被篡改
|
|
1052
1090
|
if (sub.live && (!data.live_room || data.live_room.roomid.toString() !== sub.room_id)) {
|
|
1053
1091
|
// 房间号被篡改,删除该订阅
|
|
1054
1092
|
await deleteSub();
|
|
1093
|
+
// log
|
|
1094
|
+
this.logger.info(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
1055
1095
|
return;
|
|
1056
1096
|
}
|
|
1097
|
+
// log
|
|
1098
|
+
this.logger.info(`UID:${sub.uid} 开始构建订阅对象`);
|
|
1057
1099
|
// 构建订阅对象
|
|
1058
1100
|
let subManagerItem = {
|
|
1059
1101
|
id: sub.id,
|
|
@@ -1066,24 +1108,34 @@ class ComRegister {
|
|
|
1066
1108
|
liveDispose: null,
|
|
1067
1109
|
dynamicDispose: null
|
|
1068
1110
|
};
|
|
1111
|
+
// log
|
|
1112
|
+
this.logger.info(`UID:${sub.uid} 订阅对象构建成功,开始进行订阅操作`);
|
|
1069
1113
|
// 判断需要订阅的服务
|
|
1070
1114
|
if (sub.dynamic) { // 需要订阅动态
|
|
1071
1115
|
// 开始循环检测
|
|
1072
1116
|
const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, sub.uid, targetArr), this.config.dynamicLoopTime * 1000);
|
|
1073
1117
|
// 保存销毁函数
|
|
1074
1118
|
subManagerItem.dynamicDispose = dispose;
|
|
1119
|
+
// log
|
|
1120
|
+
this.logger.info(`UID:${sub.uid} 成功订阅动态`);
|
|
1075
1121
|
}
|
|
1076
|
-
if (sub.live) { //
|
|
1122
|
+
if (sub.live) { // 需要订阅直播
|
|
1077
1123
|
// 开始循环检测
|
|
1078
1124
|
const dispose = ctx.setInterval(this.liveDetect(ctx, bot, sub.room_id, targetArr), this.config.liveLoopTime * 1000);
|
|
1079
1125
|
// 保存销毁函数
|
|
1080
1126
|
subManagerItem.liveDispose = dispose;
|
|
1127
|
+
// log
|
|
1128
|
+
this.logger.info(`UID:${sub.uid} 成功订阅直播`);
|
|
1081
1129
|
}
|
|
1082
1130
|
// 保存新订阅对象
|
|
1083
1131
|
this.subManager.push(subManagerItem);
|
|
1132
|
+
// log
|
|
1133
|
+
this.logger.info(`UID:${sub.uid} 成功保存订阅对象`);
|
|
1084
1134
|
}
|
|
1085
1135
|
// 在控制台中显示订阅对象
|
|
1086
1136
|
this.updateSubNotifier(ctx);
|
|
1137
|
+
// log
|
|
1138
|
+
this.logger.info(`数据库读取操作已完成`);
|
|
1087
1139
|
}
|
|
1088
1140
|
unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
|
|
1089
1141
|
let index;
|
package/package.json
CHANGED
package/readme.md
CHANGED