koishi-plugin-bilibili-notify 1.2.0-alpha.3 → 1.2.0-alpha.5

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 CHANGED
@@ -28,6 +28,7 @@ declare class BiliAPI extends Service {
28
28
  getMasterInfo(mid: string): Promise<any>;
29
29
  disposeNotifier(): void;
30
30
  createNewClient(): void;
31
+ getTimeOfUTC8(): number;
31
32
  getCookies(): string;
32
33
  getLoginInfoFromDB(): Promise<{
33
34
  cookies: any;
package/lib/biliAPI.js CHANGED
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const tough_cookie_1 = require("tough-cookie");
9
9
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
10
10
  const jsdom_1 = require("jsdom");
11
+ const luxon_1 = require("luxon");
11
12
  // const GET_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all'
12
13
  const GET_USER_SPACE_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
13
14
  const GET_COOKIES_INFO = 'https://passport.bilibili.com/x/passport-login/web/cookie/info';
@@ -193,6 +194,9 @@ class BiliAPI extends koishi_1.Service {
193
194
  }
194
195
  }));
195
196
  }
197
+ getTimeOfUTC8() {
198
+ return Math.floor(luxon_1.DateTime.now().setZone('UTC+8').toSeconds());
199
+ }
196
200
  getCookies() {
197
201
  let cookies;
198
202
  cookies = JSON.stringify(this.jar.serializeSync().cookies);
@@ -588,7 +588,7 @@ class ComRegister {
588
588
  // 第一次订阅判断
589
589
  if (firstSubscription) {
590
590
  // 设置第一次的时间点
591
- timePoint = await ctx.biliAPI.getServerUTCTime();
591
+ timePoint = ctx.biliAPI.getTimeOfUTC8();
592
592
  // 设置第一次为false
593
593
  firstSubscription = false;
594
594
  return;
@@ -660,8 +660,9 @@ class ComRegister {
660
660
  break;
661
661
  }
662
662
  catch (e) {
663
+ this.logger.error('dynamicDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
663
664
  if (i === attempts - 1) { // 如果已经尝试了三次,那么抛出错误
664
- throw e;
665
+ return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
665
666
  }
666
667
  }
667
668
  }
@@ -709,9 +710,9 @@ class ComRegister {
709
710
  break;
710
711
  }
711
712
  catch (e) {
712
- this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败');
713
+ this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
713
714
  if (i === attempts - 1) { // 已尝试三次
714
- return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然会发生该错误,请向作者反馈');
715
+ return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
715
716
  }
716
717
  }
717
718
  }
package/lib/database.js CHANGED
@@ -6,8 +6,8 @@ function apply(ctx) {
6
6
  // 新增LoginBili表
7
7
  ctx.model.extend('loginBili', {
8
8
  id: 'unsigned',
9
- bili_cookies: 'string',
10
- bili_refresh_token: 'string'
9
+ bili_cookies: 'text',
10
+ bili_refresh_token: 'text'
11
11
  });
12
12
  // 新增Bilibili表
13
13
  ctx.model.extend('bilibili', {
@@ -7,7 +7,7 @@ declare module 'koishi' {
7
7
  }
8
8
  declare class GenerateImg extends Service {
9
9
  static inject: string[];
10
- config: GenerateImg.Config;
10
+ giConfig: GenerateImg.Config;
11
11
  constructor(ctx: Context, config: GenerateImg.Config);
12
12
  protected start(): void | Promise<void>;
13
13
  generateLiveImg(data: any, userData: any, liveStatus: number): Promise<{
@@ -38,10 +38,10 @@ const ADDITIONAL_TYPE_UGC = 'ADDITIONAL_TYPE_UGC' */
38
38
  const ADDITIONAL_TYPE_RESERVE = 'ADDITIONAL_TYPE_RESERVE';
39
39
  class GenerateImg extends koishi_1.Service {
40
40
  static inject = ['puppeteer', 'biliAPI'];
41
- config;
41
+ giConfig;
42
42
  constructor(ctx, config) {
43
43
  super(ctx, 'gimg');
44
- this.config = config;
44
+ this.giConfig = config;
45
45
  }
46
46
  start() {
47
47
  // this.logger.info('GenerateImg已被注册到Context中');
@@ -65,7 +65,7 @@ class GenerateImg extends koishi_1.Service {
65
65
  * {
66
66
  margin: 0;
67
67
  padding: 0;
68
- font-family: "${this.config.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
68
+ font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
69
69
  }
70
70
 
71
71
  html {
@@ -76,7 +76,7 @@ class GenerateImg extends koishi_1.Service {
76
76
  .background {
77
77
  width: 770px;
78
78
  height: auto;
79
- background: linear-gradient(to right bottom, ${this.config.cardColorStart}, ${this.config.cardColorEnd});
79
+ background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
80
80
  overflow: hidden;
81
81
  }
82
82
 
@@ -91,7 +91,7 @@ class GenerateImg extends koishi_1.Service {
91
91
  }
92
92
 
93
93
  .base-plate {
94
- ${this.config.removeBorder ? `
94
+ ${this.giConfig.removeBorder ? `
95
95
  width: 740px;
96
96
  ` : `
97
97
  width: 704px;
@@ -185,30 +185,41 @@ class GenerateImg extends koishi_1.Service {
185
185
  </body>
186
186
  </html>
187
187
  `;
188
- // 判断渲染方式
189
- if (this.config.renderType) { // 为1则为真,进入page模式
190
- const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
191
- const page = await this.ctx.puppeteer.page();
192
- await page.goto(htmlPath);
193
- await page.setContent(html, { waitUntil: 'networkidle0' });
194
- const elementHandle = await page.$('html');
195
- const boundingBox = await elementHandle.boundingBox();
196
- const buffer = await page.screenshot({
197
- type: 'png',
198
- clip: {
199
- x: boundingBox.x,
200
- y: boundingBox.y,
201
- width: boundingBox.width,
202
- height: boundingBox.height
188
+ // 多次尝试生成图片
189
+ let attempts = 3;
190
+ for (let i = 0; i < attempts; i++) {
191
+ try {
192
+ // 判断渲染方式
193
+ if (this.giConfig.renderType) { // 为1则为真,进入page模式
194
+ const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
195
+ const page = await this.ctx.puppeteer.page();
196
+ await page.goto(htmlPath);
197
+ await page.setContent(html, { waitUntil: 'networkidle0' });
198
+ const elementHandle = await page.$('html');
199
+ const boundingBox = await elementHandle.boundingBox();
200
+ const buffer = await page.screenshot({
201
+ type: 'png',
202
+ clip: {
203
+ x: boundingBox.x,
204
+ y: boundingBox.y,
205
+ width: boundingBox.width,
206
+ height: boundingBox.height
207
+ }
208
+ });
209
+ await elementHandle.dispose();
210
+ await page.close();
211
+ return { buffer };
212
+ }
213
+ // 使用render模式渲染
214
+ const pic = await this.ctx.puppeteer.render(html);
215
+ return { pic };
216
+ }
217
+ catch (e) {
218
+ if (i === attempts - 1) { // 已尝试三次
219
+ throw new Error('生成图片失败!错误: ' + e.toString());
203
220
  }
204
- });
205
- await elementHandle.dispose();
206
- await page.close();
207
- return { buffer };
221
+ }
208
222
  }
209
- // 使用render模式渲染
210
- const pic = await this.ctx.puppeteer.render(html);
211
- return { pic };
212
223
  }
213
224
  async generateDynamicImg(data) {
214
225
  // module_author
@@ -251,14 +262,14 @@ class GenerateImg extends koishi_1.Service {
251
262
  }
252
263
  }, '');
253
264
  // 关键字和正则屏蔽
254
- if (this.config.filter.enable) { // 开启关键字和正则屏蔽
255
- if (this.config.filter.regex) { // 正则屏蔽
256
- const reg = new RegExp(this.config.filter.regex);
265
+ if (this.giConfig.filter.enable) { // 开启关键字和正则屏蔽
266
+ if (this.giConfig.filter.regex) { // 正则屏蔽
267
+ const reg = new RegExp(this.giConfig.filter.regex);
257
268
  if (reg.test(richText))
258
269
  throw new Error('出现关键词,屏蔽该动态');
259
270
  }
260
- if (this.config.filter.keywords.length !== 0 &&
261
- this.config.filter.keywords
271
+ if (this.giConfig.filter.keywords.length !== 0 &&
272
+ this.giConfig.filter.keywords
262
273
  .some(keyword => richText.includes(keyword))) {
263
274
  throw new Error('出现关键词,屏蔽该动态');
264
275
  }
@@ -517,7 +528,7 @@ class GenerateImg extends koishi_1.Service {
517
528
  const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'font/HYZhengYuan-75W.ttf'));
518
529
  // 判断是否开启大字体模式
519
530
  let style;
520
- if (this.config.enableLargeFont) {
531
+ if (this.giConfig.enableLargeFont) {
521
532
  style = `
522
533
  @font-face {
523
534
  font-family: "Custom Font";
@@ -528,7 +539,7 @@ class GenerateImg extends koishi_1.Service {
528
539
  margin: 0;
529
540
  padding: 0;
530
541
  box-sizing: border-box;
531
- font-family: "${this.config.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
542
+ font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
532
543
  }
533
544
 
534
545
  html {
@@ -539,7 +550,7 @@ class GenerateImg extends koishi_1.Service {
539
550
  .background {
540
551
  width: 770px;
541
552
  height: auto;
542
- background: linear-gradient(to right bottom, ${this.config.cardColorStart}, ${this.config.cardColorEnd});
553
+ background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
543
554
  overflow: hidden;
544
555
  }
545
556
 
@@ -554,7 +565,7 @@ class GenerateImg extends koishi_1.Service {
554
565
  }
555
566
 
556
567
  .base-plate {
557
- ${this.config.removeBorder ? `
568
+ ${this.giConfig.removeBorder ? `
558
569
  width: 740px;
559
570
  ` : `
560
571
  width: 704px;
@@ -858,7 +869,7 @@ class GenerateImg extends koishi_1.Service {
858
869
  * {
859
870
  margin: 0;
860
871
  padding: 0;
861
- font-family: "${this.config.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
872
+ font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
862
873
  }
863
874
 
864
875
  html {
@@ -869,7 +880,7 @@ class GenerateImg extends koishi_1.Service {
869
880
  .background {
870
881
  width: 770px;
871
882
  height: auto;
872
- background: linear-gradient(to right bottom, ${this.config.cardColorStart}, ${this.config.cardColorEnd});
883
+ background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
873
884
  overflow: hidden;
874
885
  }
875
886
 
@@ -1257,30 +1268,41 @@ class GenerateImg extends koishi_1.Service {
1257
1268
  </body>
1258
1269
  </html>
1259
1270
  `;
1260
- // 判断渲染方式
1261
- if (this.config.renderType) { // 为1则为真,进入page模式
1262
- const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
1263
- const page = await this.ctx.puppeteer.page();
1264
- await page.goto(htmlPath);
1265
- await page.setContent(html, { waitUntil: 'networkidle0' });
1266
- const elementHandle = await page.$('html');
1267
- const boundingBox = await elementHandle.boundingBox();
1268
- const buffer = await page.screenshot({
1269
- type: 'png',
1270
- clip: {
1271
- x: boundingBox.x,
1272
- y: boundingBox.y,
1273
- width: boundingBox.width,
1274
- height: boundingBox.height
1271
+ // 多次尝试生成图片
1272
+ let attempts = 3;
1273
+ for (let i = 0; i < attempts; i++) {
1274
+ try {
1275
+ // 判断渲染方式
1276
+ if (this.giConfig.renderType) { // 为1则为真,进入page模式
1277
+ const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
1278
+ const page = await this.ctx.puppeteer.page();
1279
+ await page.goto(htmlPath);
1280
+ await page.setContent(html, { waitUntil: 'networkidle0' });
1281
+ const elementHandle = await page.$('html');
1282
+ const boundingBox = await elementHandle.boundingBox();
1283
+ const buffer = await page.screenshot({
1284
+ type: 'png',
1285
+ clip: {
1286
+ x: boundingBox.x,
1287
+ y: boundingBox.y,
1288
+ width: boundingBox.width,
1289
+ height: boundingBox.height
1290
+ }
1291
+ });
1292
+ await elementHandle.dispose();
1293
+ await page.close();
1294
+ return { buffer, link };
1295
+ }
1296
+ // 使用render模式渲染
1297
+ const pic = await this.ctx.puppeteer.render(html);
1298
+ return { pic, link };
1299
+ }
1300
+ catch (e) {
1301
+ if (i === attempts - 1) { // 已尝试三次
1302
+ throw new Error('生成图片失败!错误: ' + e.toString());
1275
1303
  }
1276
- });
1277
- await elementHandle.dispose();
1278
- await page.close();
1279
- return { buffer, link };
1304
+ }
1280
1305
  }
1281
- // 使用render模式渲染
1282
- const pic = await this.ctx.puppeteer.render(html);
1283
- return { pic, link };
1284
1306
  }
1285
1307
  async getLiveStatus(time, liveStatus) {
1286
1308
  let titleStatus;
@@ -1314,7 +1336,7 @@ class GenerateImg extends koishi_1.Service {
1314
1336
  // 获取Unix时间戳(以毫秒为单位)
1315
1337
  const unixTime = date.getTime() / 1000;
1316
1338
  // 获取当前Unix时间戳
1317
- const now = await this.ctx.biliAPI.getServerUTCTime();
1339
+ const now = this.ctx.biliAPI.getTimeOfUTC8();
1318
1340
  // 计算时间差(以秒为单位)
1319
1341
  const differenceInSeconds = Math.floor(now - unixTime);
1320
1342
  // 获取yyyy:MM:dd HH:mm:ss
package/lib/wbi.d.ts CHANGED
@@ -5,7 +5,7 @@ declare module 'koishi' {
5
5
  }
6
6
  }
7
7
  declare class Wbi extends Service {
8
- config: Wbi.Config;
8
+ wbiConfig: Wbi.Config;
9
9
  mixinKeyEncTab: number[];
10
10
  constructor(ctx: Context, config: Wbi.Config);
11
11
  protected start(): void | Promise<void>;
package/lib/wbi.js CHANGED
@@ -7,7 +7,7 @@ const koishi_1 = require("koishi");
7
7
  const md5_1 = __importDefault(require("md5"));
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
9
  class Wbi extends koishi_1.Service {
10
- config;
10
+ wbiConfig;
11
11
  mixinKeyEncTab = [
12
12
  46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
13
13
  33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
@@ -16,7 +16,7 @@ class Wbi extends koishi_1.Service {
16
16
  ];
17
17
  constructor(ctx, config) {
18
18
  super(ctx, 'wbi');
19
- this.config = config;
19
+ this.wbiConfig = config;
20
20
  }
21
21
  start() {
22
22
  // this.logger.info('wbi已被注册到Context中')
@@ -62,7 +62,7 @@ class Wbi extends koishi_1.Service {
62
62
  }
63
63
  encrypt(text, secretKey) {
64
64
  const iv = crypto_1.default.randomBytes(16);
65
- const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(this.config.key), iv);
65
+ const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(this.wbiConfig.key), iv);
66
66
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
67
67
  return iv.toString('hex') + ':' + encrypted.toString('hex');
68
68
  }
@@ -70,7 +70,7 @@ class Wbi extends koishi_1.Service {
70
70
  let textParts = text.split(':');
71
71
  let iv = Buffer.from(textParts.shift(), 'hex');
72
72
  let encryptedText = Buffer.from(textParts.join(':'), 'hex');
73
- let decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(this.config.key), iv);
73
+ let decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(this.wbiConfig.key), iv);
74
74
  let decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
75
75
  return decrypted.toString();
76
76
  }
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.2.0-alpha.3",
4
+ "version": "1.2.0-alpha.5",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -24,21 +24,23 @@
24
24
  "bilibili"
25
25
  ],
26
26
  "peerDependencies": {
27
- "koishi": "^4.16.8"
27
+ "koishi": "^4.17.1"
28
28
  },
29
29
  "dependencies": {
30
30
  "axios": "^1.6.7",
31
31
  "axios-cookiejar-support": "^5.0.0",
32
32
  "jsdom": "^24.0.0",
33
+ "luxon": "^3.4.4",
33
34
  "md5": "^2.3.0",
34
35
  "qrcode": "^1.5.3",
35
36
  "tough-cookie": "^4.1.3"
36
37
  },
37
38
  "devDependencies": {
39
+ "@types/luxon": "^3",
38
40
  "@types/md5": "^2",
39
41
  "@types/qrcode": "^1",
40
42
  "@types/tough-cookie": "^4",
41
- "koishi-plugin-puppeteer": "^3.7.3"
43
+ "koishi-plugin-puppeteer": "^3.8.2"
42
44
  },
43
45
  "koishi": {
44
46
  "service": {
package/readme.md CHANGED
@@ -104,6 +104,8 @@
104
104
  - ver 1.2.0-alpha.1 对推送进行了改进:在开启直播开播艾特全体成员的情况下,发送图片后才会艾特全体成员
105
105
  - ver 1.2.0-alpha.2 支持QQ群多群推送(实验性),修复了一些bug
106
106
  - ver 1.2.0-alpha.3 修复了指定QQ群订阅时的一个bug
107
+ - ver 1.2.0-alpha.4 对时间获取进行了优化,能够适应不同环境下的时间获取,修复了一些bug
108
+ - ver 1.2.0-alpha.5 修复了与PostgreSQL不兼容的问题,优化了图片推送,增强了推送容错
107
109
 
108
110
  ## 感谢
109
111