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:
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})小于指定数量`)

View File

@ -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<LotteryNotice>} 开奖时间
*/
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('自动关注', [

View File

@ -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