randydev's picture
Update chatbot/plugins/web.py
52b19bc verified
raw
history blame
3.04 kB
import asyncio
import time
import os
import datetime
import aiohttp
from pyrogram import Client, filters
from pyrogram.types import *
from pyrogram.enums import *
from pyrogram import *
from database import db
from chatbot.plugins.user_database import users_collection
from chatbot.plugins.keyboards import get_language_keyboard
from chatbot.plugins.languages import LANGUAGES
import akenoai as dev
from . import force_sub
LANGUAGES_DEFAULT = "en"
BASE_PROMPT = f"""
You are my name Akeno AI and python language powered by @xtdevs on telegram support and language models GPT-5-ULTRA
- off topic free questions
- Code python clone user telegram available : [HERE LINK](https://github.com/TeamKillerX/akenoai-lib/blob/main/examples/clone.py) by credits @xtdevs
- Support pyrogram and telethon not python-telegram-bot
{datetime.datetime.now()}
"""
@Client.on_message(
~filters.scheduled
& filters.command(["web"])
& ~filters.forwarded
)
@force_sub
async def askwebcmd(client: Client, message: Message):
pro = await message.reply("Processing your web request...", quote=True)
user_id = message.from_user.id
user = await users_collection.find_one({"user_id": user_id})
lang = user.get("language") if user else LANGUAGES_DEFAULT
chat_user = await db.get_chatbot(message.chat.id)
if not chat_user:
return await pro.edit_text("I need to enable group")
if len(message.command) > 1:
prompt = message.text.split(maxsplit=1)[1]
elif message.reply_to_message:
prompt = message.reply_to_message.text
else:
return await pro.edit_text("Give ask from GPT-5")
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
await asyncio.sleep(1.5)
if not lang:
await message.reply(
"Please select your preferred language:",
reply_markup=get_language_keyboard()
)
await pro.delete()
return
try:
backup_chat = await db._get_openai_chat_from_db(message.from_user.id)
backup_chat.append({"role": "system", "content": BASE_PROMPT})
backup_chat.append({"role": "user", "content": prompt})
akeno_api = dev.AkenoPlus(...)
response = await akeno_api.chatgpt_mode_web(
query=prompt,
is_trans="True",
lang=lang
)
data = await akeno_api.get_json(response=response)
backup_chat.append({"role": "assistant", "content": data.randydev.message})
await pro.edit_text(data.randydev.message, disable_web_page_preview=True)
await db._update_openai_chat_in_db(message.from_user.id, backup_chat)
except aiohttp.ContentTypeError as e:
return await pro.edit_text("Error: try again.")
except Exception as e:
await pro.edit_text("Error: try again")
@Client.on_message(filters.command("setlang"))
async def setlang_cmd(client: Client, message: Message):
await message.reply(
"Please select your preferred language:",
reply_markup=get_language_keyboard()
)