koishi-plugin-bilibili-notify 1.0.0-alpha.0 → 1.0.0-beta.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.
@@ -282,6 +282,10 @@ class ComRegister {
282
282
  liveMsg = await this.checkIfNeedSub(options.live, '直播', session, data);
283
283
  // 判断是否需要订阅动态
284
284
  dynamicMsg = await this.checkIfNeedSub(options.dynamic, '动态', session);
285
+ // 判断是否未订阅任何消息
286
+ if (!liveMsg && !dynamicMsg) {
287
+ return '您未订阅该UP的任何消息';
288
+ }
285
289
  // 判断是哪个平台
286
290
  let platform;
287
291
  if (!guildId) { // 没有输入群号,默认当前聊天环境
@@ -314,7 +318,7 @@ class ComRegister {
314
318
  // 保存到数据库中
315
319
  const sub = await ctx.database.create('bilibili', {
316
320
  uid: mid,
317
- room_id: data.live_room.roomid.toString(),
321
+ room_id: data.live_room?.roomid.toString(),
318
322
  dynamic: dynamicMsg ? 1 : 0,
319
323
  video: 1,
320
324
  live: liveMsg ? 1 : 0,
@@ -330,7 +334,7 @@ class ComRegister {
330
334
  id: sub.id,
331
335
  uid: mid,
332
336
  targetId: guildId,
333
- roomId: data.live_room.roomid.toString(),
337
+ roomId: data.live_room?.roomid.toString(),
334
338
  live: liveMsg,
335
339
  dynamic: dynamicMsg,
336
340
  liveDispose: null,
@@ -474,11 +478,18 @@ class ComRegister {
474
478
  dynamicDetect(ctx, bot, guildId, uid) {
475
479
  let firstSubscription = true;
476
480
  let timePoint;
481
+ // Test code
482
+ // let timer = 0
477
483
  return async () => {
484
+ // Test code
485
+ /* console.log('timer:' + timer++);
486
+ console.log('firstSubscription:' + firstSubscription);
487
+ console.log(`timePoint: ${timePoint}`);
488
+ console.log(`timePoint: ${ctx.gimg.unixTimestampToString(timePoint)}`); */
478
489
  // 第一次订阅判断
479
490
  if (firstSubscription) {
480
491
  // 设置第一次的时间点
481
- timePoint = Date.now();
492
+ timePoint = Math.floor(Date.now() / 1000);
482
493
  // 设置第一次为false
483
494
  firstSubscription = false;
484
495
  return;
@@ -512,6 +523,8 @@ class ComRegister {
512
523
  // 没有动态内容则直接跳过
513
524
  if (!items[num])
514
525
  continue;
526
+ // Test code
527
+ // console.log(`items[${num}].modules.module_author.pub_ts: ${ctx.gimg.unixTimestampToString(items[num].modules.module_author.pub_ts)}`);
515
528
  // 寻找发布时间比时间点时间更晚的动态
516
529
  if (items[num].modules.module_author.pub_ts > timePoint) {
517
530
  // 如果这是遍历的最后一条,将时间点设置为这条动态的发布时间
@@ -651,7 +664,8 @@ class ComRegister {
651
664
  }
652
665
  async checkIfNeedSub(comNeed, subType, session, data) {
653
666
  if (comNeed) {
654
- if (subType === '直播' && data.live_room.roomStatus === 0) {
667
+ if (subType === '直播' && !data.live_room) {
668
+ await session.send('该用户未开通直播间,无法订阅直播');
655
669
  return false;
656
670
  }
657
671
  return true;
@@ -668,8 +682,8 @@ class ComRegister {
668
682
  switch (input) {
669
683
  case 'y': { // 需要订阅直播
670
684
  // 如果用户没有开通直播间则无法订阅
671
- if (subType === '直播' && data.live_room.roomStatus === 0) {
672
- await session.send('该用户没有开通直播间,无法订阅直播');
685
+ if (subType === '直播' && !data.live_room) {
686
+ await session.send('该用户未开通直播间,无法订阅直播');
673
687
  return false;
674
688
  }
675
689
  // 开启直播订阅
@@ -805,8 +819,8 @@ class ComRegister {
805
819
  (function (ComRegister) {
806
820
  ComRegister.Config = koishi_1.Schema.object({
807
821
  pushTime: koishi_1.Schema.number().required(),
808
- liveLoopTime: koishi_1.Schema.number().default(5),
809
- dynamicLoopTime: koishi_1.Schema.number().default(60)
822
+ liveLoopTime: koishi_1.Schema.number().default(10),
823
+ dynamicLoopTime: koishi_1.Schema.number().default(30)
810
824
  });
811
825
  })(ComRegister || (ComRegister = {}));
812
826
  exports.default = ComRegister;
package/lib/index.js CHANGED
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.apply = exports.Config = exports.name = void 0;
30
30
  const koishi_1 = require("koishi");
31
31
  // import crypto
32
- const crypto_1 = __importDefault(require("crypto"));
32
+ // import crypto from 'crypto'
33
33
  // import plugins
34
34
  // import Authority from './authority'
35
35
  const comRegister_1 = __importDefault(require("./comRegister"));
@@ -82,6 +82,6 @@ function apply(ctx, config) {
82
82
  });
83
83
  }
84
84
  exports.apply = apply;
85
- function generateKey() {
86
- return crypto_1.default.randomBytes(32).toString('hex');
87
- }
85
+ /* function generateKey(): string {
86
+ return crypto.randomBytes(32).toString('hex');
87
+ } */
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.0-alpha.0",
4
+ "version": "1.0.0-beta.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -44,6 +44,12 @@
44
44
  },
45
45
  "koishi": {
46
46
  "preview": true,
47
+ "service": {
48
+ "required": [
49
+ "database",
50
+ "puppeteer"
51
+ ]
52
+ },
47
53
  "description": {
48
54
  "zh": "开发中的Bilibili直播通知,动态推送插件。目前还只是个雏形,不建议使用,发布做测试用"
49
55
  },
package/readme.md CHANGED
@@ -2,4 +2,14 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/koishi-plugin-bilibili-notify?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
4
4
 
5
- Koishi bilibili notify plugin
5
+ 此插件依赖于"database"和"puppeteer"服务,同时受权限控制,需要具备authority:3及以上的权限才能使用本插件提供的指令,你可以参考下面链接中的方法得到一个超级管理员账号(具有authority:5的最高权限)
6
+ https://koishi.chat/zh-CN/manual/usage/platform.html#%E9%85%8D%E7%BD%AE%E7%99%BB%E5%BD%95%E6%8F%92%E4%BB%B6
7
+
8
+ 您还可以安装admin插件,给其他用户授予权限,操作方法请参考下面的链接
9
+ https://koishi.chat/zh-CN/manual/usage/customize.html
10
+
11
+ 指令使用方法请参考 help bili,子命令使用方法请加-h,例如bili login -h
12
+
13
+ 本插件功能均建立在B站账号登录之上,所有操作之前请先登录
14
+
15
+ 登录方式为二维码,输入命令bili login之后扫码登录,您的登录凭证将存储在您的本地数据库,并由您自己填写的密钥加密,所以请保管好你的密钥