koishi-plugin-bilibili-notify 1.0.0-beta.1 → 1.0.0-rc.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.js +5 -2
- package/lib/comRegister.d.ts +1 -1
- package/lib/comRegister.js +46 -30
- package/lib/index.js +3 -4
- package/package.json +1 -1
package/lib/biliAPI.js
CHANGED
|
@@ -222,10 +222,13 @@ class BiliAPI extends koishi_1.Service {
|
|
|
222
222
|
throw new Error('refresh_csrf 错误或 refresh_token 与 cookie 不匹配');
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
// 更新refresh_token
|
|
225
|
+
// 更新 新的cookies和refresh_token
|
|
226
|
+
const encryptedCookies = this.ctx.wbi.encrypt(this.ctx.biliAPI.getCookies());
|
|
227
|
+
const encryptedRefreshToken = this.ctx.wbi.encrypt(refreshData.data.refresh_token);
|
|
226
228
|
await this.ctx.database.upsert('loginBili', [{
|
|
227
229
|
id: 1,
|
|
228
|
-
|
|
230
|
+
bili_cookies: encryptedCookies,
|
|
231
|
+
bili_refresh_token: encryptedRefreshToken
|
|
229
232
|
}]);
|
|
230
233
|
// Get new csrf from cookies
|
|
231
234
|
let newCsrf;
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare class ComRegister {
|
|
|
18
18
|
qqguildBot: Bot<Context>;
|
|
19
19
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
20
20
|
dynamicDetect(ctx: Context, bot: Bot<Context>, guildId: string, uid: string): () => Promise<void>;
|
|
21
|
-
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<
|
|
21
|
+
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<void>;
|
|
22
22
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
|
23
23
|
getSubFromDatabase(ctx: Context): Promise<void>;
|
|
24
24
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
package/lib/comRegister.js
CHANGED
|
@@ -29,76 +29,85 @@ class ComRegister {
|
|
|
29
29
|
this.qqBot = ctx.bots[ctx.bots.findIndex(bot => bot.platform === 'qq')];
|
|
30
30
|
// 拿到QQ频道机器人
|
|
31
31
|
this.qqguildBot = ctx.bots[ctx.bots.findIndex(bot => bot.platform === 'qqguild')];
|
|
32
|
+
// 从数据库获取订阅
|
|
32
33
|
this.getSubFromDatabase(ctx);
|
|
33
|
-
ctx.command('test', { hidden: true, permissions: ['authority:5'] })
|
|
34
|
+
/* ctx.command('test', { hidden: true, permissions: ['authority:5'] })
|
|
34
35
|
.subcommand('.cookies')
|
|
35
36
|
.usage('测试指令,用于测试从数据库读取cookies')
|
|
36
37
|
.action(async () => {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
await ctx.biliAPI.loadCookiesFromDatabase()
|
|
39
|
+
})
|
|
40
|
+
|
|
39
41
|
ctx.command('test')
|
|
40
42
|
.subcommand('.my')
|
|
41
43
|
.usage('测试指令,用于测试获取自己信息')
|
|
42
44
|
.example('test.my')
|
|
43
45
|
.action(async () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const content = await ctx.biliAPI.getMyselfInfo()
|
|
47
|
+
console.log(content);
|
|
48
|
+
})
|
|
49
|
+
|
|
47
50
|
ctx.command('test')
|
|
48
51
|
.subcommand('.user <mid:string>')
|
|
49
52
|
.usage('测试指令,用于测试获取用户信息')
|
|
50
53
|
.example('test.user 用户UID')
|
|
51
54
|
.action(async (_, mid) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const content = await ctx.biliAPI.getUserInfo(mid)
|
|
56
|
+
console.log(content);
|
|
57
|
+
})
|
|
58
|
+
|
|
55
59
|
ctx.command('test')
|
|
56
60
|
.subcommand('.time')
|
|
57
61
|
.usage('测试时间接口')
|
|
58
62
|
.example('test.time')
|
|
59
63
|
.action(async () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
const content = await ctx.biliAPI.getTimeNow()
|
|
65
|
+
console.log(content);
|
|
66
|
+
})
|
|
67
|
+
|
|
63
68
|
ctx.command('test')
|
|
64
69
|
.subcommand('.exist')
|
|
65
70
|
.usage('测试写法')
|
|
66
71
|
.example('test.exist')
|
|
67
72
|
.action(async () => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
let num = 1;
|
|
74
|
+
console.log(num && `Hello World`);
|
|
75
|
+
})
|
|
76
|
+
|
|
71
77
|
ctx.command('test')
|
|
72
78
|
.subcommand('.gimg <uid:string> <index:number>')
|
|
73
79
|
.usage('测试图片生成')
|
|
74
80
|
.example('test.gimg')
|
|
75
81
|
.action(async (_, uid, index) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
// 获取用户空间动态数据
|
|
83
|
+
const { data } = await ctx.biliAPI.getUserSpaceDynamic(uid)
|
|
84
|
+
const [pic] = await ctx.gimg.generateDynamicImg(data.items[index])
|
|
85
|
+
return pic
|
|
86
|
+
})
|
|
87
|
+
|
|
81
88
|
ctx.command('test')
|
|
82
89
|
.subcommand('.group')
|
|
83
90
|
.usage('查看session groupId')
|
|
84
91
|
.example('test group')
|
|
85
92
|
.action(({ session }) => {
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
console.log(session.event.channel);
|
|
94
|
+
})
|
|
95
|
+
|
|
88
96
|
ctx.command('test')
|
|
89
97
|
.subcommand('.session')
|
|
90
98
|
.usage('查看seesion')
|
|
91
99
|
.example('test session')
|
|
92
100
|
.action(({ session }) => {
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
console.log(session);
|
|
102
|
+
})
|
|
103
|
+
|
|
95
104
|
ctx.command('test')
|
|
96
105
|
.subcommand('.dynamic <uid:string>')
|
|
97
106
|
.usage('测试动态监测')
|
|
98
107
|
.example('test dynamic uid')
|
|
99
108
|
.action(({ session }, uid) => {
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
ctx.setInterval(this.test_dynamicDetect(ctx, session, uid), 30000)
|
|
110
|
+
}) */
|
|
102
111
|
ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] })
|
|
103
112
|
.subcommand('.login', '登录B站之后才可以进行之后的操作')
|
|
104
113
|
.usage('使用二维码登录,登录B站之后才可以进行之后的操作')
|
|
@@ -154,7 +163,7 @@ class ComRegister {
|
|
|
154
163
|
return await session.send('二维码已失效,请重新登录!');
|
|
155
164
|
}
|
|
156
165
|
if (loginContent.data.code === 0) { // 登录成功
|
|
157
|
-
const encryptedCookies = ctx.wbi.encrypt(
|
|
166
|
+
const encryptedCookies = ctx.wbi.encrypt(ctx.biliAPI.getCookies());
|
|
158
167
|
const encryptedRefreshToken = ctx.wbi.encrypt(loginContent.data.refresh_token);
|
|
159
168
|
await ctx.database.upsert('loginBili', [{
|
|
160
169
|
id: 1,
|
|
@@ -573,9 +582,12 @@ class ComRegister {
|
|
|
573
582
|
let flag = true;
|
|
574
583
|
return async () => {
|
|
575
584
|
try {
|
|
585
|
+
// console.log('start before' + ' ' + flag);
|
|
576
586
|
// 如果flag为false则说明前面的代码还未执行完,则直接返回
|
|
577
587
|
if (!flag)
|
|
578
|
-
return
|
|
588
|
+
return;
|
|
589
|
+
flag && (flag = false);
|
|
590
|
+
// console.log('start after' + ' ' + flag);
|
|
579
591
|
// 发送请求检测直播状态
|
|
580
592
|
let content;
|
|
581
593
|
try {
|
|
@@ -612,6 +624,8 @@ class ComRegister {
|
|
|
612
624
|
uData = userData;
|
|
613
625
|
// 判断直播状态
|
|
614
626
|
if (data.live_status === 1) { // 当前正在直播
|
|
627
|
+
// 设置开播时间
|
|
628
|
+
liveTime = data.live_time;
|
|
615
629
|
// 推送直播信息
|
|
616
630
|
await bot.sendMessage(guildId, await ctx
|
|
617
631
|
.gimg
|
|
@@ -660,7 +674,7 @@ class ComRegister {
|
|
|
660
674
|
if (this.config.pushTime > 0) {
|
|
661
675
|
timer++;
|
|
662
676
|
// 开始记录时间
|
|
663
|
-
if (timer >= (
|
|
677
|
+
if (timer >= (6 * 60 * this.config.pushTime)) { // 到时间推送直播消息
|
|
664
678
|
// 到时间重新计时
|
|
665
679
|
timer = 0;
|
|
666
680
|
// 发送状态信息
|
|
@@ -675,8 +689,10 @@ class ComRegister {
|
|
|
675
689
|
}
|
|
676
690
|
}
|
|
677
691
|
finally {
|
|
692
|
+
// console.log('end before' + ' ' + flag);
|
|
678
693
|
// 执行完方法体不论如何都把flag设置为true
|
|
679
694
|
flag = true;
|
|
695
|
+
// console.log('end after' + ' ' + flag);
|
|
680
696
|
}
|
|
681
697
|
};
|
|
682
698
|
}
|
|
@@ -908,7 +924,7 @@ class ComRegister {
|
|
|
908
924
|
ComRegister.Config = koishi_1.Schema.object({
|
|
909
925
|
pushTime: koishi_1.Schema.number().required(),
|
|
910
926
|
liveLoopTime: koishi_1.Schema.number().default(10),
|
|
911
|
-
dynamicLoopTime: koishi_1.Schema.number().default(
|
|
927
|
+
dynamicLoopTime: koishi_1.Schema.number().default(60)
|
|
912
928
|
});
|
|
913
929
|
})(ComRegister || (ComRegister = {}));
|
|
914
930
|
exports.default = ComRegister;
|
package/lib/index.js
CHANGED
|
@@ -42,11 +42,10 @@ exports.name = 'bilibili-notify';
|
|
|
42
42
|
exports.Config = koishi_1.Schema.object({
|
|
43
43
|
pushTime: koishi_1.Schema.number()
|
|
44
44
|
.min(0)
|
|
45
|
-
.max(
|
|
46
|
-
.step(
|
|
47
|
-
.role('slider')
|
|
45
|
+
.max(12)
|
|
46
|
+
.step(0.5)
|
|
48
47
|
.default(1)
|
|
49
|
-
.description('
|
|
48
|
+
.description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
|
|
50
49
|
cardColorStart: koishi_1.Schema.string()
|
|
51
50
|
.pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
|
|
52
51
|
.default('#F38AB5')
|