diff --git a/lib/core/monitor.js b/lib/core/monitor.js index 1dd2ee6..0639ea3 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -303,7 +303,7 @@ class Monitor extends Searcher { await try_for_each(protoLotteryInfo, async function (lottery_info) { const { lottery_info_type, is_liked, - uids, uname, dyid, reserve_id, create_time, + uids, uname, dyid, reserve_id, reserve_lottery_text, create_time, ctrl, rid, des, type, hasOfficialLottery } = lottery_info; @@ -342,7 +342,7 @@ class Monitor extends Searcher { needTopic = [...new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#|(?<=[带加上])#.+?#(?=话题|tag)/ig) || [])].join(' '), isRelayDynamic = type === 1, has_key_words = key_words.every(it => new RegExp(it).test(description)), - isBlock = new RegExp(blockword.join('|')).test(description), + isBlock = new RegExp(blockword.join('|')).test(description + reserve_lottery_text), isLottery = (is_imitator && lottery_info_type === 'uid' && model !== '00') || (hasOfficialLottery && model[0] === '1') @@ -368,43 +368,6 @@ class Monitor extends Searcher { log.debug("筛选动态", { real_uid, mIsFollowed, oriIsFollowed, realIsFollowed, needAt, needTopic, type, isRelayDynamic, key_words, has_key_words, blockword, isBlock, isLottery, isSendChat }) - if (block_dynamic_type.includes(type)) { - log.warn("筛选动态", `屏蔽动态类型 ${type}`) - return false - } - - if (reserve_id) { - if (disable_reserve_lottery) { - log.info("已关闭预约抽奖功能") - } else { - log.info("预约抽奖", "开始"); - if (hasEnv('NOT_GO_LOTTERY')) { - log.info('NOT_GO_LOTTERY', 'ON'); - } else { - await bili.reserve_lottery(reserve_id) - } - } - } - - if (!has_key_words && description) { - log.warn("筛选动态", `无关键词动态的描述: ${description}\n\n考虑是否修改设置key_words:\n${key_words.join('\n')}`) - return false - } - - /**屏蔽词 */ - if (isBlock) { - log.info("筛选动态", `包含屏蔽词(https://t.bilibili.com/${dyid})`) - return false - } - - /**若勾选只转已关注 */ - if (only_followed - && (!mIsFollowed || !oriIsFollowed) - ) { - log.info("筛选动态", `只转已关注(https://t.bilibili.com/${dyid})`) - return false - } - if ( new_blacklist.some(id => keys.some(key => { if (key + '' === id) { @@ -418,6 +381,44 @@ class Monitor extends Searcher { return false } + if (block_dynamic_type.includes(type)) { + log.warn("筛选动态", `屏蔽动态类型 ${type}`) + return false + } + + /**屏蔽词 */ + if (isBlock) { + log.info("筛选动态", `包含屏蔽词(https://t.bilibili.com/${dyid})`) + return false + } + + if (reserve_id) { + if (disable_reserve_lottery) { + log.info("已关闭预约抽奖功能") + } else { + log.info("预约抽奖", "开始"); + log.info("预约抽奖", `奖品: ${reserve_lottery_text}`); + if (hasEnv('NOT_GO_LOTTERY')) { + log.info('NOT_GO_LOTTERY', 'ON'); + } else { + await bili.reserve_lottery(reserve_id) + } + } + } + + if (!has_key_words && description) { + log.warn("筛选动态", `无关键词动态的描述: ${description}\n\n考虑是否修改设置key_words:\n${key_words.join('\n且满足: ')}`) + return false + } + + /**若勾选只转已关注 */ + if (only_followed + && (!mIsFollowed || !oriIsFollowed) + ) { + log.info("筛选动态", `只转已关注(https://t.bilibili.com/${dyid})`) + return false + } + if (isLottery) { const { uname_map = {} } = global_var.get("remoteconfig") let onelotteryinfo = {}; diff --git a/lib/core/searcher.js b/lib/core/searcher.js index cffffe6..42ae441 100644 --- a/lib/core/searcher.js +++ b/lib/core/searcher.js @@ -18,7 +18,8 @@ const { log } = utils * @property {string} dynamic_id * @property {number} type * @property {string} description - * @property {number} reserve_id + * @property {string} reserve_id + * @property {string} reserve_lottery_text * @property {boolean} hasOfficialLottery * @property {Array>} ctrl * @property {number} origin_create_time 10 @@ -28,7 +29,8 @@ const { log } = utils * @property {string} origin_dynamic_id * @property {number} orig_type * @property {string} origin_description - * @property {number} origin_reserve_id + * @property {string} origin_reserve_id + * @property {string} origin_reserve_lottery_text * @property {boolean} origin_hasOfficialLottery * * 整理后的抽奖信息 @@ -40,7 +42,8 @@ const { log } = utils * @property {string} uname * @property {Array<{}>} ctrl * @property {string} dyid - * @property {number} reserve_id + * @property {string} reserve_id + * @property {string} reserve_lottery_text * @property {string} rid * @property {string} des * @property {number} type @@ -53,12 +56,12 @@ function parseDynamicCard(dynamic_detail_card) { const { strToJson } = utils; /**临时储存单个动态中的信息 */ let obj = {}; - const { desc, card, extension, extend_json } = dynamic_detail_card + const { desc, card, extension, extend_json, display = {} } = dynamic_detail_card , { is_liked = 1, user_profile = {} } = desc , { info = {} } = user_profile - , extendjsonToJson = strToJson(extend_json) - , extendjsonToJsonHidden = extendjsonToJson[""] || {} , cardToJson = strToJson(card) + , extendjsonToJson = strToJson(extend_json) + , { add_on_card_info = [] } = display , { item } = cardToJson; /* 转发者的UID */ obj.uid = desc.uid @@ -79,17 +82,18 @@ function parseDynamicCard(dynamic_detail_card) { /* 定位@信息 */ obj.ctrl = (extendjsonToJson.ctrl) || []; /* 预约抽奖信息 */ - if (extendjsonToJsonHidden.reserve) { - let status = (((dynamic_detail_card || {}) - .display || {}) - .add_on_card_info || []) - .map(it => (((it || {}) - .reserve_attach_card || {}) - .reserve_button || {}) - .status || 2)[0]; + if (add_on_card_info.length > 0) { + const [status, oid_str, text] = add_on_card_info + .filter(it => typeof it.reserve_attach_card !== 'undefined' + && typeof it.reserve_attach_card.reserve_lottery !== 'undefined' + && typeof it.reserve_attach_card.reserve_button !== 'undefined') + .map(({ reserve_attach_card }) => [ + reserve_attach_card.reserve_button.status, + reserve_attach_card.oid_str, + reserve_attach_card.reserve_lottery.text])[0] || []; if (status === 1) { - let { reserve_id } = extendjsonToJsonHidden.reserve; - obj.reserve_id = reserve_id || 0; + obj.reserve_id = oid_str; + obj.reserve_lottery_text = text; } } /* 是否有官方抽奖 */ @@ -100,9 +104,9 @@ function parseDynamicCard(dynamic_detail_card) { || (cardToJson.dynamic || '' + cardToJson.desc || '') || ''; if (obj.type === 1) { - const { origin_extension, origin, origin_extend_json } = cardToJson + const { origin_extension, origin } = cardToJson , originToJson = strToJson(origin) - , originextendjsonToJson = strToJson(origin_extend_json) + , { add_on_card_info = [] } = display.origin || {} , { user, item } = originToJson; /* 源动态的ts10 */ obj.origin_create_time = desc.origin.timestamp; @@ -113,9 +117,19 @@ function parseDynamicCard(dynamic_detail_card) { /* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */ obj.origin_dynamic_id = desc.orig_dy_id_str; /* 预约抽奖信息 */ - if (originextendjsonToJson.reserve) { - let { reserve_id, reserve_lottery } = originextendjsonToJson.reserve; - obj.origin_reserve_id = reserve_lottery === 1 ? reserve_id : 0; + if (add_on_card_info.length > 0) { + const [status, oid_str, text] = add_on_card_info + .filter(it => typeof it.reserve_attach_card !== 'undefined' + && typeof it.reserve_attach_card.reserve_lottery !== 'undefined' + && typeof it.reserve_attach_card.reserve_button !== 'undefined') + .map(({ reserve_attach_card }) => [ + reserve_attach_card.reserve_button.status, + reserve_attach_card.oid_str, + reserve_attach_card.reserve_lottery.text])[0] || []; + if (status === 1) { + obj.origin_reserve_id = oid_str; + obj.origin_reserve_lottery_text = text; + } } /* 是否有官方抽奖 */ obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott; @@ -289,6 +303,7 @@ class Searcher { ctrl: [], dyid: cur.origin_dynamic_id, reserve_id: cur.origin_reserve_id, + reserve_lottery_text: cur.origin_reserve_lottery_text, rid: cur.origin_rid_str, des: cur.origin_description, type: cur.orig_type, @@ -348,6 +363,7 @@ class Searcher { ctrl: o.ctrl, dyid: o.dynamic_id, reserve_id: o.reserve_id, + reserve_lottery_text: o.reserve_lottery_text, rid: o.rid_str, des: o.description, type: o.type, @@ -437,6 +453,7 @@ class Searcher { ctrl: o.ctrl, dyid: o.dynamic_id, reserve_id: o.reserve_id, + reserve_lottery_text: o.reserve_lottery_text, rid: o.rid_str, des: o.description, type: o.type, diff --git a/lib/data/config.js b/lib/data/config.js index 261d9cb..9cf7449 100644 --- a/lib/data/config.js +++ b/lib/data/config.js @@ -26,6 +26,8 @@ const config = { * @property {string} uname * @property {Array<{}>} ctrl * @property {string} dyid + * @property {string} reserve_id + * @property {string} reserve_lottery_text * @property {string} rid * @property {string} des * @property {number} type diff --git a/my_config.example.js b/my_config.example.js index 2b4f7b8..d85ca5b 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -38,7 +38,8 @@ module.exports = Object.freeze({ * @property {string} uname * @property {Array<{}>} ctrl * @property {string} dyid - * @property {number} reserve_id + * @property {string} reserve_id + * @property {string} reserve_lottery_text * @property {string} rid * @property {string} des * @property {number} type