From 881923ba545c3687b3d8f80c368c8deb97624c0a Mon Sep 17 00:00:00 2001 From: shanmite Date: Wed, 15 Feb 2023 15:05:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E5=A5=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=92=8C=E7=B2=89=E4=B8=9D=E6=95=B0=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20(#253)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed #253 --- lib/core/monitor.js | 26 ++++++++++++++------------ lib/net/bili.js | 28 +++++++++++++++++----------- test/api.test.js | 5 +++-- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/core/monitor.js b/lib/core/monitor.js index 5e49a5d..43331d3 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -91,12 +91,6 @@ class Monitor extends Searcher { case 5001: event_bus.emit('Turn_off_the_Monitor', '转发失败') break - case 6001: - event_bus.emit('Turn_off_the_Monitor', '获取开奖时间失败') - break - case 7001: - event_bus.emit('Turn_off_the_Monitor', '获取关注数失败') - break default: event_bus.emit('Turn_off_the_Monitor', `??? 未知错误: ${status}`) break; @@ -135,9 +129,16 @@ class Monitor extends Searcher { if (lottery.isOfficialLottery) { let { ts } = await bili.getLotteryNotice(lottery.dyid); const ts_10 = Date.now() / 1000; - if (ts < 0) { - status = 6001 - break; + if (ts === -1) { + log.warn('过滤', '无法判断开奖时间') + await delay(filter_wait) + continue + } + if (ts === -9999) { + log.info('过滤', '已撤销抽奖') + d_storage.updateDyid(lottery.dyid) + await delay(filter_wait) + continue } if (ts < ts_10) { log.info('过滤', '已过开奖时间') @@ -155,9 +156,10 @@ class Monitor extends Searcher { const { minfollower } = config if (minfollower > 0) { const followerNum = await bili.getUserInfo(lottery.uid[0]); - if (followerNum < 0) { - status = 7001 - break; + if (followerNum === -1) { + log.warn('过滤', `粉丝数(${followerNum})获取失败`) + await delay(filter_wait) + continue } if (followerNum < minfollower) { log.info('过滤', `粉丝数(${followerNum})小于指定数量`) diff --git a/lib/net/bili.js b/lib/net/bili.js index e2f8e6f..eefa2b7 100644 --- a/lib/net/bili.js +++ b/lib/net/bili.js @@ -578,7 +578,7 @@ const bili_client = { if (res.code === 0) { return [false, res.data.follower, 'ok']; } else { - return [true, 1, `出错 可能是访问过频繁\n${responseText}`] + return [true, -1, `出错 可能是访问过频繁\n${responseText}`] } }), /** @@ -594,7 +594,7 @@ const bili_client = { * @param {string} dyid * 动态id * @typedef LotteryNotice - * @property {number | -1} ts + * @property {number} ts * @returns {Promise} 开奖时间 */ async getLotteryNotice(dyid) { @@ -606,15 +606,21 @@ const bili_client = { } }), res = strToJson(responseText); - if (res.code === 0) { - return { - ts: res.data.lottery_time - }; - } else { - log.error('获取开奖信息', `失败\n${responseText}`); - return { - ts: -1 - }; + switch (res.code) { + case 0: + return { + ts: res.data.lottery_time + }; + case -9999: + log.warn('获取开奖信息', `${dyid}已撤销抽奖`); + return { + ts: -9999 + }; + default: + log.error('获取开奖信息', `${dyid}失败\n${responseText}`); + return { + ts: -1 + }; } }, _autoAttention: new Line('自动关注', [ diff --git a/test/api.test.js b/test/api.test.js index 93b4751..82e9e89 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -1,6 +1,7 @@ const assert = require('assert'); const bili_client = require("../lib/net/bili"); const util = require('./util'); +const { parseDynamicCard } = require('../lib/core/searcher'); (async () => { assert(await bili_client.getMyinfo()); @@ -13,7 +14,7 @@ const util = require('./util'); // 1 async () => { assert.equal(await bili_client.sendChat( - (await bili_client.getOneDynamicByDyid("692193323569381399")).desc.rid, + parseDynamicCard(await bili_client.getOneDynamicByDyid("692193323569381399")).rid_str, "test", 11), 7 @@ -22,7 +23,7 @@ const util = require('./util'); // 2 async () => { assert.equal(await bili_client.sendChat( - (await bili_client.getOneDynamicByDyid("11229466874154064")).desc.rid, + parseDynamicCard(await bili_client.getOneDynamicByDyid("11229466874154064")).rid_str, "test", 1), 3