You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📝 docs: update README for multi-group support and current test coverage
Add multi-group feature section, groups.json setup guide, updated project
structure with new files (group_config.py, check.py), and refresh test
stats from 404 to 440 tests at 99% coverage (1,381 statements).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
To manage multiple groups with a single bot instance, create a `groups.json` file:
116
+
117
+
```bash
118
+
cp groups.json.example groups.json
119
+
```
120
+
121
+
Edit `groups.json` with your groups:
122
+
123
+
```json
124
+
[
125
+
{
126
+
"group_id": -1001234567890,
127
+
"warning_topic_id": 123,
128
+
"restrict_failed_users": false,
129
+
"warning_threshold": 3,
130
+
"warning_time_threshold_minutes": 180,
131
+
"captcha_enabled": false,
132
+
"captcha_timeout_seconds": 120,
133
+
"new_user_probation_hours": 72,
134
+
"new_user_violation_threshold": 3,
135
+
"rules_link": "https://t.me/yourgroup/rules"
136
+
},
137
+
{
138
+
"group_id": -1009876543210,
139
+
"warning_topic_id": 456,
140
+
"restrict_failed_users": true,
141
+
"warning_threshold": 5,
142
+
"warning_time_threshold_minutes": 60,
143
+
"captcha_enabled": true,
144
+
"captcha_timeout_seconds": 180,
145
+
"new_user_probation_hours": 168,
146
+
"new_user_violation_threshold": 2,
147
+
"rules_link": "https://t.me/mygroup/rules"
148
+
}
149
+
]
150
+
```
151
+
152
+
Each group has independent settings. When `groups.json` exists, the per-group `GROUP_ID`/`WARNING_TOPIC_ID`/etc. fields in `.env` are ignored. You still need `TELEGRAM_BOT_TOKEN`, `DATABASE_PATH`, and logging settings in `.env`.
153
+
104
154
## Installation
105
155
106
156
```bash
@@ -150,14 +200,14 @@ uv run pytest -v
150
200
### Test Coverage
151
201
152
202
The project maintains comprehensive test coverage:
153
-
-**Coverage**: 99% (1,216 statements)
154
-
-**Tests**: 404 total
155
-
-**Pass Rate**: 100% (404/404 passed)
156
-
-**All modules**: 100% coverage including JobQueue scheduler integration, captcha verification, and anti-spam enforcement
203
+
-**Coverage**: 99% (1,381 statements)
204
+
-**Tests**: 440 total
205
+
-**Pass Rate**: 100% (440/440 passed)
206
+
-**All modules**: 100% coverage including JobQueue scheduler integration, captcha verification, anti-spam enforcement, and multi-group configuration
class Init,FetchAdmins,RecoverPending,StartJobs,Poll,CheckProfile,CheckDMProfile,RestrictAndChallenge,StorePending,ScheduleTimeout,WaitCaptcha,StartProbation,StartProbationAfter processNode
442
+
class Init,LoadGroups,FetchAdmins,RecoverPending,StartJobs,Poll,CheckProfile,CheckDMProfile,RestrictAndChallenge,StorePending,ScheduleTimeout,WaitCaptcha,StartProbation,StartProbationAfter processNode
384
443
class UpdateType,RecoverCaptcha,TopicGuard,IsAdmin,CheckBot,CheckWhitelist,ProfileComplete,CheckMode,CheckCount,CheckInGroup,CheckPendingCaptcha,DMProfileComplete,CheckBotRestricted,CheckCurrentStatus,HasExpired,CheckKicked,NextUser,CheckAdminVerify,CheckAdminUnverify,CaptchaAnswer,CheckCaptchaEnabled,CheckProbation,CheckExpired,CheckViolation,CheckWhitelisted,ViolationCount,CheckWarningsExist,CheckAdminForward,ExtractUser decisionNode
385
444
class IncrementDB,SilentIncrement,MarkRestricted,ClearRecord,ClearRecord2,QueryDB,ClearKicked,MarkTimeRestricted,AddWhitelist,RemoveWhitelist,IncrementViolation,ClearProbation,DeleteWarnings dataNode
386
445
class DeleteMsg,SendWarning,SendFirstWarning,RestrictUser,SendRestrictionMsg,SendNotInGroup,SendCaptchaRedirect,SendMissing,SendNoRestriction,SendAlreadyUnrestricted,UnrestrictUser,SendSuccess,ApplyTimeRestriction,SendTimeNotice,SchedulerJob,SendVerifySuccess,SendUnverifySuccess,DenyVerify,DenyUnverify,UnrestrictMember,KickMember,UpdateMessage,CancelTimeout,ShowError,DeleteSpam,SendSpamWarning,RestrictSpammer,SendSpamRestriction,UnrestrictVerified,SendClearance,DenyForward,SendButtons,SendExtractError,ProcessVerify,ProcessUnverify actionNode
@@ -395,13 +454,17 @@ flowchart TD
395
454
The bot is organized into clear modules for maintainability:
396
455
397
456
-**main.py**: Entry point with python-telegram-bot's JobQueue integration and graceful shutdown
457
+
-**config.py**: Environment configuration using Pydantic
458
+
-**group_config.py**: Multi-group configuration with `GroupConfig` and `GroupRegistry` (singleton pattern for O(1) group lookup)
459
+
-**constants.py**: Centralized message templates and utilities for consistent formatting across handlers
398
460
-**handlers/**: Message processing logic
399
461
-`message.py`: Monitors group messages and sends warnings/restrictions
400
462
-`dm.py`: Handles DM unrestriction flow
401
463
-`topic_guard.py`: Protects warning topic from unauthorized messages
402
464
-`captcha.py`: Captcha verification for new members
403
465
-`anti_spam.py`: Anti-spam enforcement for users on probation
404
466
-`verify.py`: /verify and /unverify command handlers
467
+
-`check.py`: /check command and forwarded message handler
405
468
-**services/**: Business logic and utilities
406
469
-`scheduler.py`: JobQueue background job that runs every 5 minutes for time-based auto-restrictions
0 commit comments