koishi-plugin-bilibili-notify 1.0.4-alpha.2 → 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.
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
- /* this.client = this.ctx.http.extend({
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('Failed to parse server time');
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;
@@ -31,79 +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, /* permissions: ['authority:5'] */ })
34
+ /* ctx.command('test', { hidden: true, permissions: ['authority:5'] })
35
35
  .subcommand('.cookies')
36
36
  .usage('测试指令,用于测试从数据库读取cookies')
37
37
  .action(async () => {
38
- await ctx.biliAPI.loadCookiesFromDatabase();
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
- const content = await ctx.biliAPI.getMyselfInfo();
46
- console.log(content);
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
- const content = await ctx.biliAPI.getUserInfo(mid);
54
- console.log(content);
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
63
  .action(async ({ session }) => {
61
- session.send(await ctx.biliAPI.getTimeNow());
62
- });
64
+ session.send(await ctx.biliAPI.getTimeNow())
65
+ })
66
+
63
67
  ctx.command('test')
64
68
  .subcommand('.exist')
65
69
  .usage('测试写法')
66
70
  .example('test.exist')
67
71
  .action(async () => {
68
- let num = 1;
69
- console.log(num && `Hello World`);
70
- });
72
+ let num = 1;
73
+ console.log(num && `Hello World`);
74
+ })
75
+
71
76
  ctx.command('test')
72
77
  .subcommand('.gimg <uid:string> <index:number>')
73
78
  .usage('测试图片生成')
74
79
  .example('test.gimg')
75
80
  .action(async ({ session }, uid, index) => {
76
- // 获取用户空间动态数据
77
- const { data } = await ctx.biliAPI.getUserSpaceDynamic(uid);
78
- // 获取动态推送图片
79
- const { pic, buffer } = await ctx.gimg.generateDynamicImg(data.items[index]);
80
- // 如果pic存在,则直接返回pic
81
- if (pic)
82
- return pic;
83
- // pic不存在,说明使用的是page模式
84
- await session.send(koishi_1.h.image(buffer, 'image/png'));
85
- });
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
+
86
91
  ctx.command('test')
87
92
  .subcommand('.group')
88
93
  .usage('查看session groupId')
89
94
  .example('test group')
90
95
  .action(({ session }) => {
91
- console.log(session.event.channel);
92
- });
96
+ console.log(session.event.channel);
97
+ })
98
+
93
99
  ctx.command('test')
94
100
  .subcommand('.session')
95
101
  .usage('查看seesion')
96
102
  .example('test session')
97
103
  .action(({ session }) => {
98
- console.log(session);
99
- });
104
+ console.log(session);
105
+ })
106
+
100
107
  ctx.command('test')
101
108
  .subcommand('.utc')
102
109
  .usage('获取当前UTC+8 Unix时间戳')
103
110
  .example('test utc')
104
111
  .action(async ({ session }) => {
105
- session.send((await ctx.biliAPI.getServerUTCTime()).toString());
106
- });
112
+ session.send((await ctx.biliAPI.getServerUTCTime()).toString())
113
+ }) */
107
114
  ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] })
108
115
  .subcommand('.login', '登录B站之后才可以进行之后的操作')
109
116
  .usage('使用二维码登录,登录B站之后才可以进行之后的操作')
@@ -499,10 +506,10 @@ class ComRegister {
499
506
  let timer = 0;
500
507
  return async () => {
501
508
  // Test code
502
- this.logger.info('timer:' + timer++);
503
- this.logger.info('firstSubscription:' + firstSubscription);
504
- this.logger.info(`timePoint: ${timePoint}`);
505
- this.logger.info(`timePoint: ${ctx.gimg.unixTimestampToString(timePoint)}`);
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)}`) */
506
513
  // 第一次订阅判断
507
514
  if (firstSubscription) {
508
515
  // 设置第一次的时间点
@@ -535,30 +542,24 @@ class ComRegister {
535
542
  }
536
543
  // 获取数据内容
537
544
  const items = content.data.items;
538
- // 发送请求 默认只查看配置文件规定的数据
545
+ // 发送请求 默认只查看配置文件规定数量的数据
539
546
  for (let num = this.config.dynamicCheckNumber - 1; num >= 0; num--) {
540
547
  // 没有动态内容则直接跳过
541
548
  if (!items[num])
542
549
  continue;
543
550
  // Test code
544
- this.logger.info(`items[${num}].modules.module_author.pub_ts: ${items[num].modules.module_author.pub_ts}`);
545
- this.logger.info(`items[${num}].modules.module_author.pub_ts: ${ctx.gimg.unixTimestampToString(items[num].modules.module_author.pub_ts)}`);
546
- // 寻找发布时间比时间点时间更晚的动态
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
+ // 寻找发布时间比时间点更晚的动态
547
554
  if (items[num].modules.module_author.pub_ts > timePoint) {
548
- // 如果这是遍历的最后一条,将时间点设置为这条动态的发布时间
549
- /* if (num === 1) timePoint = items[num].modules.module_author.pub_ts
550
- if (num === 0) {
551
- timePoint = items[num].modules.module_author.pub_ts
552
- } */
553
- // 检查最一条动态是否是置顶动态
554
- if (num === 0) {
555
- // 如果是置顶动态,则跳过
556
- if (items[num].modules.module_tag) {
557
- // 将上一条动态的发布时间设为时间点
558
- timePoint = items[num + 1].modules.module_author.pub_ts;
559
- 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;
560
562
  }
561
- timePoint = items[num].modules.module_author.pub_ts;
562
563
  }
563
564
  // 推送该条动态
564
565
  let attempts = 3;
@@ -580,6 +581,22 @@ class ComRegister {
580
581
  }
581
582
  }
582
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
+ } */
583
600
  }
584
601
  }
585
602
  };
@@ -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, '../font/HYZhengYuan-55W.ttf'));
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, '../font/HYZhengYuan-55W.ttf'));
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
@@ -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-alpha.2",
4
+ "version": "1.0.4-rc.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -79,6 +79,7 @@
79
79
  ver 1.0.1 修复了一些bug,提供用户自己选择动态检测时间的选项
80
80
  ver 1.0.2 修复时间bug和字体乱码问题
81
81
  ver 1.0.3 修复了一些bug,提供用户自己选择推送卡片字体样式的选项
82
+ ver 1.0.4 修复了重复推送的bug,提供用户选择推送卡片渲染方式的选项
82
83
 
83
84
  ## 感谢
84
85