-
-
Notifications
You must be signed in to change notification settings - Fork 142
Fixes #310
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
Fixes #310
Conversation
Saatnya back fix bugs Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Will add another in another time Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Signed-off-by: Yasir Aris M <git@yasir.id>
Reviewer's Guide by SourceryThis pull request includes several bug fixes and enhancements across different modules. The changes include improvements to the pypi search functionality, fixes to the warn command, updates to the chatbot AI, and error handling improvements. Sequence diagram for updated PyPI search flowsequenceDiagram
actor User
participant Bot
participant PyPI
participant Telegraph
User->>Bot: /pypi command
Bot->>PyPI: GET /pypi/{package}/json
alt Success (200)
PyPI-->>Bot: Package data
alt Response too long
Bot->>Telegraph: Post package details
Telegraph-->>Bot: Telegraph URL
Bot-->>User: Telegraph URL with package info
else Normal response
Bot-->>User: Formatted package info
end
else Failure
Bot-->>User: Connection error message
end
Sequence diagram for enhanced warn systemsequenceDiagram
actor Admin
participant Bot
participant Database
Admin->>Bot: Warn command
Bot->>Database: Get current warns
Database-->>Bot: Warns count
alt Warns >= 2
Bot->>Bot: Attempt to ban user
alt Has ban permission
Bot-->>Admin: Ban success message
Bot->>Database: Remove warns
else No ban permission
Bot-->>Admin: No permission message
end
else Warns < 2
Bot->>Database: Add warn
Bot-->>Admin: Warning message
end
Class diagram for error handling updatesclassDiagram
class ErrorHandler {
+handle_error(client, update, error)
}
class FloodWait {
+value: int
}
class SlowmodeWait {
+value: int
}
class RPCError
ErrorHandler ..> FloodWait
ErrorHandler ..> SlowmodeWait
ErrorHandler ..> RPCError
note for ErrorHandler "New centralized error handling for flood and slowmode waits"
File-Level Changes
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 @yasirarism - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Hardcoded OpenAI API key found. (link)
Overall Comments:
- Please split these changes into separate PRs - one for error handling improvements, one for the PyPI search rewrite, and one for the chatbot modifications. This will make the changes easier to review and maintain.
- Add a proper description explaining what issues these changes are fixing and any potential breaking changes, especially for the PyPI search rewrite.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🔴 Security: 1 blocking issue
- 🟢 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.
html = await fetch.get(f"https://pypi.org/pypi/{kueri}/json") | ||
if html.status_code != 200: | ||
return await pesan.edit_msg("Failed connect fo pypi server") | ||
res = html.json() |
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.
suggestion (bug_risk): Consider adding error handling for JSON parsing
The JSON parsing could fail if the response is malformed. Consider wrapping this in a try-catch block to handle potential JSONDecodeError exceptions.
Suggested implementation:
html = await fetch.get(f"https://pypi.org/pypi/{kueri}/json")
if html.status_code != 200:
return await pesan.edit_msg("Failed connect fo pypi server")
try:
res = html.json()
except json.JSONDecodeError:
return await pesan.edit_msg("Failed to parse PyPI response - invalid JSON received")
requirement = (
You'll need to add the following import at the top of the file if it's not already present:
import json
await message.chat.ban_member(user_id) | ||
await message.reply_text(strings("exceed_warn_msg").format(mention=mention)) | ||
await remove_warns(chat_id, await int_to_alpha(user_id)) | ||
try: |
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.
suggestion: Consider handling additional ban-related exceptions
While ChatAdminRequired is handled, consider also catching other potential exceptions like UserAdminInvalid or other permission-related errors that could occur during member banning.
Suggested implementation:
except ChatAdminRequired:
await message.reply_msg(strings("no_ban_permission"))
except UserAdminInvalid:
await message.reply_msg("I can't ban admin users!")
except (ChatError, UserBannedInChannel) as e:
await message.reply_msg(f"Failed to ban user: {str(e)}")
Note: If the import statement for pyrogram.errors isn't visible in the provided code snippet, you'll need to add or modify it at the top of the file. Also, you may want to add these error messages to your strings system rather than having them hardcoded.
else: | ||
gptai_conversations[uid].append({"role": "user", "content": pertanyaan}) | ||
ai_response = await get_openai_stream_response(True, OPENAI_KEY, "https://models.inference.ai.azure.com" if uid == OWNER_ID else "https://duckai.yasirapi.eu.org/v1", "gpt-4o" if uid == OWNER_ID else "gpt-4o-mini", gptai_conversations[uid], msg, strings) | ||
ai_response = await get_openai_stream_response(True, OPENAI_KEY, "https://models.inference.ai.azure.com", "gpt-4o-mini", gptai_conversations[uid], msg, strings) |
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.
🚨 issue (security): Hardcoded OpenAI API key found.
The OPENAI_KEY
variable is hardcoded in the openai_chatbot
function. This is a security risk and should be stored securely, such as in environment variables or a secrets management service.
Summary by Sourcery
Update the PyPi search command to fetch data directly from the PyPi API, display additional package information, and present the results in a more user-friendly format. Improve the warn command to handle cases where the bot lacks ban permissions. Update the chatbot prompts to instruct the AI to use the user's specified language. Add error handlers for common network-related exceptions. Refine the Google search function to enhance snippet extraction. Update the broadcast messages function to handle FloodWait exceptions more effectively.
New Features:
Enhancements: