Skip to content

✨ feat: add multi-group support#1

Merged
hendisantika merged 8 commits intomainfrom
multi-groups
Feb 24, 2026
Merged

✨ feat: add multi-group support#1
hendisantika merged 8 commits intomainfrom
multi-groups

Conversation

@hendisantika
Copy link
Member

Summary

  • 🏗️ Add GroupConfig (Pydantic model) and GroupRegistry for per-group configuration (warning topic, restriction settings, captcha, thresholds)
  • 📄 Support groups.json file for multi-group config with automatic fallback to .env for single-group backward compatibility
  • ♻️ Refactor all 7 handlers (topic_guard, anti_spam, message, captcha, verify, check, dm) to use get_group_config_for_update() instead of settings.group_id
  • 🔄 Update scheduler and captcha recovery to iterate per-group with per-group thresholds
  • 🚀 Update main.py to initialize GroupRegistry and fetch per-group admin IDs
  • ✅ Update all 10 test files (440 tests pass) + new test_group_config.py

Highlights

  • Backward compatible: No groups.json? Bot works exactly as before using .env values
  • Per-group settings: Each group can have its own warning_topic_id, restrict_failed_users, warning_threshold, captcha_enabled, captcha_timeout_seconds, rules_link, etc.
  • DM handler: Iterates all monitored groups to find user membership, pending captchas, and restrictions
  • Admin IDs: Per-group admin lookup with union set for DM-based admin commands (/verify, /check)
  • Validation: Pydantic validators for group_id (must be negative), thresholds (must be positive), captcha timeout (10-600s range)

Test plan

  • All 440 unit tests pass (uv run pytest tests/ -v)
  • Single-group backward compat: delete groups.json, run bot with .env only
  • Multi-group: create groups.json with 2+ groups, verify per-group behavior
  • Config errors: test malformed groups.json (invalid JSON, duplicate IDs, positive group_id)

🤖 Generated with Claude Code

hendisantika and others added 8 commits February 21, 2026 06:25
…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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds configurable path for groups.json file (defaults to "groups.json").
Existing .env fields kept for backward compatibility when no groups.json exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rvice

Per-group variant that filters by group_id AND uses group-specific
threshold, enabling different auto-restriction timing per group.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Scheduler iterates per-group with group-specific thresholds
- Captcha recovery uses per-group timeout from GroupConfig
- Skips captchas for groups no longer in registry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- groups.json.example with sample multi-group configuration
- .env.example documents GROUPS_CONFIG_PATH option
- .gitignore excludes groups.json (contains group IDs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🔄 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.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hendisantika hendisantika merged commit ea81972 into main Feb 24, 2026
4 of 5 checks passed
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