koishi-plugin-bilibili-notify 1.0.4-alpha.1 → 1.0.4-rc.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/HYZhengYuan-55W.ttf +0 -0
- package/lib/biliAPI.js +4 -14
- package/lib/comRegister.js +69 -53
- package/lib/generateImg.js +3 -3
- package/lib/wbi.js +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
|
Binary file
|
package/lib/biliAPI.js
CHANGED
|
@@ -29,12 +29,11 @@ class BiliAPI extends koishi_1.Service {
|
|
|
29
29
|
super(ctx, 'biliAPI');
|
|
30
30
|
}
|
|
31
31
|
start() {
|
|
32
|
-
|
|
33
|
-
endpoint: 'https://api.live.bilibili.com',
|
|
34
|
-
}) */
|
|
32
|
+
// 创建新的http客户端(axios)
|
|
35
33
|
this.createNewClient();
|
|
34
|
+
// 从数据库加载cookies
|
|
36
35
|
this.loadCookiesFromDatabase();
|
|
37
|
-
this.logger.info('BiliAPI已被注册到Context中')
|
|
36
|
+
// this.logger.info('BiliAPI已被注册到Context中')
|
|
38
37
|
}
|
|
39
38
|
async getServerUTCTime() {
|
|
40
39
|
try {
|
|
@@ -46,7 +45,7 @@ class BiliAPI extends koishi_1.Service {
|
|
|
46
45
|
return timestamp / 1000;
|
|
47
46
|
}
|
|
48
47
|
else {
|
|
49
|
-
throw new Error('
|
|
48
|
+
throw new Error('解析服务器时间失败!');
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
catch (e) {
|
|
@@ -303,13 +302,4 @@ class BiliAPI extends koishi_1.Service {
|
|
|
303
302
|
// 没有问题,cookies已更新完成
|
|
304
303
|
}
|
|
305
304
|
}
|
|
306
|
-
/* namespace LiveAPI {
|
|
307
|
-
export interface Config {
|
|
308
|
-
roomId: string
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export const Config: Schema<Config> = Schema.object({
|
|
312
|
-
roomId: Schema.string().required()
|
|
313
|
-
})
|
|
314
|
-
} */
|
|
315
305
|
exports.default = BiliAPI;
|
package/lib/comRegister.js
CHANGED
|
@@ -31,80 +31,86 @@ class ComRegister {
|
|
|
31
31
|
this.qqguildBot = ctx.bots[ctx.bots.findIndex(bot => bot.platform === 'qqguild')];
|
|
32
32
|
// 从数据库获取订阅
|
|
33
33
|
this.getSubFromDatabase(ctx);
|
|
34
|
-
ctx.command('test', { hidden: true,
|
|
34
|
+
/* ctx.command('test', { hidden: true, permissions: ['authority:5'] })
|
|
35
35
|
.subcommand('.cookies')
|
|
36
36
|
.usage('测试指令,用于测试从数据库读取cookies')
|
|
37
37
|
.action(async () => {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
await ctx.biliAPI.loadCookiesFromDatabase()
|
|
39
|
+
})
|
|
40
|
+
|
|
40
41
|
ctx.command('test')
|
|
41
42
|
.subcommand('.my')
|
|
42
43
|
.usage('测试指令,用于测试获取自己信息')
|
|
43
44
|
.example('test.my')
|
|
44
45
|
.action(async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const content = await ctx.biliAPI.getMyselfInfo()
|
|
47
|
+
console.log(content);
|
|
48
|
+
})
|
|
49
|
+
|
|
48
50
|
ctx.command('test')
|
|
49
51
|
.subcommand('.user <mid:string>')
|
|
50
52
|
.usage('测试指令,用于测试获取用户信息')
|
|
51
53
|
.example('test.user 用户UID')
|
|
52
54
|
.action(async (_, mid) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const content = await ctx.biliAPI.getUserInfo(mid)
|
|
56
|
+
console.log(content);
|
|
57
|
+
})
|
|
58
|
+
|
|
56
59
|
ctx.command('test')
|
|
57
60
|
.subcommand('.time')
|
|
58
61
|
.usage('测试时间接口')
|
|
59
62
|
.example('test.time')
|
|
60
|
-
.action(async () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
.action(async ({ session }) => {
|
|
64
|
+
session.send(await ctx.biliAPI.getTimeNow())
|
|
65
|
+
})
|
|
66
|
+
|
|
64
67
|
ctx.command('test')
|
|
65
68
|
.subcommand('.exist')
|
|
66
69
|
.usage('测试写法')
|
|
67
70
|
.example('test.exist')
|
|
68
71
|
.action(async () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
let num = 1;
|
|
73
|
+
console.log(num && `Hello World`);
|
|
74
|
+
})
|
|
75
|
+
|
|
72
76
|
ctx.command('test')
|
|
73
77
|
.subcommand('.gimg <uid:string> <index:number>')
|
|
74
78
|
.usage('测试图片生成')
|
|
75
79
|
.example('test.gimg')
|
|
76
80
|
.action(async ({ session }, uid, index) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
// 获取用户空间动态数据
|
|
82
|
+
const { data } = await ctx.biliAPI.getUserSpaceDynamic(uid)
|
|
83
|
+
// 获取动态推送图片
|
|
84
|
+
const { pic, buffer } = await ctx.gimg.generateDynamicImg(data.items[index])
|
|
85
|
+
// 如果pic存在,则直接返回pic
|
|
86
|
+
if (pic) return pic
|
|
87
|
+
// pic不存在,说明使用的是page模式
|
|
88
|
+
await session.send(h.image(buffer, 'image/png'))
|
|
89
|
+
})
|
|
90
|
+
|
|
87
91
|
ctx.command('test')
|
|
88
92
|
.subcommand('.group')
|
|
89
93
|
.usage('查看session groupId')
|
|
90
94
|
.example('test group')
|
|
91
95
|
.action(({ session }) => {
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
console.log(session.event.channel);
|
|
97
|
+
})
|
|
98
|
+
|
|
94
99
|
ctx.command('test')
|
|
95
100
|
.subcommand('.session')
|
|
96
101
|
.usage('查看seesion')
|
|
97
102
|
.example('test session')
|
|
98
103
|
.action(({ session }) => {
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
console.log(session);
|
|
105
|
+
})
|
|
106
|
+
|
|
101
107
|
ctx.command('test')
|
|
102
108
|
.subcommand('.utc')
|
|
103
109
|
.usage('获取当前UTC+8 Unix时间戳')
|
|
104
110
|
.example('test utc')
|
|
105
111
|
.action(async ({ session }) => {
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
session.send((await ctx.biliAPI.getServerUTCTime()).toString())
|
|
113
|
+
}) */
|
|
108
114
|
ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] })
|
|
109
115
|
.subcommand('.login', '登录B站之后才可以进行之后的操作')
|
|
110
116
|
.usage('使用二维码登录,登录B站之后才可以进行之后的操作')
|
|
@@ -500,10 +506,10 @@ class ComRegister {
|
|
|
500
506
|
let timer = 0;
|
|
501
507
|
return async () => {
|
|
502
508
|
// Test code
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
509
|
+
/* this.logger.info('timer:' + timer++)
|
|
510
|
+
this.logger.info('firstSubscription:' + firstSubscription)
|
|
511
|
+
this.logger.info(`timePoint: ${timePoint}`)
|
|
512
|
+
this.logger.info(`timePoint: ${ctx.gimg.unixTimestampToString(timePoint)}`) */
|
|
507
513
|
// 第一次订阅判断
|
|
508
514
|
if (firstSubscription) {
|
|
509
515
|
// 设置第一次的时间点
|
|
@@ -536,30 +542,24 @@ class ComRegister {
|
|
|
536
542
|
}
|
|
537
543
|
// 获取数据内容
|
|
538
544
|
const items = content.data.items;
|
|
539
|
-
// 发送请求
|
|
545
|
+
// 发送请求 默认只查看配置文件规定数量的数据
|
|
540
546
|
for (let num = this.config.dynamicCheckNumber - 1; num >= 0; num--) {
|
|
541
547
|
// 没有动态内容则直接跳过
|
|
542
548
|
if (!items[num])
|
|
543
549
|
continue;
|
|
544
550
|
// Test code
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
//
|
|
551
|
+
/* this.logger.info(`items[${num}].modules.module_author.pub_ts: ${items[num].modules.module_author.pub_ts}`)
|
|
552
|
+
this.logger.info(`items[${num}].modules.module_author.pub_ts: ${ctx.gimg.unixTimestampToString(items[num].modules.module_author.pub_ts)}`) */
|
|
553
|
+
// 寻找发布时间比时间点更晚的动态
|
|
548
554
|
if (items[num].modules.module_author.pub_ts > timePoint) {
|
|
549
|
-
//
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
// 如果是置顶动态,则跳过
|
|
557
|
-
if (items[num].modules.module_tag) {
|
|
558
|
-
// 将上一条动态的发布时间设为时间点
|
|
559
|
-
timePoint = items[num + 1].modules.module_author.pub_ts;
|
|
560
|
-
continue;
|
|
555
|
+
// 更新时间点为当前动态的发布时间
|
|
556
|
+
if (num === 1) { // 寻找倒数第二条动态
|
|
557
|
+
if (items[0].modules.module_tag) { // 存在置顶动态
|
|
558
|
+
timePoint = items[num].modules.module_author.pub_ts;
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
timePoint = items[0].modules.module_author.pub_ts;
|
|
561
562
|
}
|
|
562
|
-
timePoint = items[num].modules.module_author.pub_ts;
|
|
563
563
|
}
|
|
564
564
|
// 推送该条动态
|
|
565
565
|
let attempts = 3;
|
|
@@ -581,6 +581,22 @@ class ComRegister {
|
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
|
+
// 如果这是遍历的最后一条,将时间点设置为这条动态的发布时间
|
|
585
|
+
/* if (num === 1) timePoint = items[num].modules.module_author.pub_ts
|
|
586
|
+
if (num === 0) {
|
|
587
|
+
timePoint = items[num].modules.module_author.pub_ts
|
|
588
|
+
} */
|
|
589
|
+
// 检查最一条动态是否是置顶动态 (ver 1.0.4 不用考虑置顶动态的问题)
|
|
590
|
+
// 如果是新发布的置顶动态,直接推送即可。如果是旧的置顶动态,则无法进入这个判断
|
|
591
|
+
/* if (num === 0) {
|
|
592
|
+
// 如果是置顶动态,则跳过
|
|
593
|
+
if (items[num].modules.module_tag) {
|
|
594
|
+
// 将上一条动态的发布时间设为时间点
|
|
595
|
+
timePoint = items[num + 1].modules.module_author.pub_ts
|
|
596
|
+
continue
|
|
597
|
+
}
|
|
598
|
+
timePoint = items[num].modules.module_author.pub_ts
|
|
599
|
+
} */
|
|
584
600
|
}
|
|
585
601
|
}
|
|
586
602
|
};
|
package/lib/generateImg.js
CHANGED
|
@@ -44,12 +44,12 @@ class GenerateImg extends koishi_1.Service {
|
|
|
44
44
|
this.config = config;
|
|
45
45
|
}
|
|
46
46
|
start() {
|
|
47
|
-
this.logger.info('GenerateImg已被注册到Context中');
|
|
47
|
+
// this.logger.info('GenerateImg已被注册到Context中');
|
|
48
48
|
}
|
|
49
49
|
async generateLiveImg(data, userData, liveStatus /*0未开播 1刚开播 2已开播 */) {
|
|
50
50
|
const [titleStatus, liveTime, cover] = await this.getLiveStatus(data.live_time, liveStatus);
|
|
51
51
|
// 加载字体
|
|
52
|
-
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, '
|
|
52
|
+
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, './HYZhengYuan-55W.ttf'));
|
|
53
53
|
// 卡片内容
|
|
54
54
|
const html = `
|
|
55
55
|
<!DOCTYPE html>
|
|
@@ -496,7 +496,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
496
496
|
}
|
|
497
497
|
const [main, link] = await getDynamicMajor(data, false);
|
|
498
498
|
// 加载字体
|
|
499
|
-
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, '
|
|
499
|
+
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, './HYZhengYuan-55W.ttf'));
|
|
500
500
|
// 定义卡片内容
|
|
501
501
|
const html = `
|
|
502
502
|
<!DOCTYPE html>
|
package/lib/wbi.js
CHANGED
|
@@ -19,7 +19,7 @@ class Wbi extends koishi_1.Service {
|
|
|
19
19
|
this.config = config;
|
|
20
20
|
}
|
|
21
21
|
start() {
|
|
22
|
-
this.logger.info('wbi已被注册到Context中')
|
|
22
|
+
// this.logger.info('wbi已被注册到Context中')
|
|
23
23
|
}
|
|
24
24
|
// 对 imgKey 和 subKey 进行字符顺序打乱编码
|
|
25
25
|
getMixinKey = (orig) => this.mixinKeyEncTab.map(n => orig[n]).join('').slice(0, 32);
|
package/package.json
CHANGED