Skip to content

fix: multi-group moderation gaps in topic guard and spam handlers#6

Merged
rezhajulio merged 2 commits intomainfrom
fix/multi-group-moderation-gaps
Mar 6, 2026
Merged

fix: multi-group moderation gaps in topic guard and spam handlers#6
rezhajulio merged 2 commits intomainfrom
fix/multi-group-moderation-gaps

Conversation

@rezhajulio
Copy link
Owner

Summary

Fixes several multi-group moderation gaps where the bot could fail to delete spam messages or protect the warning topic.

Changes

topic_guard.py

  • Stop propagation: Raise ApplicationHandlerStop after handling warning-topic messages, preventing downstream spam/profile handlers from processing them
  • Edited messages: Handle update.edited_message in addition to update.message
  • Fail-closed: On get_chat_member API error, delete the message (scoped to confirmed warning-topic messages only)

main.py

  • Register topic_guard with combined MESSAGE | EDITED_MESSAGE filter
  • Add edited_message to allowed_updates in run_polling()
  • Add periodic admin cache refresh via JobQueue (every 10 minutes) with graceful fallback

Tests

  • Coverage improved from 99% → 99.9% (504 → 519 tests)
  • All modules at 100% except 1 unreachable line in anti_spam.py

Issues Addressed

  1. Warning-topic messages leaked to spam/profile handlers (no ApplicationHandlerStop)
  2. Edited messages bypassed topic guard entirely
  3. API errors in topic guard failed open (non-admin messages left in warning topic)
  4. Stale admin cache never refreshed after startup (promotions/demotions ignored)
  5. edited_message updates never reached the bot (allowed_updates missing it)

rezhajulio and others added 2 commits March 5, 2026 11:24
- topic_guard: raise ApplicationHandlerStop after handling warning-topic
  messages to prevent downstream handlers from processing them
- topic_guard: handle edited messages (update.message or update.edited_message)
- topic_guard: fail-closed on get_chat_member error (delete message in
  warning topic on API failure), scoped to confirmed warning-topic only
- main: register edited_message handler for topic_guard using combined
  MESSAGE | EDITED_MESSAGE filter at group=-1
- main: add 'edited_message' to allowed_updates in run_polling
- main: add periodic admin cache refresh via JobQueue (every 10 minutes)
  with graceful fallback to cached data on failure
- tests: improve coverage from 99% to 99.9% (519 tests, 1 unreachable line)

Amp-Thread-ID: https://ampcode.com/threads/T-019cbc2b-3b09-743f-9ecc-eaa7dfd0234c
Co-authored-by: Amp <amp@ampcode.com>
…d coverage changes

- Handler priority groups: document all 6 groups (-1 through 4)
- Topic guard: document edited message handling, ApplicationHandlerStop, fail-closed behavior
- Admin cache: document periodic refresh (every 10 min) with graceful fallback
- allowed_updates: reflect addition of edited_message
- Test coverage: update stats to 519 tests, 99.9% coverage
- Test file list: add missing test_check.py, test_duplicate_spam.py
- Architecture: reflect all handler modules and their priority groups

Amp-Thread-ID: https://ampcode.com/threads/T-019cbc2b-3b09-743f-9ecc-eaa7dfd0234c
Co-authored-by: Amp <amp@ampcode.com>
@rezhajulio rezhajulio merged commit d0846ec into main Mar 6, 2026
5 checks passed
@rezhajulio rezhajulio deleted the fix/multi-group-moderation-gaps branch March 6, 2026 11:30
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