feat: implement comprehensive keyword filtering and management system#11
Open
ZZ0YY wants to merge 6 commits into
Open
feat: implement comprehensive keyword filtering and management system#11ZZ0YY wants to merge 6 commits into
ZZ0YY wants to merge 6 commits into
Conversation
- Implement real-time blocked word filtering for both text and captions. - Integrate both hardcoded (BLOCKED_WORDS) and dynamic (KV-based) word lists. - Add admin commands (/addword, /delword, /listwords) for dynamic management. - Introduce memory-based caching (blockedWordsCache) to optimize KV read performance.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 描述
本 PR 为 Telegram Bot Worker 引入了核心屏蔽词过滤系统,增强了机器人的内容合规性管理。
🚀 新增功能
forwardToTopic逻辑中增加了对msg.text和msg.caption的内容检查。BLOCKED_WORDS硬编码列表。blocked_words_kv动态 KV 词库,无需重启代码即可实时更新规则。blockedWordsCache内存缓存,设置 TTL 60秒,大幅降低 KV 读取频率。/addword <word>: 添加动态屏蔽词。/delword <word>: 删除动态屏蔽词。/listwords: 查看当前的全部屏蔽词列表(硬编码 + 动态)。🛠️ 逻辑细节
forwardToTopic,在转发消息前强制执行检查,命中规则将向用户发送拦截通知并中断后续逻辑。用户发送消息
│
▼
速率限制检查 ──超频──▶ 返回提示
│
▼
指令拦截(非 /start 的 /xxx)
│
▼
封禁检查 ──已封禁──▶ 静默丢弃
│
▼
【新增】屏蔽词检查 ──命中──▶ 返回"违规拦截"提示 ❌
│
▼
验证状态检查 ──未验证──▶ 发送验证挑战,消息ID加入待转发队列
│
▼
forwardToTopic ──包含屏蔽词检查(双重保险)──▶ 转发到话题 ✅
🧪 测试验证
caption触发屏蔽词的拦截效果。/addword实时添加词汇后立即生效。/listwords能正确合并并显示所有词汇。