Commit History
-
onboarding: sweep every known chat, so no group is ever left behind by hand
ilang-ai +1: Claude Opus 5Layers 2 and 3 only attach at the moment the bot is added, which left two holes that could only be closed manually: chats that predate the feature never get nagged at all, and the JobQueue is in memory, so a restart silently drops every pending nag. This bot is the live proof - it sits in 9 chats with no rights that nothing was ever going to act on. Layer 4 is a run_repeating sweep, 6 hours apart, first pass 5 minutes after start. Every known chat is probed; the rights-less ones enter the same 1/2/3/5/10 minute nag cycle and leave on their own. It also picks up chats whose rights were revoked later, which nothing else watched for. The sweep itself sends nothing, leaves nothing and writes no blocklist row - it only decides who enters layer 2, so every existing safety rule still applies. Two things it has to get right: - 'gone' is now its own member_state, separate from 'no rights'. left/kicked fails the same rights predicate as an unpromoted admin, so without the split the sweep …dfca837 -
onboarding: never let a network blip trigger a leave + blocklist
ilang-ai +1: Claude Opus 5Same three fixes as the private tree, plus the two wiring gaps that made them worse here. The core problem: has_rights collapsed every exception into "no rights", and at the 600s slot that answer went straight to leave + blocklist. probe_rights is now tri-state (True/False/None); only a confirmed False may act. An unreadable answer requeues the same slot 60s later, up to 3 times, then gives up without leaving. The nag's send_message no longer treats a timeout as "muted/removed" - only Forbidden and the chat-is-gone BadRequests do, and that path leaves without blocklisting. Error-derived cache negatives now live 20s instead of 300s, so a blip can no longer silence a group for five minutes. Also here: - /groups (list + unblock) was private-only, and unblock() was dead code in this repo. A wrong entry was only undoable by hand-editing bot.db on the VPS. - ADMIN_USER_ID was claimed by whoever sent the first /start after a restart. On a public bot that is a stranger, and it re-opened …76a45e0
-
入群授权催办:没权限就不判定,10 分钟仍未授权自动退群拉黑
ilang-ai动机是一个真实的额度消耗攻击面:任何人都能把 bot 拉进任意群,而没有管理权限时 bot 删不掉封不了,却仍把每条群消息送去 AI 判定,判完才发现无权处置。 线上实测一个陌生群 24 小时刷出 447 条「检测到 spam 但没权限」,全是白烧的调用。 拉进一个高流量群、不给权限,就能静静烧掉额度。 三层处置,新增 modules/onboarding.py: 1. 没权限时根本不判 —— 这才是真正掐掉成本的地方。has_rights() 要求 administrator + can_delete_messages + can_restrict_members 三者齐全, 缺一即视为无权限;查询失败也按无权限处理(宁可少判,不在未授权群烧调用)。 带 300 秒缓存,且 my_chat_member(权限变更时同样会推送)到达时立即作废, 不必等 TTL。位置放在节点采集之前,未授权的群一概不消耗任何资源。 2. 加进群后按 1/2/3/5/10 分钟催办,措辞逐级明确,第 5 分钟起预告将退群。 任一次催办时若已拿到权限,立即取消全部剩余任务。 催办发不出去(被禁言/被踢)说明留着也没意义,直接进入退群流程。 3. 10 分钟仍无权限:说明原因、退群、写入 group_blocklist。 之后再被拉进同一个群直接退且一言不发 —— 否则反复邀请就是一个免费的 「让 bot 说话 + 处理流量」循环。 私有版另加超管命令 /groups 查看黑名单、/groups unblock <chat_id> 解除。 沙箱验证两边各 21/21:权限判定五种组合(含线上那个被禁言的俄语群场景)、 排程时间点、有权限时绝不误退群、无权限时逐级催办且不提前退、 10 分钟到点退群并拉黑、拉黑后拦截与解除、缓存命中与作废。f691796 -
可选的跨供应商兜底:主供应商超时不再直接掉到只认关键词的词库
ilang-ai线上实测(199.180.115.46, 24 小时):主供应商 38 次 Request timed out, 导致 37 次 spam 判定只能退回词库单独裁决——那层只认词表里已有的黑话, 覆盖面比 AI 差一大截。姊妹项目已用跨供应商兜底解决,这里补上。 因为是开源仓库,不写死任何凭据,做成纯可选: - 新增 AI_FALLBACK_API_KEY / _BASE_URL / _MODEL / _VISION_MODEL 四个环境变量 - 不填 AI_FALLBACK_API_KEY 则行为与之前完全一致(链条不变、不建第二个 client) - 填了才在每条模型链尾部追加一个备用供应商条目 实现: - 单例 _client 改为按 provider 名缓存的 _clients,_get_client(which) - 链条目支持 "模型名"(主供应商) 或 (FALLBACK, "模型名")(备用供应商) - 解包与建 client 都在 try 内,某条目不可用时跳过继续降级,不中断整条链 - 识图未单独配 AI_FALLBACK_VISION_MODEL 时复用文本模型 沙箱验证 8/8:未配置时链条与原来逐项相同;配置后链尾正确追加; 强制主供应商 401 后兜底接管并返回正确判定;恢复后主供应商照常; 主备双双失效时抛 AIError(调用方据此退词库),不会崩。 四个新变量已同步 .env.example 与中英文 README 配置表。99f0a25
-
反spam: 同步私有姊妹版的入口完整性审计成果
ilang-ai同源的私有 bot 在真实群流量上跑出了这批问题,公开版逐条同样存在。 仍是同一个模式:消息走到某条路径后,反spam 静默地根本没跑。 1. 崩溃: msg.forward_date 在 PTB 22.8 已不存在(Bot API 7.0 换成 forward_origin, 读取直接 AttributeError)。三处在读它 —— bot.py 两处判定链 + prefilter.forward_spam, 于是任何无 caption 的贴纸/文件/GIF 进群就崩,不判定不删除不记录。 而且全仓库零个错误处理器,崩了只在日志留 traceback。已全部改 forward_origin 并注册 add_error_handler。 2. 命令抢占: CommandHandler 注册在群 handler 之前且同在 group 0,PTB 每个 group 只跑第一个匹配的;而 PTB 允许命令携带任意后缀正文 —— /<任意命令> <广告> 被命令 handler 吃掉后静默 return,广告全程无人过问。群 handler 移到 group=-1 先跑, 真正处置(删/封)后 raise ApplicationHandlerStop 掐断。连带:命令消息不再算作 @提问,否则 /start@自己 会被 AI 回一遍、命令再回一遍。 3. 类型覆盖: 过滤器白名单只有 TEXT/PHOTO/VIDEO/Document/Sticker,语音、音频、 圆视频、投票、快拍等匹配不到任何 handler。改为收群里的一切、只排掉入群退群 系统消息。名片不再排除 —— 本仓库没有独立的名片 handler,排掉等于复刻同一个洞。 4. 判定链死分支 + 看不见的文本: 贴纸/无caption文件/GIF 以前只判 caption, 没 caption 就恒判为干净。现在走缩略图识图(image/* 文件直接用本体), 并新增 _poll_text / _media_meta / _hidden_text 与 judge_text —— text_link 超链接的真实 URL 存在 entities 里不在 text 里,转发来源频道名、 发送者昵称、via_bot 同理…e4cf54e -
反spam: 堵住五个静默绕过 + 新增签到探针层
ilang-ai这五个问题都是在同源的私有 bot 上、用真实群流量测出来的,公开版同样存在 (探针那层是公开版从来就没有的功能)。都属同一类:消息走到某条路径后, 反spam 静默地根本没跑。 1. @提及/回复bot 绕过 —— 该分支回复完就 return,位置在整条反spam 之前。 spam bot 只要回复一下 bot 自己发的欢迎语就完全免检,而且 bot 还会用 AI 回它一句(等于帮它顶帖)。改为:先过反spam,判定干净了才在函数末尾回答。 新增 sender_ctx 提示提问本身不算违规,避免把正常提问的人误判封号。 管理员仍照常得到回答(公开版对管理员是提前 return,不能顺手跳过回答)。 2. 编辑消息绕过 —— 先发一句无害的、再编辑成广告。两因叠加:allowed_updates 没订阅 edited_message(Telegram 根本不推) + handler 只取 update.message (编辑事件里是 None)。改为订阅 + 取 message or edited_message;编辑只重判 不重答;私聊 handler 与 CommandHandler 显式加 UpdateType.MESSAGE,否则 编辑一次就重复回答/重复执行命令一次。 3. 判定解析 fail-open —— 非 spam/yes 开头一律当干净,模型多说两个字 (根据以上判断,yes)或被 max_tokens=8 截断在前言里就是免死金牌。 改三态 True/False/None,None 退回词库兜底并记录原始输出;max_tokens 8→32。 4. 新增签到探针层(modules/probe.py) —— 对所有非管理员生效,只标记绝不封人, 窗口内累计到阈值才静默删除。词表刻意只收签到打卡这一族:更宽的版本 (哈+/好+的?/收到/顶/纯emoji/纯标点)实测命中中文群短消息的 59%, 会把真人的哈哈👍删掉,比漏拦更糟。window_start 记窗口起点且命中不刷新, 否则每天发一句水消息的人计数只涨不降,被永久静默删。 5. 命令消息绕过 —— 群 handler 带着 ~filters.COMMAND,命令根本不进反spam; 而…da5659b
-
Tidy: drop vestigial device field + rewrite READMEs for the flagship
ilang-ai- chat.py/bot.py: remove the dead 'device' field left over from the old node/device-onboarding contract; _parse and the AI handlers now return (intent, reply) 2-tuples. py_compile clean, no behavior change (device was always None and never acted on). - README.md / README_CN.md: full rewrite for the antispam.bot flagship — clean brand voice matching the landing page, 'engine behind antispam.bot' positioning, a proper env-var config table, and accurate architecture. All setup paths already use AI_API_KEY; HF front-matter preserved.5c153bd
-
Phase 2: 中文黑话词库 + I-Lang v5.0 判定参考 + 修子串误判
ilang-ai- 新增 modules/lexicon.py:NFKC+零宽+同形字归一化 → 黑话打分(收米/上车/日结/薇V/USDT...), 破全角/同形字/零宽规避;接进 prefilter Layer 2.5(硬命中直接判spam,省AI调用) - 新增 modules/ilang_judge.py:I-Lang v5.0 决策函数 f_v5(11维向量→8模式)参考实现,自测9/9 (persona.ilang 的 v4.0 GENE 已实现'知无不答'对话行为,v5.0 作为可计算判定层备用/展示) - config.py 加 LEXICON_HARD_THRESHOLD(env) - 修 chat.py 判定 '"spam" in result' 子串bug('not spam'会误判)→ _is_spam 精确解析 - 实测:零宽规避命中、正常不误伤、prefilter 抓到正则漏掉的黑话a8e2bd1 -
Phase 1: 去 Gemini,AI 改走 OpenAI 兼容 provider(默认硅基流动)
ilang-ai- 新增 modules/ai_provider.py:OpenAI兼容抽象层,文本+视觉容错链+600px压缩+懒加载, 任何 OpenAI 兼容供应商(SiliconFlow/OpenAI/DeepSeek/本地vLLM)都能接 - chat.py 去 google-generativeai/SAFETY_SETTINGS/_safe_text,7个函数走 provider,保留 .ilang prompt 与全部行为 - config.py:Gemini → AI_API_KEY/AI_BASE_URL/AI_MODEL/AI_VISION_MODELS(env) - bot.py 启动AI测试改走 provider;requirements 换 openai+Pillow - 实测:中英双语聊天 + 判spam(广告→True/闲聊→False)均正确c5249c3
-
v4.3: pre-filter layer — zero API cost spam defense
ilang-aiThree defense lines BEFORE AI: 1. Repeat detection (already had) — same msg 3x in 5min 2. Pre-filter (NEW): - Keyword/regex: multilingual spam patterns + URL/contact combo - Forward spam: forwarded msg with link/contact = spam - New account: no username + no name + has link = spam 3. API rate limiter with token bucket: - 50 calls/minute budget - Below 20%: sampling mode (1 in 3 messages) - Exhausted: rules-only mode, no AI calls - Graceful degradation, never goes blind AI only sees messages that pass all pre-filters. Addresses ACC red team finding #2 (rate limit trap).27803aa -
fix: pass BLOCK_NONE safety_settings on every API call, not just constructor
ilang-aiConstructor-level safety_settings may not propagate to all calls in google-generativeai 0.8.4. Now explicitly passed on all 9 generate_content_async calls.4abec07 -
fix: safe Gemini response extraction + startup logging
ilang-ai- r.text throws ValueError when response is blocked, now caught - _safe_text() extracts from candidates as fallback - Startup logs show which .ilang files loaded and their size - Fallback system prompt if .ilang files not found - Detailed AI response logging for debugging39fe1a0 -
v3.0: international edition — universal prompts, English UI, multilingual bot
ilang-ai- Persona: universal personality, auto-detect language, boundary handler (split don't refuse) - Antispam: language-agnostic three-step analysis - Vision: universal three-step image reading - All UI strings: English (bot auto-detects user language for replies) - GENE/IMMUNE framework showcased in every .ilang file - Safety filters: BLOCK_NONE for all Gemini categoriesecdeed3 -
fix: relax Gemini safety filters — BLOCK_NONE for all categories
ilang-aiWithout this, Gemini blocks any message containing slang/adult terms from the 黑话词典, returning empty response and triggering deflect. Added better logging for blocked responses.7c1cf27 -
v1.0: TelegramGuard - AI-powered group guardian with I-Lang Prompt Spec
ilang-ai- Anti-spam: AI + repeat message detection (3x in 5min = ban) - Vision: image and video thumbnail understanding - Chat: group @mention and private conversation - Prompts: .ilang format (I-Lang Prompt Spec) - Deploy: HF Space (free) or VPS - GitHub Actions: auto-sync to HuggingFacecc6f785