Merged
Conversation
…astructure Introduces the foundation for multi-group support: - GroupConfig (Pydantic BaseModel) with per-group settings - GroupRegistry for O(1) group lookup - JSON file loading and backward-compatible fallback from .env - get_group_config_for_update() helper for handlers - Module-level singleton with init/get/reset
Adds configurable path for groups.json file (defaults to "groups.json"). Existing .env fields kept for backward compatibility when no groups.json exists.
…rvice Per-group variant that filters by group_id AND uses group-specific threshold, enabling different auto-restriction timing per group.
Universal pattern change across all group-facing handlers: - topic_guard: uses get_group_config_for_update for guard check - anti_spam: per-group probation thresholds and violation tracking - message: per-group warning/restriction with group-specific settings - captcha: accepts GroupConfig, looks up group from registry on callback - verify: iterates all groups for unrestrict/delete-warnings - check: sends warnings to all monitored groups - dm: iterates all groups for membership check and cross-group unrestriction
- Scheduler iterates per-group with group-specific thresholds - Captcha recovery uses per-group timeout from GroupConfig - Skips captchas for groups no longer in registry
- Initialize group registry from settings (groups.json or .env fallback) - Fetch admin IDs per-group and store union for DM commands - Captcha recovery checks all groups with captcha enabled - Log per-group config summary at startup
- groups.json.example with sample multi-group configuration - .env.example documents GROUPS_CONFIG_PATH option - .gitignore excludes groups.json (contains group IDs)
🔄 Replace get_settings() patches with get_group_config_for_update() and get_group_registry() patches across all test files. 🆕 Add test_group_config.py for GroupConfig, GroupRegistry, JSON loading, and singleton management. 🎯 All 440 tests pass.
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS from .env was rejected by Pydantic Settings as an unknown field. Added extra="ignore" to SettingsConfigDict.
- Remove RuntimeError in dm.py when all unrestriction attempts fail, replace with error log and friendly user message - Add try/except around get_user_status() in dm.py membership scan so one inaccessible group doesn't abort the entire DM handler - Add per-group try/except in verify_user() so a failure in one group doesn't prevent verification in other groups - Make get_group_config_for_update() resilient to uninitialized registry by catching RuntimeError and returning None - Fix ruff lint: remove unused imports and variables
3d293e9 to
9dc52de
Compare
…tion
- Encode group_id in captcha callback data (captcha_verify_{group_id}_{user_id})
to deterministically resolve the correct group instead of scanning all groups
- Wrap scheduler per-group warning query in try/except so one failing group
does not abort the entire auto-restriction job
fc42ceb to
747f818
Compare
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
Add multi-group support so a single bot instance can manage multiple Telegram groups.
This work builds upon the multi-group foundation from jvmdeveloperid/PythonID-bot by Hendy Santika (@hendisantika).
Multi-group infrastructure
GroupConfig(Pydantic model) andGroupRegistryfor per-group configurationgroups.jsonfile support with automatic fallback to.envfor single-group backward compatibilityHandler refactoring
get_group_config_for_update()instead ofsettings.group_idRobustness fixes
group_idin captcha callback data to deterministically resolve the correct group instead of scanning all groupsRuntimeErrorin DM handler that could disrupt bot operationget_group_config_for_update()resilient to uninitialized registryBackward compatible
No
groups.json? Bot works exactly as before using.envvalues.Tests
All 442 tests pass, 99% coverage.