From c4b876c0fe8f81e15ca61fcc6c9b467a3eb5be33 Mon Sep 17 00:00:00 2001 From: TrueSaiyan Date: Fri, 26 Jan 2024 14:51:53 +0800 Subject: [PATCH] Update _chatactions.py --- plugins/_chatactions.py | 57 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/plugins/_chatactions.py b/plugins/_chatactions.py index caf0655de..7d91dde7c 100644 --- a/plugins/_chatactions.py +++ b/plugins/_chatactions.py @@ -21,7 +21,7 @@ from pyUltroid.dB.greetings_db import get_goodbye, get_welcome, must_thank from pyUltroid.dB.nsfw_db import is_profan from pyUltroid.fns.helper import check_reply_to, inline_mention -from pyUltroid.fns.tools import async_searcher, create_tl_btn, get_chatbot_reply +from pyUltroid.fns.tools import async_searcher, create_tl_btn, get_chatbot_reply, get_oracle_reply try: from ProfanityDetector import detector @@ -304,6 +304,61 @@ async def chatBot_replies(e): if y: await e.delete() +@ultroid_bot.on(events.NewMessage(incoming=True)) +async def oracleBot_replies(e): + xxxrep = await check_reply_to(e) + + if xxxrep: + sender = await e.get_sender() + if not isinstance(sender, types.User) or sender.bot: + return + if check_echo(e.chat_id, e.sender_id): + try: + await e.respond(e.message) + except Exception as er: + LOGS.exception(er) + key = udB.get_key("ORACLE_USERS") or {} + if e.text and key.get(e.chat_id) and sender.id in key[e.chat_id]: + # Simulate typing indicator + async with e.client.action(e.chat_id, "typing"): + msg = await get_gem_reply( + e.message.message, user_id=sender.id, mongo_url=MONGO_URI + ) + if msg: + sleep = udB.get_key("ORACLE_SLEEP") or 1.5 + await asyncio.sleep(sleep) + + # Check if the message length exceeds a certain threshold + if len(msg) > 4096: + # Create a temporary text file + with tempfile.NamedTemporaryFile( + mode="w+", delete=False + ) as temp_file: + temp_file.write(msg) + + # Send the text file with a caption + await e.client.send_file( + e.chat_id, + temp_file.name, + caption="Here is the response in a text file", + ) + + # Delete the temporary text file + os.remove(temp_file.name) + else: + # Send the message directly + await e.reply(msg) + + chat = await e.get_chat() + if e.is_group and sender.username: + await uname_stuff(e.sender_id, sender.username, sender.first_name) + elif e.is_private and chat.username: + await uname_stuff(e.sender_id, chat.username, chat.first_name) + if detector and is_profan(e.chat_id) and e.text: + x, y = detector(e.text) + if y: + await e.delete() + @ultroid_bot.on(events.Raw(types.UpdateUserName)) async def uname_change(e):