Skip to content

Let /spam ai run without the /spam master switch - #21

Merged
scarletkc merged 2 commits into
mainfrom
scarletkc/message-delete-spam-feature-8acd0e
Nov 3, 2026
Merged

scarletkc merged 2 commits into
mainfrom
scarletkc/message-delete-spam-feature-8acd0e

Conversation

@scarletkc

@scarletkc scarletkc commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

The global spam_words.txt substring-matches common words such as ad, DM, 投资 and 充值, so it produces many false positives. Admins who only wanted the paid AI check could not get it without that list: /spam ai on required the /spam master switch, and the master switch always turns on the global list unless the group has custom keywords.

The AI check is now its own switch.

Behaviour

/spam master /spam ai What runs
on on Unchanged: link → mention → keywords → AI
on off Unchanged: link → mention → keywords
off on New: AI only. Links, mentions, custom keywords and the global list are skipped, even if their per-group flags are still set
off off Nothing (unchanged)
  • /spam ai on|renew no longer requires the master switch. It still requires the bot's delete-messages right.
  • Turning the master switch off no longer implies that everything has stopped. If the AI check is still running, the reply adds 「AI 识别不受影响,仍在运行;如需暂停,使用 /spam ai off。」
  • Strikes are unchanged: an AI deletion still counts toward the 3-in-1-hour kick.

Cost

process_message now calls the new spam_ai.handlers.is_running(chat_id) before the admin lookup. That function wraps judge.is_configured() and the cached operations.is_checking. Groups with neither switch on still return before any get_chat_member call. Groups with the master switch on never call is_running on that early path.

Texts

  • /spam ai status with the master switch off says that only AI runs. Its "service unavailable" and "daily limit" notes then say 「不检查消息」 instead of promising keyword filtering.
  • The expiry reminder now reads 「本群的 AI 识别已到期,不再用 AI 检查消息。」 because the reminder job does not know the master state.
  • /spam help, the plain-text help and resources/docs/spam.md say that AI can run on its own.

Not changed

  • The global word list itself. I looked at GitHub candidates, and the only ready-made Chinese list (dkgks/tgforwarder) is old web-censorship vocabulary without Telegram ad terms. It was shelved.

Test plan

  • uv run pytest -q: 1224 passed, 68 skipped
  • uv run ruff check src tests
  • New tests:
    • With the master switch off, a running AI check gets messages that the keyword, link and mention filters would have caught.
    • Admins are still skipped.
    • Groups with nothing on skip the admin lookup.
    • is_running gating.
    • The disabled-switch reply.
  • Not tried in a real Telegram group yet: enable /spam ai on in a group with /spam off and check that a spam message is deleted with the warning and buttons

Devin Review

The global spam_words.txt substring-matches common words, so admins who
only want the paid AI check had no way to get it without the word list.

- /spam ai on|renew no longer requires the master switch.
- With the master switch off and AI running, messages skip the link,
  mention and keyword checks and go straight to the AI; groups with
  neither on still return before the admin lookup.
- Turning the master switch off says when the AI check keeps running.
- Status, expiry reminder and help texts no longer promise keyword
  filtering as the fallback when the master switch is off.

Co-Authored-By: Claude <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

The master switch is saved before the AI status lookup that decides
whether to add the "AI still running" note. If that lookup raised, the
shared handler told the admin the whole operation failed, and a retry
would turn the filter back on. Treat an unreadable status as "not
running" and only log it.
@scarletkc
scarletkc added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 6903d83 Nov 3, 2026
6 checks passed
@scarletkc
scarletkc deleted the scarletkc/message-delete-spam-feature-8acd0e branch November 3, 2026 18:00
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