feat: core UX and safety package - #24
Merged
Merged
Conversation
- Bump python-telegram-bot dependency from >=22.5 to >=22.8
- Pass api_kwargs={'return_bots': False} to get_chat_administrators
- Also filter admin.user.is_bot client-side as a safety net
- Update tests to set is_bot=False on mock admins and verify bot exclusion
- Add test_fetch_admins_excludes_bots test case
Major changes:
1. Group-scoped admin authorization:
- Add is_user_admin_in_group() and get_admin_groups() helpers
- /check now shows group selector when admin is admin in multiple groups
- All callback data encodes group_id: action:{group_id}:{user_id}
- Callbacks verify caller is admin of the specific group, not global union
- Add handle_check_group_callback for group selection flow
- Warn callback sends to one group only, not all groups
2. Separate Trust, photo exemption, and unrestriction:
- Trust no longer auto-unrestricts (removes bot param from trust_user)
- Trust only clears probation, does not lift restrictions
- Add separate 'Buka pembatasan bot' (unrestrict) action
- unrestrict_user_in_group only lifts bot-applied restrictions
- Verify (photo exemption) is group-scoped, clears warnings in one group
- Rename buttons to Indonesian: 'Izinkan foto tersembunyi',
'Kecualikan dari anti-spam', 'Buka pembatasan bot'
3. New plugins: check_group_callback, unrestrict_callback
4. Updated all tests for group-scoped callback data and authorization
1. Captcha callback validation (Item 4):
- Validate callback message/chat IDs against persisted challenge
- Prevents stale or spoofed callbacks from acting on wrong challenge
2. Contextual DM recovery with deep links (Item 5):
- Add /start verify_<group_id> deep link parsing in DM handler
- Captcha timeout and restriction messages now include group-specific
deep links instead of generic bot URL
- DM handler uses target group's rules_link instead of global settings
- Pending captcha DM message lists specific groups
3. Stale enforcement fix + accurate copy (Item 6):
- Clear active profile warnings when compliant profile is observed
- Add get_active_user_warning() DB method (non-creating lookup)
- Recheck profile before scheduler restriction, skip if now complete
- Remove false 'akan dibatasi' threat from warning-only mode
- Warning-only mode no longer references threshold_display
Updated all affected tests for new behavior.
- /status now shows only groups where the caller is admin - Per-group enforcement mode (Restriksi/Peringatan) - Per-group probation and captcha counts - Per-group disabled plugins list - All labels translated to Indonesian (Grup, Jadwal terakhir, etc.) - Updated tests for new scoped behavior and Indonesian text
… test warning
- Swap captcha callback ordering: Telegram unrestrict now runs BEFORE DB
finalization, so a transient unrestrict failure preserves the pending
captcha and the user can retry by pressing the button again
- Remove redundant api_kwargs={'return_bots': False} from
get_chat_administrators — Telegram already excludes other bots by
default; client-side is_bot filter remains as safety net
- Fix RuntimeWarning in scheduler test by adding proper bot.get_chat_member
mock (was leaving an AsyncMock coroutine unawaited)
- Update AGENTS.md Code Map with current line counts and roles
- Update AGENTS.md captcha DB ordering documentation to match new flow
- Add tests: spoofed message/chat ID rejection, successful retry after
transient failure, deep-link payload parsing edge cases
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.
Core UX and Safety Package
PTB 22.8 upgrade & admin cache
python-telegram-botto >=22.8is_botfilter)Group-scoped admin authorization
/checkfinds only groups where the caller is an admin, shows a group selector for multi-group adminsgroup_id(e.g.warn:{group_id}:{user_id}:{missing_code}) and revalidate the caller per-groupis_user_admin_in_group(),get_admin_groups()check_group_callback,unrestrict_callback)Trust / photo exemption / bot-owned unrestriction separation
Recoverable/idempotent captcha completion
unrestrict_userruns before DB finalization — transient failures preserve the pending captcha so the user can retryremove_pending_captchareturning False provides idempotent duplicate-callback protectionContextual DM recovery with group deep links
https://t.me/<bot>?start=verify_<group_id>/start verify_<group_id>and uses the target group'srules_linkStale enforcement safety
get_active_user_warning()non-creating lookup clears stale warnings when profile becomes compliantGroup-scoped
/statusAudit fixes
api_kwargs={"return_bots": False}(Telegram already excludes other bots by default)RuntimeWarningfrom unawaitedAsyncMockcoroutineValidation