Skip to content

fix(anti-spam): delete all duplicate messages, not just triggering one#18

Merged
rezhajulio merged 3 commits into
mainfrom
fix/duplicate-spam-delete-all-messages
Jul 3, 2026
Merged

fix(anti-spam): delete all duplicate messages, not just triggering one#18
rezhajulio merged 3 commits into
mainfrom
fix/duplicate-spam-delete-all-messages

Conversation

@rezhajulio

Copy link
Copy Markdown
Owner

Summary

  • Duplicate-spam handler was calling update.message.delete() only on the message that crossed the threshold, leaving earlier duplicate messages already sitting in the tracking window undeleted (e.g. detects on 3rd message, deletes only the 3rd — 1st and 2nd stay in chat).
  • Now collects message_id for every similar message in the window plus the current one, and deletes each via context.bot.delete_message.

Test plan

  • uv run pytest tests/test_duplicate_spam.py -q — 38 passed
  • uv run pytest -q — 958 passed, no regressions
  • uv run ruff check . — clean
  • Added regression assertion in test_third_message_also_triggers proving all prior duplicate message_ids get deleted, not just the last one

handle_duplicate_spam only called update.message.delete() on the
message that crossed threshold, leaving earlier duplicates in the
window undeleted. Now deletes every message_id in the similar-message
window via context.bot.delete_message.
Superseded by the similar_messages list built inline in
handle_duplicate_spam, which needs the message_ids for deletion, not
just a count.
Deque entries stayed forever, so every subsequent duplicate message
in the same window re-attempted delete_message on already-deleted
message_ids, spamming error logs until the window expired. Track
delete_attempted per entry and skip it.
@rezhajulio rezhajulio merged commit 148fb1a into main Jul 3, 2026
5 checks passed
@rezhajulio rezhajulio deleted the fix/duplicate-spam-delete-all-messages branch July 3, 2026 07:47
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