Merged
Conversation
Detect users who repeatedly paste the same message within a configurable time window. On reaching the threshold (default: 3 similar messages in 120 seconds), the duplicate is deleted and the user is restricted. Key design decisions: - In-memory rolling deque per (group_id, user_id) for tracking - Text normalization + difflib similarity matching (threshold 0.97) - No UserWarning record created, so DM unrestriction flow cannot bypass (same pattern as inline keyboard spam and new user probation handlers) - Configurable per group: enabled, window_seconds, threshold, min_length Files changed: - New: handlers/duplicate_spam.py - core detection and enforcement - New: tests/test_duplicate_spam.py - 37 tests, 100% coverage - Modified: constants.py - Indonesian notification templates - Modified: group_config.py - per-group config fields + .env fallback - Modified: config.py - Settings fields for .env support - Modified: main.py - handler registration at group=0 - Modified: .env.example, groups.json.example - documentation - Modified: test_config.py, test_group_config.py - coverage for new fields
Add duplicate_spam_similarity field (float, default 0.95) to GroupConfig, Settings, and example configs. 0.95 catches minor word edits while avoiding false positives on legitimately similar messages.
…uler tests - Change default duplicate_spam_threshold from 3 to 2 (trigger on 2nd duplicate within window) - Fix RuntimeWarning in test_scheduler: mock get_chat_member to return proper MagicMock user instead of AsyncMock with unawaited coroutines
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
Detects and restricts users who repeatedly paste the same message in a group chat (e.g., job spam posted 3 times in 2 minutes).
How it works
DM bypass protection
Restrictions from this handler (and existing inline keyboard spam / new user probation handlers) do NOT create a UserWarning record, so the DM unrestriction flow cannot bypass them.
Configuration (per group)
Similarity threshold reference
Test coverage