fix(anti-spam): delete all duplicate messages, not just triggering one#18
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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).message_idfor every similar message in the window plus the current one, and deletes each viacontext.bot.delete_message.Test plan
uv run pytest tests/test_duplicate_spam.py -q— 38 passeduv run pytest -q— 958 passed, no regressionsuv run ruff check .— cleantest_third_message_also_triggersproving all prior duplicate message_ids get deleted, not just the last one