feat: 源uid参与筛选判断

- 重构筛选处关于uid的逻辑
- debug日志详细化
This commit is contained in:
shanmite 2021-12-02 17:53:49 +08:00
parent a19739d2d8
commit 2f26a393ca
4 changed files with 49 additions and 44 deletions

View File

@ -6,13 +6,8 @@ on:
- main - main
paths: paths:
- "lib/**" - "lib/**"
- "main.js" - "*.js"
pull_request: - "*.json"
branches:
- main
paths:
- "lib/**"
- "main.js"
workflow_dispatch: workflow_dispatch:
jobs: jobs:

View File

@ -1,20 +1,15 @@
name: "Package Node.js project into an executable" name: "Package Node.js project into an executable"
on: on:
push: push:
branches: branches:
- main - main
paths: paths:
- "lib/**" - "lib/**"
- "main.js" - "*.js"
pull_request: - "*.json"
branches:
- main
paths:
- "lib/**"
- "main.js"
workflow_dispatch: workflow_dispatch:
branches:
- main
jobs: jobs:
build_all: build_all:
runs-on: ubuntu-latest runs-on: ubuntu-latest

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ node_modules/
tests/ tests/
dyids/ dyids/
dist/ dist/
*.log
package-lock.json package-lock.json
env.js env.js
my_config.js my_config.js

View File

@ -188,8 +188,6 @@ class Monitor extends Searcher {
log.info('筛选动态', `开始筛选(${protoLotteryInfo.length})`); log.info('筛选动态', `开始筛选(${protoLotteryInfo.length})`);
log.debug('未进行筛选的动态信息', protoLotteryInfo);
/** 所有抽奖信息 */ /** 所有抽奖信息 */
let alllotteryinfo = []; let alllotteryinfo = [];
const const
@ -235,28 +233,36 @@ class Monitor extends Searcher {
} }
/* 检查动态是否满足要求 */ /* 检查动态是否满足要求 */
await try_for_each(protoLotteryInfo, async function ({ await try_for_each(protoLotteryInfo, async function (lottery_info) {
lottery_info_type, is_liked, const {
uids, uname, dyid, create_time, lottery_info_type, is_liked,
ctrl, rid, des, type, uids, uname, dyid, create_time,
hasOfficialLottery ctrl, rid, des, type,
}) { hasOfficialLottery
} = lottery_info;
log.debug('正在筛选的动态信息', lottery_info);
/* 遇到转发过就退出 */ /* 遇到转发过就退出 */
if (is_liked) { if (is_liked) {
log.info("筛选动态", `已转发(${dyid})`) log.info("筛选动态", `已转发(https://t.bilibili.com/${dyid})`)
return false return false
} }
/* 超过指定时间退出 */ /* 超过指定时间退出 */
if (now_ts - create_time > max_create_time * 86400) { if (now_ts - create_time > max_create_time * 86400) {
log.info("筛选动态", `过时动态(${dyid})`) log.info("筛选动态", `过时动态(https://t.bilibili.com/${dyid})`)
return false return false
} }
const const
/**判断是转发源动态还是现动态 */ [m_uid, ori_uid] = uids,
uid = lottery_info_type === 'uid' ? uids[1] : uids[0], mIsFollowed = m_uid && (new RegExp(m_uid)).test(attentionList),
isFollowed = (new RegExp(uid)).test(attentionList), oriIsFollowed = ori_uid && (new RegExp(ori_uid)).test(attentionList),
/**判断是转发源动态还是现动态 实际发奖人*/
[real_uid, realIsFollowed] = lottery_info_type === 'uid'
? [ori_uid, oriIsFollowed]
: [m_uid, mIsFollowed],
description = typeof des === 'string' ? des : '', description = typeof des === 'string' ? des : '',
needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description), needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description),
needTopic = [...new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#|(?<=[带加上])#.+?#(?=话题|tag)/ig) || [])].join(' '), needTopic = [...new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#|(?<=[带加上])#.+?#(?=话题|tag)/ig) || [])].join(' '),
@ -273,25 +279,32 @@ class Monitor extends Searcher {
|| (hasOfficialLottery && chatmodel[0] === '1') || (hasOfficialLottery && chatmodel[0] === '1')
|| (!hasOfficialLottery && chatmodel[1] === '1'); || (!hasOfficialLottery && chatmodel[1] === '1');
log.debug("筛选动态", { real_uid, mIsFollowed, oriIsFollowed, realIsFollowed, needAt, needTopic, isRelayDynamic, isTwoLevelDynamic, key_words, has_key_words, isBlock, isLottery, isSendChat })
/**屏蔽词 */ /**屏蔽词 */
if (isBlock) { if (isBlock) {
log.info("筛选动态", `包含屏蔽词(${dyid})`) log.info("筛选动态", `包含屏蔽词(https://t.bilibili.com/${dyid})`)
return false return false
} }
/**若勾选只转已关注 */ /**若勾选只转已关注 */
if (only_followed && !isFollowed) { if (only_followed && !mIsFollowed && !oriIsFollowed) {
log.info("筛选动态", `只转已关注(${dyid})`) log.info("筛选动态", `只转已关注(https://t.bilibili.com/${dyid})`)
return false return false
} }
/* 获取黑名单并去重合并 */ /* 获取黑名单并去重合并 */
const { blacklist: remote_blacklist } = global_var.get("remoteconfig") const
, new_blacklist = remote_blacklist { blacklist: remote_blacklist } = global_var.get("remoteconfig"),
? [...new Set([...blacklist.split(','), ...remote_blacklist.split(',')])].join() new_blacklist = remote_blacklist
? [
...new Set([...blacklist.split(','),
...remote_blacklist.split(',')])
].join()
: blacklist; : blacklist;
if ((new RegExp(dyid + '|' + uid)).test(new_blacklist)) {
log.info("筛选动态", `黑名单用户(${dyid})`) if ((new RegExp(dyid + '|' + m_uid + '|' + ori_uid)).test(new_blacklist)) {
log.info("筛选动态", `黑名单用户(https://t.bilibili.com/${dyid})`)
return false return false
} }
@ -304,8 +317,8 @@ class Monitor extends Searcher {
/**初始化待关注列表 */ /**初始化待关注列表 */
onelotteryinfo.uid = [] onelotteryinfo.uid = []
if (!isFollowed) { if (!realIsFollowed) {
onelotteryinfo.uid.push(uid); onelotteryinfo.uid.push(real_uid);
} }
onelotteryinfo.dyid = dyid; onelotteryinfo.dyid = dyid;
@ -335,12 +348,12 @@ class Monitor extends Searcher {
} }
/* 是否是转发的动态 */ /* 是否是转发的动态 */
if (isRelayDynamic) { if (isRelayDynamic && real_uid) {
/* 转发内容长度+'//'+'@'+用户名+':'+源内容 */ /* 转发内容长度+'//'+'@'+用户名+':'+源内容 */
const addlength = RandomStr.length + 2 + uname.length + 1 + 1; const addlength = RandomStr.length + 2 + uname.length + 1 + 1;
onelotteryinfo.relay_chat = RandomStr + `//@${uname}:` + des; onelotteryinfo.relay_chat = RandomStr + `//@${uname}:` + des;
new_ctrl.push({ new_ctrl.push({
data: String(uid), data: String(real_uid),
location: RandomStr.length + 2, location: RandomStr.length + 2,
length: uname.length + 1, length: uname.length + 1,
type: 1 type: 1
@ -349,8 +362,9 @@ class Monitor extends Searcher {
item.location += addlength; item.location += addlength;
return item; return item;
}).forEach(it => new_ctrl.push(it)) }).forEach(it => new_ctrl.push(it))
if (!(new RegExp(uids[1])).test(attentionList)) if (!oriIsFollowed) {
onelotteryinfo.uid.push(uids[1]); onelotteryinfo.uid.push(ori_uid);
}
} else { } else {
onelotteryinfo.relay_chat = RandomStr; onelotteryinfo.relay_chat = RandomStr;
} }
@ -372,7 +386,7 @@ class Monitor extends Searcher {
alllotteryinfo.push(onelotteryinfo); alllotteryinfo.push(onelotteryinfo);
} else { } else {
log.info("筛选动态", `非抽奖动态(${dyid})`) log.info("筛选动态", `非抽奖动态(https://t.bilibili.com/${dyid})`)
} }
}) })