fix: 开奖时间和粉丝数判断逻辑 (#253)

Fixed #253
This commit is contained in:
shanmite 2023-02-15 15:05:18 +08:00
parent 097e2d61e7
commit 881923ba54
3 changed files with 34 additions and 25 deletions

View File

@ -91,12 +91,6 @@ class Monitor extends Searcher {
case 5001: case 5001:
event_bus.emit('Turn_off_the_Monitor', '转发失败') event_bus.emit('Turn_off_the_Monitor', '转发失败')
break break
case 6001:
event_bus.emit('Turn_off_the_Monitor', '获取开奖时间失败')
break
case 7001:
event_bus.emit('Turn_off_the_Monitor', '获取关注数失败')
break
default: default:
event_bus.emit('Turn_off_the_Monitor', `??? 未知错误: ${status}`) event_bus.emit('Turn_off_the_Monitor', `??? 未知错误: ${status}`)
break; break;
@ -135,9 +129,16 @@ class Monitor extends Searcher {
if (lottery.isOfficialLottery) { if (lottery.isOfficialLottery) {
let { ts } = await bili.getLotteryNotice(lottery.dyid); let { ts } = await bili.getLotteryNotice(lottery.dyid);
const ts_10 = Date.now() / 1000; const ts_10 = Date.now() / 1000;
if (ts < 0) { if (ts === -1) {
status = 6001 log.warn('过滤', '无法判断开奖时间')
break; await delay(filter_wait)
continue
}
if (ts === -9999) {
log.info('过滤', '已撤销抽奖')
d_storage.updateDyid(lottery.dyid)
await delay(filter_wait)
continue
} }
if (ts < ts_10) { if (ts < ts_10) {
log.info('过滤', '已过开奖时间') log.info('过滤', '已过开奖时间')
@ -155,9 +156,10 @@ class Monitor extends Searcher {
const { minfollower } = config const { minfollower } = config
if (minfollower > 0) { if (minfollower > 0) {
const followerNum = await bili.getUserInfo(lottery.uid[0]); const followerNum = await bili.getUserInfo(lottery.uid[0]);
if (followerNum < 0) { if (followerNum === -1) {
status = 7001 log.warn('过滤', `粉丝数(${followerNum})获取失败`)
break; await delay(filter_wait)
continue
} }
if (followerNum < minfollower) { if (followerNum < minfollower) {
log.info('过滤', `粉丝数(${followerNum})小于指定数量`) log.info('过滤', `粉丝数(${followerNum})小于指定数量`)

View File

@ -578,7 +578,7 @@ const bili_client = {
if (res.code === 0) { if (res.code === 0) {
return [false, res.data.follower, 'ok']; return [false, res.data.follower, 'ok'];
} else { } else {
return [true, 1, `出错 可能是访问过频繁\n${responseText}`] return [true, -1, `出错 可能是访问过频繁\n${responseText}`]
} }
}), }),
/** /**
@ -594,7 +594,7 @@ const bili_client = {
* @param {string} dyid * @param {string} dyid
* 动态id * 动态id
* @typedef LotteryNotice * @typedef LotteryNotice
* @property {number | -1} ts * @property {number} ts
* @returns {Promise<LotteryNotice>} 开奖时间 * @returns {Promise<LotteryNotice>} 开奖时间
*/ */
async getLotteryNotice(dyid) { async getLotteryNotice(dyid) {
@ -606,15 +606,21 @@ const bili_client = {
} }
}), }),
res = strToJson(responseText); res = strToJson(responseText);
if (res.code === 0) { switch (res.code) {
return { case 0:
ts: res.data.lottery_time return {
}; ts: res.data.lottery_time
} else { };
log.error('获取开奖信息', `失败\n${responseText}`); case -9999:
return { log.warn('获取开奖信息', `${dyid}已撤销抽奖`);
ts: -1 return {
}; ts: -9999
};
default:
log.error('获取开奖信息', `${dyid}失败\n${responseText}`);
return {
ts: -1
};
} }
}, },
_autoAttention: new Line('自动关注', [ _autoAttention: new Line('自动关注', [

View File

@ -1,6 +1,7 @@
const assert = require('assert'); const assert = require('assert');
const bili_client = require("../lib/net/bili"); const bili_client = require("../lib/net/bili");
const util = require('./util'); const util = require('./util');
const { parseDynamicCard } = require('../lib/core/searcher');
(async () => { (async () => {
assert(await bili_client.getMyinfo()); assert(await bili_client.getMyinfo());
@ -13,7 +14,7 @@ const util = require('./util');
// 1 // 1
async () => { async () => {
assert.equal(await bili_client.sendChat( assert.equal(await bili_client.sendChat(
(await bili_client.getOneDynamicByDyid("692193323569381399")).desc.rid, parseDynamicCard(await bili_client.getOneDynamicByDyid("692193323569381399")).rid_str,
"test", "test",
11), 11),
7 7
@ -22,7 +23,7 @@ const util = require('./util');
// 2 // 2
async () => { async () => {
assert.equal(await bili_client.sendChat( assert.equal(await bili_client.sendChat(
(await bili_client.getOneDynamicByDyid("11229466874154064")).desc.rid, parseDynamicCard(await bili_client.getOneDynamicByDyid("11229466874154064")).rid_str,
"test", "test",
1), 1),
3 3