koishi-plugin-bilibili-notify 1.0.10-alpha.0 → 1.0.11
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 +10 -10
- package/lib/comRegister.d.ts +2 -2
- package/lib/comRegister.js +84 -46
- package/lib/generateImg.js +1 -1
- package/package.json +7 -5
- package/readme.md +1 -0
- package/lib/authority.d.ts +0 -5
- package/lib/authority.js +0 -12
package/lib/biliAPI.js
CHANGED
|
@@ -150,11 +150,7 @@ class BiliAPI extends koishi_1.Service {
|
|
|
150
150
|
}
|
|
151
151
|
getCookies() {
|
|
152
152
|
let cookies;
|
|
153
|
-
this.jar.
|
|
154
|
-
if (err)
|
|
155
|
-
throw err;
|
|
156
|
-
cookies = JSON.stringify(c, null, 2);
|
|
157
|
-
});
|
|
153
|
+
cookies = JSON.stringify(this.jar.serializeSync().cookies);
|
|
158
154
|
return cookies;
|
|
159
155
|
}
|
|
160
156
|
async loadCookiesFromDatabase() {
|
|
@@ -205,6 +201,8 @@ class BiliAPI extends koishi_1.Service {
|
|
|
205
201
|
});
|
|
206
202
|
this.jar.setCookieSync(cookie, `http${cookie.secure ? 's' : ''}://${cookie.domain}${cookie.path}`, {});
|
|
207
203
|
});
|
|
204
|
+
// restart plugin check
|
|
205
|
+
this.checkIfTokenNeedRefresh(decryptedRefreshToken, csrf);
|
|
208
206
|
// Open scheduled tasks and check if token need refresh
|
|
209
207
|
this.ctx.setInterval(() => {
|
|
210
208
|
this.checkIfTokenNeedRefresh(decryptedRefreshToken, csrf);
|
|
@@ -285,13 +283,15 @@ class BiliAPI extends koishi_1.Service {
|
|
|
285
283
|
}]);
|
|
286
284
|
// Get new csrf from cookies
|
|
287
285
|
let newCsrf;
|
|
288
|
-
this.jar.store.getAllCookies((err, c) => {
|
|
289
|
-
if (err)
|
|
290
|
-
throw err;
|
|
286
|
+
/* this.jar.store.getAllCookies((err, c) => {
|
|
287
|
+
if (err) throw err;
|
|
291
288
|
c.forEach(cookie => {
|
|
292
|
-
if (cookie.key === 'bili_jct')
|
|
293
|
-
newCsrf = cookie.value;
|
|
289
|
+
if (cookie.key === 'bili_jct') newCsrf = cookie.value
|
|
294
290
|
});
|
|
291
|
+
}) */
|
|
292
|
+
this.jar.serializeSync().cookies.forEach(cookie => {
|
|
293
|
+
if (cookie.key === 'bili_jct')
|
|
294
|
+
newCsrf = cookie.value;
|
|
295
295
|
});
|
|
296
296
|
// Accept update
|
|
297
297
|
const { data: aceeptData } = await this.client.post('https://passport.bilibili.com/x/passport-login/web/confirm/refresh', {
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ declare class ComRegister {
|
|
|
20
20
|
qqguildBot: Bot<Context>;
|
|
21
21
|
oneBot: Bot<Context>;
|
|
22
22
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
23
|
-
dynamicDetect(ctx: Context, bot: Bot<Context>, guildId: string, uid: string): () => Promise<void
|
|
24
|
-
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<
|
|
23
|
+
dynamicDetect(ctx: Context, bot: Bot<Context>, guildId: string, uid: string): () => Promise<void>;
|
|
24
|
+
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<string[]>;
|
|
25
25
|
subShow(): string;
|
|
26
26
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
|
27
27
|
updateSubNotifier(ctx: Context): void;
|
package/lib/comRegister.js
CHANGED
|
@@ -42,7 +42,9 @@ class ComRegister {
|
|
|
42
42
|
testCom.subcommand('.cookies')
|
|
43
43
|
.usage('测试指令,用于测试从数据库读取cookies')
|
|
44
44
|
.action(async () => {
|
|
45
|
-
|
|
45
|
+
this.logger.info('调用test cookies指令')
|
|
46
|
+
// await ctx.biliAPI.loadCookiesFromDatabase()
|
|
47
|
+
console.log(ctx.biliAPI.getCookies());
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
testCom
|
|
@@ -135,19 +137,16 @@ class ComRegister {
|
|
|
135
137
|
// 判断是否出问题
|
|
136
138
|
if (content.code !== 0)
|
|
137
139
|
return await session.send('出问题咯,请联系管理员解决!');
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
+
// 生成二维码
|
|
141
|
+
qrcode_1.default.toBuffer(content.data.url, {
|
|
140
142
|
errorCorrectionLevel: 'H', // 错误更正水平
|
|
141
|
-
type: '
|
|
142
|
-
quality: 0.92, // 图像质量(仅适用于'image/jpeg')
|
|
143
|
+
type: 'png', // 输出类型
|
|
143
144
|
margin: 1, // 边距大小
|
|
144
145
|
color: {
|
|
145
146
|
dark: '#000000', // 二维码颜色
|
|
146
147
|
light: '#FFFFFF' // 背景颜色
|
|
147
148
|
}
|
|
148
|
-
}
|
|
149
|
-
// 生成二维码
|
|
150
|
-
qrcode_1.default.toBuffer(content.data.url, options, async (err, buffer) => {
|
|
149
|
+
}, async (err, buffer) => {
|
|
151
150
|
if (err)
|
|
152
151
|
return await session.send('二维码生成出错,请联系管理员解决!');
|
|
153
152
|
await session.send(koishi_1.h.image(buffer, 'image/png'));
|
|
@@ -586,10 +585,14 @@ class ComRegister {
|
|
|
586
585
|
}
|
|
587
586
|
}
|
|
588
587
|
// 如果pic存在,则直接返回pic
|
|
589
|
-
if (pic)
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
588
|
+
if (pic) {
|
|
589
|
+
// pic存在,使用的是render模式
|
|
590
|
+
await bot.sendMessage(guildId, pic);
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
// pic不存在,说明使用的是page模式
|
|
594
|
+
await bot.sendMessage(guildId, koishi_1.h.image(buffer, 'image/png'));
|
|
595
|
+
}
|
|
593
596
|
// 如果成功,那么跳出循环
|
|
594
597
|
break;
|
|
595
598
|
}
|
|
@@ -638,14 +641,25 @@ class ComRegister {
|
|
|
638
641
|
// 相当于锁的作用,防止上一个循环没处理完
|
|
639
642
|
let flag = true;
|
|
640
643
|
async function sendLiveNotifyCard(data, uData, liveType) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
644
|
+
let attempts = 3;
|
|
645
|
+
for (let i = 0; i < attempts; i++) {
|
|
646
|
+
try {
|
|
647
|
+
// 获取直播通知卡片
|
|
648
|
+
const { pic, buffer } = await ctx.gimg.generateLiveImg(data, uData, liveType);
|
|
649
|
+
// 推送直播信息
|
|
650
|
+
// pic 存在,使用的是render模式
|
|
651
|
+
if (pic)
|
|
652
|
+
return bot.sendMessage(guildId, pic);
|
|
653
|
+
// pic不存在,说明使用的是page模式
|
|
654
|
+
await bot.sendMessage(guildId, koishi_1.h.image(buffer, 'image/png'));
|
|
655
|
+
}
|
|
656
|
+
catch (e) {
|
|
657
|
+
this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败');
|
|
658
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
659
|
+
return bot.sendMessage(guildId, '插件可能出现某些未知错误,请尝试重启插件,如果仍然会发生该错误,请向作者反馈');
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
649
663
|
}
|
|
650
664
|
return async () => {
|
|
651
665
|
try {
|
|
@@ -655,11 +669,17 @@ class ComRegister {
|
|
|
655
669
|
flag && (flag = false);
|
|
656
670
|
// 发送请求检测直播状态
|
|
657
671
|
let content;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
672
|
+
let attempts = 3;
|
|
673
|
+
for (let i = 0; i < attempts; i++) {
|
|
674
|
+
try {
|
|
675
|
+
content = await ctx.biliAPI.getLiveRoomInfo(roomId);
|
|
676
|
+
}
|
|
677
|
+
catch (e) {
|
|
678
|
+
this.logger.error('liveDetect getLiveRoomInfo 网络请求失败');
|
|
679
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
680
|
+
return bot.sendMessage(guildId, '你的网络可能出现了某些问题,请检查后重启插件');
|
|
681
|
+
}
|
|
682
|
+
}
|
|
663
683
|
}
|
|
664
684
|
const { data } = content;
|
|
665
685
|
// B站出问题了
|
|
@@ -678,12 +698,18 @@ class ComRegister {
|
|
|
678
698
|
firstSubscription = false;
|
|
679
699
|
// 获取主播信息
|
|
680
700
|
let userData;
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
701
|
+
let attempts = 3;
|
|
702
|
+
for (let i = 0; i < attempts; i++) {
|
|
703
|
+
try {
|
|
704
|
+
const { data: userInfo } = await ctx.biliAPI.getMasterInfo(data.uid);
|
|
705
|
+
userData = userInfo;
|
|
706
|
+
}
|
|
707
|
+
catch (e) {
|
|
708
|
+
this.logger.error('liveDetect getMasterInfo() 本次网络请求失败');
|
|
709
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
710
|
+
return bot.sendMessage(guildId, '你的网络可能出现了某些问题,请检查后重启插件');
|
|
711
|
+
}
|
|
712
|
+
}
|
|
687
713
|
}
|
|
688
714
|
// 主播信息不会变,请求一次即可
|
|
689
715
|
uData = userData;
|
|
@@ -708,7 +734,7 @@ class ComRegister {
|
|
|
708
734
|
// 下播了将定时器清零
|
|
709
735
|
timer = 0;
|
|
710
736
|
// 发送下播通知
|
|
711
|
-
bot.sendMessage(guildId, `${uData.info.uname}下播啦,本次直播了${await ctx.gimg.getTimeDifference(liveTime)}`);
|
|
737
|
+
await bot.sendMessage(guildId, `${uData.info.uname}下播啦,本次直播了${await ctx.gimg.getTimeDifference(liveTime)}`);
|
|
712
738
|
}
|
|
713
739
|
// 未进循环,还未开播,继续循环
|
|
714
740
|
break;
|
|
@@ -721,12 +747,18 @@ class ComRegister {
|
|
|
721
747
|
liveTime = data.live_time;
|
|
722
748
|
// 获取主播信息
|
|
723
749
|
let userData;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
750
|
+
let attempts = 3;
|
|
751
|
+
for (let i = 0; i < attempts; i++) {
|
|
752
|
+
try {
|
|
753
|
+
const { data: userInfo } = await ctx.biliAPI.getMasterInfo(data.uid);
|
|
754
|
+
userData = userInfo;
|
|
755
|
+
}
|
|
756
|
+
catch (e) {
|
|
757
|
+
this.logger.error('liveDetect open getMasterInfo() 网络请求错误');
|
|
758
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
759
|
+
return bot.sendMessage(guildId, '你的网络可能出现了某些问题,请检查后重启插件');
|
|
760
|
+
}
|
|
761
|
+
}
|
|
730
762
|
}
|
|
731
763
|
// 主播信息不会变,开播时刷新一次即可
|
|
732
764
|
uData = userData;
|
|
@@ -801,14 +833,20 @@ class ComRegister {
|
|
|
801
833
|
updateSubNotifier(ctx) {
|
|
802
834
|
// 更新控制台提示
|
|
803
835
|
this.subNotifier && this.subNotifier.dispose();
|
|
804
|
-
//
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
836
|
+
// 获取订阅信息
|
|
837
|
+
const subInfo = this.subShow();
|
|
838
|
+
// 定义table
|
|
839
|
+
let table = '';
|
|
840
|
+
if (subInfo === '没有订阅任何UP') {
|
|
841
|
+
table = subInfo;
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
// 获取subTable
|
|
845
|
+
let subTableArray = subInfo.split('\n');
|
|
846
|
+
subTableArray.splice(subTableArray.length - 1, 1);
|
|
847
|
+
// 定义Table
|
|
848
|
+
table = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map(str => ((0, jsx_runtime_1.jsx)("li", { children: str }))) }) });
|
|
849
|
+
}
|
|
812
850
|
// 设置更新后的提示
|
|
813
851
|
this.subNotifier = ctx.notifier.create(table);
|
|
814
852
|
}
|
package/lib/generateImg.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-bilibili-notify",
|
|
3
3
|
"description": "Koishi bilibili notify plugin",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Akokko <admin@akokko.com>"
|
|
7
7
|
],
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"url": "git+https://github.com/Akokk0/koishi-plugin-bilibili-notify"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.npmjs.com/package/koishi-plugin-bilibili-notify",
|
|
20
|
-
"scripts": {},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"chatbot",
|
|
23
22
|
"koishi",
|
|
@@ -25,16 +24,19 @@
|
|
|
25
24
|
"bilibili"
|
|
26
25
|
],
|
|
27
26
|
"peerDependencies": {
|
|
28
|
-
"koishi": "^4.16.
|
|
27
|
+
"koishi": "^4.16.6"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"axios-cookiejar-support": "^
|
|
32
|
-
"jsdom": "^
|
|
30
|
+
"axios-cookiejar-support": "^5.0.0",
|
|
31
|
+
"jsdom": "^24.0.0",
|
|
33
32
|
"md5": "^2.3.0",
|
|
34
33
|
"qrcode": "^1.5.3",
|
|
35
34
|
"tough-cookie": "^4.1.3"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
37
|
+
"@types/md5": "^2",
|
|
38
|
+
"@types/qrcode": "^1",
|
|
39
|
+
"@types/tough-cookie": "^4",
|
|
38
40
|
"koishi-plugin-puppeteer": "^3.7.3"
|
|
39
41
|
},
|
|
40
42
|
"koishi": {
|
package/readme.md
CHANGED
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
- ver 1.0.8 修复了取消订阅的bug
|
|
87
87
|
- ver 1.0.9 更新请求客户端header信息。优化了动态推送卡片的页面布局,增加了字体大小。提供用户开放订阅数量限制的选项,提供用户移除推送卡片边框的选项。在控制台页面增加订阅信息提示
|
|
88
88
|
- ver 1.0.10 增加对onebot的支持,添加动态关键字屏蔽功能
|
|
89
|
+
- ver 1.0.11 修复了render渲染模式下,动态重复推送的问题,修复了没有订阅时,控制台空白提示的问题。优化了视频动态缩略图显示不全的问题,优化了部分逻辑。增强容错和增加错误提示
|
|
89
90
|
|
|
90
91
|
## 感谢
|
|
91
92
|
|
package/lib/authority.d.ts
DELETED
package/lib/authority.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class Authority {
|
|
4
|
-
constructor(ctx) {
|
|
5
|
-
// 授予权限
|
|
6
|
-
/* ctx.permissions.provide('telegram:admin', async (name, session) => {
|
|
7
|
-
console.log(session);
|
|
8
|
-
return session.telegram?.sender?.role === 'admin'
|
|
9
|
-
}) */
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.default = Authority;
|