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
paths:
- "lib/**"
- "main.js"
pull_request:
branches:
- main
paths:
- "lib/**"
- "main.js"
- "*.js"
- "*.json"
workflow_dispatch:
jobs:

View File

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

1
.gitignore vendored
View File

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

View File

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