-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ChatAdminRequired error by sending warning messages #282
Conversation
Fixes #281 Add handling for `ChatAdminRequired` exception in `UserIsAdmin` filter. * Import `ChatAdminRequired` from `hydrogram.errors`. * Modify `UserIsAdmin.__call__` method to catch `ChatAdminRequired` exception. * Add warning message in `UserIsAdmin.__call__` method when `ChatAdminRequired` exception is caught, informing the user that the bot needs to be an administrator to perform the action.
Reviewer's Guide by SourceryThis PR enhances error handling in the UserIsAdmin filter by adding specific handling for ChatAdminRequired exceptions. The implementation wraps the admin check in a try-catch block and provides user-friendly warning messages when the bot lacks necessary admin privileges. Sequence diagram for handling ChatAdminRequired exceptionsequenceDiagram
actor User
participant Bot
participant Chat
participant Message
participant Update
User->>Bot: Send command
Bot->>Chat: Get member status
alt User is admin
Chat-->>Bot: Return admin status
Bot-->>User: Allow action
else ChatAdminRequired exception
Chat-->>Bot: Throw ChatAdminRequired
alt show_alert is true
Bot->>User: Show alert "I need to be an administrator to perform that action!"
else
Bot->>User: Reply "I need to be an administrator to perform that action!"
end
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @HitaloM - I've reviewed your changes - here's some feedback:
Overall Comments:
- The
ChatAdminRequired
import is referenced in the description but not shown in the diff. Please ensure it's properly imported fromhydrogram.errors
.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes #281
Add handling for
ChatAdminRequired
exception inUserIsAdmin
filter.ChatAdminRequired
fromhydrogram.errors
.UserIsAdmin.__call__
method to catchChatAdminRequired
exception.UserIsAdmin.__call__
method whenChatAdminRequired
exception is caught, informing the user that the bot needs to be an administrator to perform the action.Summary by Sourcery
Bug Fixes: