diff --git a/misskaty/plugins/admin.py b/misskaty/plugins/admin.py index 89611db9de..085d575a44 100644 --- a/misskaty/plugins/admin.py +++ b/misskaty/plugins/admin.py @@ -620,9 +620,12 @@ async def warn_user(client, message, strings): if message.command[0][0] == "d": await message.reply_to_message.delete() if warns >= 2: - 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: + await message.chat.ban_member(user_id) + await message.reply_msg(strings("exceed_warn_msg").format(mention=mention)) + await remove_warns(chat_id, await int_to_alpha(user_id)) + except ChatAdminRequired: + await message.reply_msg(strings("no_ban_permission")) else: warn = {"warns": warns + 1} msg = strings("warn_msg").format( @@ -631,7 +634,7 @@ async def warn_user(client, message, strings): reas=reason or "No Reason Provided.", twarn=warns + 1, ) - await message.reply_text(msg, reply_markup=keyboard) + await message.reply_msg(msg, reply_markup=keyboard) await add_warn(chat_id, await int_to_alpha(user_id), warn) diff --git a/misskaty/plugins/chatbot_ai.py b/misskaty/plugins/chatbot_ai.py index 8cfef0a8c4..a72d2e4b58 100644 --- a/misskaty/plugins/chatbot_ai.py +++ b/misskaty/plugins/chatbot_ai.py @@ -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) if not ai_response: gptai_conversations[uid].pop() if len(gptai_conversations[uid]) == 1: diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py index aada9fd43c..1a242f3a14 100644 --- a/misskaty/plugins/dev.py +++ b/misskaty/plugins/dev.py @@ -38,6 +38,8 @@ FloodWait, MessageTooLong, PeerIdInvalid, + RPCError, + SlowmodeWait, ) from pyrogram.raw.types import UpdateBotStopped from pyrogram.types import ( @@ -659,6 +661,14 @@ async def update_restart(_, ctx: Message, strings): os.execvp(sys.executable, [sys.executable, "-m", "misskaty"]) +@app.on_error(errors=(FloodWait, RPCError, SlowmodeWait)) +async def error_handlers(_: "Client", __: "Update", error: "Exception") -> None: + if isinstance(error, (FloodWait, SlowmodeWait)): + await asyncio.sleep(error.value) + else: + LOGGER.error(repr(error)) + + @app.on_raw_update(group=-99) async def updtebot(client, update, users, _): if isinstance(update, UpdateBotStopped): diff --git a/misskaty/plugins/misc_tools.py b/misskaty/plugins/misc_tools.py index c1d5909f10..da10431ad7 100644 --- a/misskaty/plugins/misc_tools.py +++ b/misskaty/plugins/misc_tools.py @@ -340,9 +340,9 @@ def shorten_text(text): for result in soup.select(".tF2Cxc"): link = result.select_one(".yuRUbf a")["href"] title = result.select_one(".DKV0Md").text - if snippet := result.find(class_="VwiC3b yXK7lf lVm3ye r025kc hJNv6b"): + if snippet := result.find(class_="VwiC3b yXK7lf p4wth r025kc hJNv6b"): snippet = snippet.get_text() - elif snippet := result.find(class_="VwiC3b yXK7lf lVm3ye r025kc hJNv6b Hdw6tb"): + elif snippet := result.find(class_="VwiC3b yXK7lf p4wth r025kc hJNv6b Hdw6tb"): snippet = snippet.get_text() else: snippet = "-" diff --git a/misskaty/plugins/pypi_search.py b/misskaty/plugins/pypi_search.py index 9cf776f904..9fa4f8789b 100644 --- a/misskaty/plugins/pypi_search.py +++ b/misskaty/plugins/pypi_search.py @@ -50,20 +50,41 @@ async def pypi_s(_, ctx: Message): "Please add query after command. Ex: /pypi pyrogram", 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() + 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"Package Name: {res['info'].get('name', 'Unknown')}\n" + msg += f"Version: {res['info'].get('version', 'Unknown')}\n" + msg += f"License: {res['info'].get('license', 'Unknown')}\n" + msg += f"Author: {res['info'].get('author', 'Unknown')}\n" + msg += f"Author Email: {res['info'].get('author_email', 'Unknown')}\n" + msg += f"Requirements: {requirement}\n" + msg += ( + f"Requires Python: {res['info'].get('requires_python', 'Unknown')}\n" ) - keyboard.row(InlineButton("👇 Get Info ", "Hmmm")) - keyboard.row(*btn) + msg += f"HomePage: {res['info'].get('home_page', 'Unknown')}\n" + msg += f"Bug Track: {res['info'].get('vulnerabilities', 'Unknown')}\n" + if res["info"].get("project_urls"): + msg += f"Docs Url: {res['info']['project_urls'].get('Documentation', 'Unknown')}\n" + msg += f"Description: {res['info'].get('summary', 'Unknown')}\n" + msg += ( + f"Pip Command: pip3 install {res['info'].get('name', 'Unknown')}\n" + ) + msg += f"Keywords: {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)) diff --git a/utils.py b/utils.py index 09aeb0b68e..d66c34b251 100644 --- a/utils.py +++ b/utils.py @@ -72,7 +72,7 @@ async def broadcast_messages(user_id, message): await message.copy(chat_id=user_id) return True, "Succes" except FloodWait as e: - await asyncio.sleep(e.x) + await asyncio.sleep(e.value) return await broadcast_messages(user_id, message) except InputUserDeactivated: await db.delete_user(int(user_id))