-
-
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
Changes from all commits
f468909
5bf1c04
1de0272
c21d809
6f29813
2fec8d5
b374614
fbed06d
340fa29
41cfc85
284395d
1c8571b
ff988a9
4a49a32
25b301e
1df8797
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ async def gemini_chatbot(_, ctx: Message, strings): | |
uid = ctx.from_user.id if ctx.from_user else ctx.sender_chat.id | ||
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True) | ||
if uid not in gemini_conversations: | ||
gemini_conversations[uid] = [{"role": "system", "content": "Kamu adalah AI dengan karakter mirip kucing bernama MissKaty AI yang diciptakan oleh Yasir untuk membantu manusia mencari informasi."}, {"role": "user", "content": ctx.input}] | ||
gemini_conversations[uid] = [{"role": "system", "content": "Kamu adalah AI dengan karakter mirip kucing bernama MissKaty AI yang diciptakan oleh Yasir untuk membantu manusia mencari informasi dan gunakan bahasa sesuai yang saya katakan."}, {"role": "user", "content": ctx.input}] | ||
else: | ||
gemini_conversations[uid].append({"role": "user", "content": ctx.input}) | ||
ai_response = await get_openai_stream_response(False, GOOGLEAI_KEY, "https://gemini.yasirapi.eu.org/v1", "gemini-1.5-flash", gemini_conversations[uid], msg, strings) | ||
|
@@ -113,6 +113,9 @@ async def gemini_chatbot(_, ctx: Message, strings): | |
gemini_conversations[uid].append({"role": "assistant", "content": ai_response}) | ||
|
||
@app.on_message(filters.command("ask", COMMAND_HANDLER) & pyro_cooldown.wait(10)) | ||
@app.on_bot_business_message( | ||
filters.command("ask", COMMAND_HANDLER) & pyro_cooldown.wait(10) | ||
) | ||
@use_chat_lang() | ||
async def openai_chatbot(self, ctx: Message, strings): | ||
if len(ctx.command) == 1: | ||
|
@@ -128,10 +131,10 @@ async def openai_chatbot(self, ctx: Message, strings): | |
pertanyaan = ctx.input | ||
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True) | ||
if uid not in gptai_conversations: | ||
gptai_conversations[uid] = [{"role": "system", "content": "Kamu adalah AI dengan karakter mirip kucing bernama MissKaty AI yang diciptakan oleh Yasir untuk membantu manusia mencari informasi."}, {"role": "user", "content": pertanyaan}] | ||
gptai_conversations[uid] = [{"role": "system", "content": "Kamu adalah AI dengan karakter mirip kucing bernama MissKaty AI yang diciptakan oleh Yasir untuk membantu manusia mencari informasi dan gunakan bahasa sesuai yang saya katakan."}, {"role": "user", "content": pertanyaan}] | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Hardcoded OpenAI API key found. The |
||
if not ai_response: | ||
gptai_conversations[uid].pop() | ||
if len(gptai_conversations[uid]) == 1: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,20 +50,41 @@ async def pypi_s(_, ctx: Message): | |
"Please add query after command. Ex: <code>/pypi pyrogram</code>", del_in=6 | ||
) | ||
pesan = await ctx.reply_msg("⏳ Please wait, getting data from pypi..", quote=True) | ||
CurrentPage = 1 | ||
pypires, PageLen, btn = await getDataPypi( | ||
pesan, kueri, CurrentPage, ctx.from_user.id | ||
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 commentThe 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 |
||
requirement = ( | ||
"".join(f"{i}, " for i in res["info"].get("requires_dist")) | ||
if res["info"].get("requires_dist") | ||
else "Unknown" | ||
) | ||
if not pypires: | ||
return | ||
keyboard = InlineKeyboard() | ||
keyboard.paginate( | ||
PageLen, CurrentPage, "page_pypi#{number}" + f"#{pesan.id}#{ctx.from_user.id}" | ||
msg = "" | ||
msg += f"<b>Package Name:</b> {res['info'].get('name', 'Unknown')}\n" | ||
msg += f"<b>Version:</b> {res['info'].get('version', 'Unknown')}\n" | ||
msg += f"<b>License:</b> {res['info'].get('license', 'Unknown')}\n" | ||
msg += f"<b>Author:</b> {res['info'].get('author', 'Unknown')}\n" | ||
msg += f"<b>Author Email:</b> {res['info'].get('author_email', 'Unknown')}\n" | ||
msg += f"<b>Requirements:</b> {requirement}\n" | ||
msg += ( | ||
f"<b>Requires Python:</b> {res['info'].get('requires_python', 'Unknown')}\n" | ||
) | ||
keyboard.row(InlineButton("👇 Get Info ", "Hmmm")) | ||
keyboard.row(*btn) | ||
msg += f"<b>HomePage:</b> {res['info'].get('home_page', 'Unknown')}\n" | ||
msg += f"<b>Bug Track:</b> {res['info'].get('vulnerabilities', 'Unknown')}\n" | ||
if res["info"].get("project_urls"): | ||
msg += f"<b>Docs Url:</b> {res['info']['project_urls'].get('Documentation', 'Unknown')}\n" | ||
msg += f"<b>Description:</b> {res['info'].get('summary', 'Unknown')}\n" | ||
msg += ( | ||
f"<b>Pip Command:</b> pip3 install {res['info'].get('name', 'Unknown')}\n" | ||
) | ||
msg += f"<b>Keywords:</b> {res['info'].get('keywords', 'Unknown')}\n" | ||
keyboard = InlineKeyboard() | ||
keyboard.row(InlineButton("❌ Close", f"close#{ctx.from_user.id}")) | ||
await pesan.edit_msg(pypires, reply_markup=keyboard) | ||
try: | ||
await pesan.edit_msg(msg, reply_markup=keyboard) | ||
except MessageTooLong: | ||
url = await post_to_telegraph(False, f"{res['info'].get('name')} {res['info'].get('version', None)}-detail", msg) | ||
await pesan.edit_msg(f"Result is too long:\n{url}", reply_markup=keyboard) | ||
|
||
|
||
@app.on_callback_query(filters.create(lambda _, __, query: "page_pypi#" in query.data)) | ||
|
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:
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.