koishi-plugin-bilibili-notify 1.0.0-alpha.1 → 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.
- package/lib/comRegister.js +22 -8
- package/package.json +1 -1
package/lib/comRegister.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
809
|
-
dynamicLoopTime: koishi_1.Schema.number().default(
|
|
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;
|