Skip to content

Commit

Permalink
update: improve comment bot filter
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Nov 30, 2024
1 parent 4ec24ed commit 95c4d7a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
8 changes: 7 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"recommendations": ["Vue.volar", "bradlc.vscode-tailwindcss"]
"recommendations": [
"Vue.volar",
"bradlc.vscode-tailwindcss",
"esbenp.prettier-vscode",
"stylelint.vscode-stylelint",
"dbaeumer.vscode-eslint"
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 4.0.12

- 更新:评论区过滤 增强召唤AI机器人屏蔽
- 更新:评论区过滤 收录更多AI机器人
- 更新:正则模式升级为 ius 模式,支持跨行匹配
- 优化:右键菜单样式

Expand Down
3 changes: 3 additions & 0 deletions src/modules/filters/variety/comment/extra/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ export const bots = [
'AI工具集', // 605801219
'Ai的评论', // 3546740500204293
'AI识片酱', // 1835753760
'AI知识总结', // 3546765074630961
]

export const botsSet = new Set(bots)
57 changes: 32 additions & 25 deletions src/modules/filters/variety/comment/pages/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isPageBangumi, isPageDynamic, isPagePlaylist, isPageVideo } from '@/uti
import ShadowInstance from '@/utils/shadow'
import { BiliCleanerStorage } from '@/utils/storage'
import { orderedUniq, showEle } from '@/utils/tool'
import { bots } from '../extra/bots'
import { bots, botsSet } from '../extra/bots'
import {
CommentBotFilter,
CommentCallBotFilter,
Expand Down Expand Up @@ -87,36 +87,43 @@ const GM_KEYS = {
}

// 一二级评论信息提取
// 测试视频:
// https://b23.tv/av810872
// https://b23.tv/av1855797296
// https://b23.tv/av1706101190
// https://b23.tv/av1705573085
// https://b23.tv/av1350214762
// https://b23.tv/av113195607985861
const selectorFns = {
// 测试视频:
// https://b23.tv/av810872
// https://b23.tv/av1855797296
// https://b23.tv/av1706101190
// https://b23.tv/av1705573085
// https://b23.tv/av1350214762
// https://b23.tv/av113195607985861
root: {
username: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.member?.uname?.trim()
},
content: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message?.replace(/@[^@\s]+/g, ' ').trim()
},
callBot: (comment: HTMLElement): SelectorResult => {
const members = (comment as any).__data?.content?.members
if (members?.length) {
return members.some((v: { uname: string }) => botsSet.has(v.uname))
}
return false
},
callUser: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.members[0]?.uname
return !!(comment as any).__data?.content?.members?.[0]
},
callUserNoReply: (comment: HTMLElement): SelectorResult => {
if ((comment as any).__data?.rcount !== 0) {
return undefined
return false
}
return (comment as any).__data?.content?.members[0]?.uname
return !!(comment as any).__data?.content?.members?.[0]
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message?.replace(/@[^@\s]+/g, ' ').trim() === ''
},
callUserOnlyNoReply: (comment: HTMLElement): SelectorResult => {
if ((comment as any).__data?.rcount !== 0) {
return undefined
return false
}
return (comment as any).__data?.content?.message?.replace(/@[^@\s]+/g, ' ').trim() === ''
},
Expand Down Expand Up @@ -171,21 +178,24 @@ const selectorFns = {
?.replace(/@[^@\s]+/g, ' ')
.trim()
},
callBot: (comment: HTMLElement): SelectorResult => {
const members = (comment as any).__data?.content?.members
if (members.length) {
return members.some((v: { uname: string }) => botsSet.has(v.uname))
}
return false
},
callUser: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message
return !!(comment as any).__data?.content?.message
?.trim()
?.replace(/^回复\s?@[^@\s]+\s?:/, '')
?.match(/@[^@\s]+/)?.[0]
.replace('@', '')
.trim()
?.match(/@[^@\s]+/)
},
callUserNoReply: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message
return !!(comment as any).__data?.content?.message
?.trim()
?.replace(/^回复\s?@[^@\s]+\s?:/, '')
?.match(/@[^@\s]+/)?.[0]
.replace('@', '')
.trim()
?.match(/@[^@\s]+/)
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (
Expand Down Expand Up @@ -274,9 +284,6 @@ class CommentFilterCommon implements IMainFilter {
this.commentContentFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.content.valueKey, []))
this.commentLevelFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.level.valueKey, 0))
this.commentBotFilter.setParam(bots)
this.commentCallBotFilter.setParam(bots)
this.commentCallUserFilter.setParam([`/./`])
this.commentCallUserNoReplyFilter.setParam([`/./`])
}

/**
Expand Down Expand Up @@ -348,7 +355,7 @@ class CommentFilterCommon implements IMainFilter {
this.commentContentFilter.isEnable && blackPairs.push([this.commentContentFilter, selectorFns.root.content])
this.commentLevelFilter.isEnable && blackPairs.push([this.commentLevelFilter, selectorFns.root.level])
this.commentBotFilter.isEnable && blackPairs.push([this.commentBotFilter, selectorFns.root.username])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.root.callUser])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.root.callBot])
this.commentCallUserFilter.isEnable && blackPairs.push([this.commentCallUserFilter, selectorFns.root.callUser])
this.commentCallUserNoReplyFilter.isEnable &&
blackPairs.push([this.commentCallUserNoReplyFilter, selectorFns.root.callUserNoReply])
Expand Down Expand Up @@ -438,7 +445,7 @@ class CommentFilterCommon implements IMainFilter {
this.commentContentFilter.isEnable && blackPairs.push([this.commentContentFilter, selectorFns.sub.content])
this.commentLevelFilter.isEnable && blackPairs.push([this.commentLevelFilter, selectorFns.sub.level])
this.commentBotFilter.isEnable && blackPairs.push([this.commentBotFilter, selectorFns.sub.username])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.sub.callUser])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.sub.callBot])
this.commentCallUserFilter.isEnable && blackPairs.push([this.commentCallUserFilter, selectorFns.sub.callUser])
this.commentCallUserNoReplyFilter.isEnable &&
blackPairs.push([this.commentCallUserNoReplyFilter, selectorFns.sub.callUserNoReply])
Expand Down
19 changes: 13 additions & 6 deletions src/modules/filters/variety/comment/pages/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { debugFilter as debug, error } from '@/utils/logger'
import { isPageSpace } from '@/utils/pageType'
import { BiliCleanerStorage } from '@/utils/storage'
import { orderedUniq, showEle, waitForEle } from '@/utils/tool'
import { bots } from '../extra/bots'
import { bots, botsSet } from '../extra/bots'
import {
CommentBotFilter,
CommentCallBotFilter,
Expand Down Expand Up @@ -84,6 +84,12 @@ const selectorFns = {
.replace(/@[^@\s]+/g, ' ')
.trim()
},
callBot: (comment: HTMLElement): SelectorResult => {
const members = Array.from(
comment.querySelectorAll<HTMLElement>('.root-reply-container .reply-content .jump-link.user'),
)
return members.some((v: HTMLElement) => botsSet.has(v.textContent!.replace('@', '')))
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.root-reply-container .reply-content .jump-link.user')
Expand Down Expand Up @@ -128,6 +134,10 @@ const selectorFns = {
?.replace(/@[^@\s]+/g, ' ')
.trim()
},
callBot: (comment: HTMLElement): SelectorResult => {
const members = Array.from(comment.querySelectorAll<HTMLElement>('.reply-content .jump-link.user'))
return members.some((v: HTMLElement) => botsSet.has(v.textContent!.replace('@', '')))
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.reply-content')
Expand Down Expand Up @@ -187,8 +197,6 @@ class CommentFilterLegacy implements IMainFilter {
this.commentContentFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.content.valueKey, []))
this.commentLevelFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.level.valueKey, 0))
this.commentBotFilter.setParam(bots)
this.commentCallBotFilter.setParam(bots)
this.commentCallUserFilter.setParam([`/./`])
}

async check(mode?: 'full' | 'incr') {
Expand Down Expand Up @@ -277,8 +285,7 @@ class CommentFilterLegacy implements IMainFilter {
this.commentContentFilter.isEnable && blackPairs.push([this.commentContentFilter, selectorFns.root.content])
this.commentLevelFilter.isEnable && blackPairs.push([this.commentLevelFilter, selectorFns.root.level])
this.commentBotFilter.isEnable && blackPairs.push([this.commentBotFilter, selectorFns.root.username])
this.commentCallBotFilter.isEnable &&
blackPairs.push([this.commentCallBotFilter, selectorFns.root.callUser])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.root.callBot])
this.commentCallUserFilter.isEnable &&
blackPairs.push([this.commentCallUserFilter, selectorFns.root.callUser])
this.commentCallUserOnlyFilter.isEnable &&
Expand All @@ -299,7 +306,7 @@ class CommentFilterLegacy implements IMainFilter {
this.commentContentFilter.isEnable && blackPairs.push([this.commentContentFilter, selectorFns.sub.content])
this.commentLevelFilter.isEnable && blackPairs.push([this.commentLevelFilter, selectorFns.sub.level])
this.commentBotFilter.isEnable && blackPairs.push([this.commentBotFilter, selectorFns.sub.username])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.sub.callUser])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.sub.callBot])
this.commentCallUserFilter.isEnable &&
blackPairs.push([this.commentCallUserFilter, selectorFns.sub.callUser])
this.commentCallUserOnlyFilter.isEnable &&
Expand Down
6 changes: 3 additions & 3 deletions src/modules/filters/variety/comment/subFilters/black.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class CommentLevelFilter extends NumberMinFilter {}

export class CommentBotFilter extends StringFilter {}

export class CommentCallBotFilter extends StringFilter {}
export class CommentCallBotFilter extends BooleanFilter {}

export class CommentCallUserFilter extends KeywordFilter {}
export class CommentCallUserFilter extends BooleanFilter {}

export class CommentCallUserNoReplyFilter extends KeywordFilter {}
export class CommentCallUserNoReplyFilter extends BooleanFilter {}

export class CommentCallUserOnlyFilter extends BooleanFilter {}

Expand Down

0 comments on commit 95c4d7a

Please sign in to comment.