Skip to content

feat: implement comprehensive keyword filtering and management system#11

Open
ZZ0YY wants to merge 6 commits into
jikssha:mainfrom
ZZ0YY:main
Open

feat: implement comprehensive keyword filtering and management system#11
ZZ0YY wants to merge 6 commits into
jikssha:mainfrom
ZZ0YY:main

Conversation

@ZZ0YY
Copy link
Copy Markdown

@ZZ0YY ZZ0YY commented May 15, 2026

💡 描述

本 PR 为 Telegram Bot Worker 引入了核心屏蔽词过滤系统,增强了机器人的内容合规性管理。

🚀 新增功能

  • 关键词过滤:在 forwardToTopic 逻辑中增加了对 msg.textmsg.caption 的内容检查。
  • 双层词库
    • 内置 BLOCKED_WORDS 硬编码列表。
    • 支持 blocked_words_kv 动态 KV 词库,无需重启代码即可实时更新规则。
  • 缓存优化:引入 blockedWordsCache 内存缓存,设置 TTL 60秒,大幅降低 KV 读取频率。
  • 管理指令
    • /addword <word>: 添加动态屏蔽词。
    • /delword <word>: 删除动态屏蔽词。
    • /listwords: 查看当前的全部屏蔽词列表(硬编码 + 动态)。

🛠️ 逻辑细节

  • 修改了 forwardToTopic,在转发消息前强制执行检查,命中规则将向用户发送拦截通知并中断后续逻辑。
  • 完善了命令权限管理,确保仅管理员可通过群内指令操作词库。

用户发送消息


速率限制检查 ──超频──▶ 返回提示


指令拦截(非 /start 的 /xxx)


封禁检查 ──已封禁──▶ 静默丢弃


【新增】屏蔽词检查 ──命中──▶ 返回"违规拦截"提示 ❌


验证状态检查 ──未验证──▶ 发送验证挑战,消息ID加入待转发队列


forwardToTopic ──包含屏蔽词检查(双重保险)──▶ 转发到话题 ✅

🧪 测试验证

  • 已验证普通文本触发屏蔽词的拦截效果。
  • 已验证媒体组(Media Group)的 caption 触发屏蔽词的拦截效果。
  • 已验证通过 /addword 实时添加词汇后立即生效。
  • 已验证 /listwords 能正确合并并显示所有词汇。

ZZ0YY added 3 commits May 16, 2026 06:46
- 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.
@ZZ0YY ZZ0YY mentioned this pull request May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant