diff --git a/lib/core/monitor.js b/lib/core/monitor.js index eb9236c..011470d 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -324,7 +324,10 @@ class Monitor extends Searcher { await try_for_each(protoLotteryInfo, async function (lottery_info) { const { lottery_info_type, is_liked, - uids, uname, dyid, reserve_id, reserve_lottery_text, create_time, + uids, uname, dyid, reserve_id, + reserve_lottery_text, + is_charge_lottery, + create_time, ctrl, rid, des, type, hasOfficialLottery } = lottery_info; @@ -350,6 +353,11 @@ class Monitor extends Searcher { return false } + if (is_charge_lottery) { + log.info("筛选动态", `充电抽奖(https://t.bilibili.com/${dyid})`) + return false + } + const [m_uid, ori_uid] = uids, mIsFollowed = !m_uid || (new RegExp(m_uid)).test(attentionList), diff --git a/lib/core/searcher.js b/lib/core/searcher.js index f2bfad1..b8fd1a7 100644 --- a/lib/core/searcher.js +++ b/lib/core/searcher.js @@ -20,6 +20,7 @@ const { log } = utils * @property {string} description * @property {string} reserve_id * @property {string} reserve_lottery_text + * @property {boolean} is_charge_lottery * @property {boolean} hasOfficialLottery * @property {Array>} ctrl * @property {number} origin_create_time 10 @@ -31,6 +32,7 @@ const { log } = utils * @property {string} origin_description * @property {string} origin_reserve_id * @property {string} origin_reserve_lottery_text + * @property {boolean} origin_is_charge_lottery * @property {boolean} origin_hasOfficialLottery * * 整理后的抽奖信息 @@ -44,6 +46,7 @@ const { log } = utils * @property {string} dyid * @property {string} reserve_id * @property {string} reserve_lottery_text + * @property {boolean} is_charge_lottery * @property {string} rid * @property {string} des * @property {number} type @@ -96,6 +99,9 @@ function parseDynamicCard(dynamic_detail_card) { obj.reserve_lottery_text = text; } } + if (JSON.stringify(add_on_card_info).match(/充电专属抽奖/)) { + obj.is_charge_lottery = true + } /* 是否有官方抽奖 */ obj.hasOfficialLottery = extension && extension.lott && true; /* 转发者的描述 纯文字内容 图片动态描述 后两个分别是视频动态的描述和视频本身的描述*/ @@ -131,6 +137,9 @@ function parseDynamicCard(dynamic_detail_card) { obj.origin_reserve_lottery_text = text; } } + if (JSON.stringify(add_on_card_info).match(/充电专属抽奖/)) { + obj.origin_is_charge_lottery = true + } /* 是否有官方抽奖 */ obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott; /* 被转发者的name */ @@ -256,6 +265,7 @@ class Searcher { return ({ allModifyDynamicResArray, offset }); } + /** * 获取最新动态信息(转发子动态) * 并初步整理 @@ -307,6 +317,7 @@ class Searcher { dyid: cur.origin_dynamic_id, reserve_id: cur.origin_reserve_id, reserve_lottery_text: cur.origin_reserve_lottery_text, + is_charge_lottery: cur.origin_is_charge_lottery, rid: cur.origin_rid_str, des: cur.origin_description, type: cur.orig_type, @@ -320,6 +331,7 @@ class Searcher { return fomatdata; } + /** * 获取tag下的抽奖信息(转发母动态) * 并初步整理 @@ -367,6 +379,7 @@ class Searcher { dyid: o.dynamic_id, reserve_id: o.reserve_id, reserve_lottery_text: o.reserve_lottery_text, + is_charge_lottery: o.is_charge_lottery, rid: o.rid_str, des: o.description, type: o.type, @@ -377,6 +390,7 @@ class Searcher { return fomatdata } + /** * 从专栏中获取抽奖信息 * @param {string} key_words @@ -457,6 +471,7 @@ class Searcher { dyid: o.dynamic_id, reserve_id: o.reserve_id, reserve_lottery_text: o.reserve_lottery_text, + is_charge_lottery: o.is_charge_lottery, rid: o.rid_str, des: o.description, type: o.type, @@ -548,5 +563,4 @@ class Searcher { } } - -module.exports = { Searcher }; +module.exports = { Searcher, parseDynamicCard }; diff --git a/lib/net/http.js b/lib/net/http.js index ae2d2a4..fb18b2e 100644 --- a/lib/net/http.js +++ b/lib/net/http.js @@ -1,4 +1,3 @@ -//@ts-check /** * @typedef {import("http").IncomingHttpHeaders} HttpHeaders 头部信息 * diff --git a/test/api.test.js b/test/api.test.js index 7e8655b..f4c6426 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -5,7 +5,7 @@ const util = require('./util'); (async () => { assert(await bili_client.getMyinfo()); - await util.par_run([ + await util.par_run([0, 1, 2, 3, 4], [ async () => { assert.equal((await bili_client.getTopRcmd()).length, 10) }, @@ -32,7 +32,7 @@ const util = require('./util'); assert.notEqual(await bili_client.sendChat("703886913053917267", "t", 17), 1) }, async () => { - // assert(!await bili_client.createDynamic("123")) + assert(!await bili_client.createDynamic("1")) } ]) diff --git a/test/dynamic_card.test.js b/test/dynamic_card.test.js new file mode 100644 index 0000000..87e7cac --- /dev/null +++ b/test/dynamic_card.test.js @@ -0,0 +1,17 @@ +const assert = require('assert'); +const bili_client = require("../lib/net/bili"); +const searcher = require("../lib/core/searcher"); + +(async () => { + assert(await bili_client.getMyinfo()); + + let info = await bili_client.getOneDynamicByDyid("728424890210713624"); + + assert(searcher.parseDynamicCard(info).is_charge_lottery); + + info = await bili_client.getOneDynamicByDyid("728455586333589522"); + + assert(searcher.parseDynamicCard(info).origin_is_charge_lottery); + + console.log("dynamic_card.test ... ok!"); +})() \ No newline at end of file diff --git a/test/util.js b/test/util.js index b78f7f5..9b10195 100644 --- a/test/util.js +++ b/test/util.js @@ -1,8 +1,11 @@ /** + * @param {Array} nums * @param {Array<()=>any>} fns */ -function par_run(fns) { - return Promise.all((fns.map(fn => fn()))) +function par_run(nums, fns) { + return Promise.all( + nums.map(num => fns[num]()) + ) } module.exports = {