Skip to content

Commit

Permalink
Update _chatactions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoptg authored Jan 26, 2024
1 parent 7133f62 commit c4b876c
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion plugins/_chatactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c4b876c

Please sign in to comment.