Implement plans/01: cache cap + RetryAfter helper + handler refactor + /status command#22
Merged
Merged
Conversation
Behavior-preserving readability refactor with zero test changes: 1. bio_bait.py: extract enforce delete+restrict+notify into _enforce_bio_bait_restriction() — parent raises ApplicationHandlerStop 2. dm.py: extract unrestrict loop into _unrestrict_in_groups() returning success count — parent handles response messages 3. anti_spam.py: extract guard clauses into _should_skip_new_user_spam_check() predicate 4. message.py: extract is_bot guard into _should_skip_profile_check() predicate 5. check.py: extract callback data parsing into _parse_warn_callback_data() returning (user_id, missing_code) or None All 948 tests pass, coverage 99% (22 missed, unchanged). Ruff + mypy clean.
…r_with_retry - Two helpers in telegram_utils.py: RetryAfter-aware wrappers that sleep + retry once, return False on second RetryAfter, re-raise other errors - unrestrict_user uses restrict_chat_member_with_retry internally - 4 call sites updated: check.py handle_warn_callback, scheduler.py auto-restrict loop, dm.py unrestrict loop, bio_bait.py monitor alert - 8 unit tests for helpers, 2 integration tests for bio_bait error paths - 958 tests pass, 99% coverage, ruff clean, mypy clean ponytail: scheduler.py RetryAfter-fallback continue (lines 95-98) not covered by tests; add scheduler-level RetryAfter test if it becomes a real problem.
…ct stamp on real work Applies multi-model review feedback: - Remove premature-abstraction _should_skip_profile_check predicate (M1) - Track processed_any in auto_restrict to skip stamp on no-op cycles (R3) - Add logger.warning for missing message/from_user in status handler (C3) - Drop group_titles read; use str(gid) directly (M2, M6)
Plan docs are working notes for a session, not source. Untrack the one that snuck into the improvement branch's history.
- verify.py: catch RuntimeError from unrestrict_user retry exhaustion; wrap clearance notification with send_message_with_retry - bio_bait.py: wrap enforcement path (restrict + notify) with retry helpers (the monitor-only alert path was already wrapped) - scheduler.py: stamp last_auto_restrict unconditionally on every successful run (matches admin_cache behavior) - telegram_utils.py: cap retry sleep at 30s to prevent one bad RetryAfter from stalling per-group loop for a minute-plus - status.py: drop dead title variable (was duplicating group_id)
Owner
Author
|
Pushed additional fixes from reviewer feedback (commit 3f7d33a):
|
title = str(gid) just re-stringified the same group_id with nothing else feeding it (GroupConfig has no name/title field), so each group line printed the ID twice: `-100123` — -100123. Show it once.
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
Implements Phases 1a, 1b, 3, and 4 from
plans/01-bot-improvement-recommendations.md.Changes
RECENT_MESSAGES_KEYinduplicate_spam.py(mirror of bio_bait USER_BIO_CACHE_MAX_SIZE pattern); new eviction testssend_message_with_retry+restrict_chat_member_with_retryintelegram_utils.py; applied to 4 multi-group broadcast sites (handlers/check.py,handlers/dm.py,handlers/bio_bait.py,services/scheduler.py); handles bothintandtimedeltaRetryAfter.retry_after_unrestrict_in_groups(dm), guard-clause predicates (anti_spam, message, check), bio_bait tail; behavior-preserving/statuscommand: uptime, per-group plugin toggles, probation/captcha counts, DB size, last job timestamps; stampslast_admin_refresh/last_auto_restricton real workVerification
Multi-Model Review
Reviewed by 3 agents (correctness, reliability, maintainability). Applied:
_should_skip_profile_checkpredicateprocessed_anyto skip false stamp on no-op auto-restrict cyclelogger.warningfor missing message in status handlergroup_titlesread in statusSkipped (test additions for NIT findings; defer to follow-up):
_should_skip_*predicateslast_admin_refreshnot-stamped-on-all-fail testPhase 5 (Dockerfile HEALTHCHECK) skipped per plan — low value for polling bot.