Update chatbot/plugins/chat.py
Browse files- chatbot/plugins/chat.py +34 -2
chatbot/plugins/chat.py
CHANGED
@@ -24,6 +24,7 @@ import asyncio
|
|
24 |
import io
|
25 |
import os
|
26 |
import re
|
|
|
27 |
from PIL import Image
|
28 |
|
29 |
from pyrogram import *
|
@@ -43,6 +44,10 @@ from openai import AsyncOpenAI as openai
|
|
43 |
import akenoai.openai as akeno
|
44 |
import akenoai.logger as akeno_log
|
45 |
|
|
|
|
|
|
|
|
|
46 |
from . import force_sub
|
47 |
|
48 |
|
@@ -63,6 +68,27 @@ DISABLE_COMMAND = [
|
|
63 |
"ask"
|
64 |
]
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
GEMINI_START_TEXT = """
|
67 |
Hey! {name}
|
68 |
|
@@ -188,6 +214,9 @@ async def on_mode(client: Client, cb: CallbackQuery):
|
|
188 |
async def askcmd(client: Client, message: Message):
|
189 |
pro = await message.reply("Processing your request...", quote=True)
|
190 |
chat_user = await db.get_chatbot(message.chat.id)
|
|
|
|
|
|
|
191 |
if not chat_user:
|
192 |
await pro.edit_text("Ok disable")
|
193 |
return
|
@@ -208,7 +237,7 @@ async def askcmd(client: Client, message: Message):
|
|
208 |
model="gpt-4o",
|
209 |
messages=backup_chat
|
210 |
)
|
211 |
-
output = response.choices[0].message.content
|
212 |
if len(output) > 4096:
|
213 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
214 |
out_file.write(output)
|
@@ -257,6 +286,9 @@ async def askcmd(client: Client, message: Message):
|
|
257 |
async def chatbot_talk(client: Client, message: Message):
|
258 |
chat_user = await db.get_chatbot(message.chat.id)
|
259 |
pro = await message.reply("Processing your request...", quote=True)
|
|
|
|
|
|
|
260 |
if not chat_user:
|
261 |
await pro.edit_text("Ok disable")
|
262 |
return
|
@@ -285,7 +317,7 @@ async def chatbot_talk(client: Client, message: Message):
|
|
285 |
model="gpt-4o",
|
286 |
messages=backup_chat
|
287 |
)
|
288 |
-
output = response.choices[0].message.content
|
289 |
if len(output) > 4096:
|
290 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
291 |
out_file.write(output)
|
|
|
24 |
import io
|
25 |
import os
|
26 |
import re
|
27 |
+
import aiohttp
|
28 |
from PIL import Image
|
29 |
|
30 |
from pyrogram import *
|
|
|
44 |
import akenoai.openai as akeno
|
45 |
import akenoai.logger as akeno_log
|
46 |
|
47 |
+
from chatbot.plugins.user_database import users_collection
|
48 |
+
from chatbot.plugins.keyboards import get_language_keyboard
|
49 |
+
from chatbot.plugins.languages import LANGUAGES
|
50 |
+
|
51 |
from . import force_sub
|
52 |
|
53 |
|
|
|
68 |
"ask"
|
69 |
]
|
70 |
|
71 |
+
LANGUAGES_DEFAULT = "en"
|
72 |
+
|
73 |
+
async def translate(text, target_lang):
|
74 |
+
API_URL = "https://translate.googleapis.com/translate_a/single"
|
75 |
+
HEADERS = {"User-Agent": "Mozilla/5.0"}
|
76 |
+
params = {
|
77 |
+
"client": "gtx",
|
78 |
+
"sl": "auto",
|
79 |
+
"tl": target_lang,
|
80 |
+
"dt": "t",
|
81 |
+
"q": text,
|
82 |
+
}
|
83 |
+
async with aiohttp.ClientSession() as session:
|
84 |
+
async with session.post(API_URL, headers=HEADERS, params=params) as response:
|
85 |
+
if response.status == 200:
|
86 |
+
translation = await response.json()
|
87 |
+
translated_text = "".join([item[0] for item in translation[0]])
|
88 |
+
return translated_text
|
89 |
+
else:
|
90 |
+
return None
|
91 |
+
|
92 |
GEMINI_START_TEXT = """
|
93 |
Hey! {name}
|
94 |
|
|
|
214 |
async def askcmd(client: Client, message: Message):
|
215 |
pro = await message.reply("Processing your request...", quote=True)
|
216 |
chat_user = await db.get_chatbot(message.chat.id)
|
217 |
+
user_id = message.from_user.id
|
218 |
+
user = await users_collection.find_one({"user_id": user_id})
|
219 |
+
lang = user.get("language") if user else LANGUAGES_DEFAULT
|
220 |
if not chat_user:
|
221 |
await pro.edit_text("Ok disable")
|
222 |
return
|
|
|
237 |
model="gpt-4o",
|
238 |
messages=backup_chat
|
239 |
)
|
240 |
+
output = await translate(response.choices[0].message.content, lang)
|
241 |
if len(output) > 4096:
|
242 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
243 |
out_file.write(output)
|
|
|
286 |
async def chatbot_talk(client: Client, message: Message):
|
287 |
chat_user = await db.get_chatbot(message.chat.id)
|
288 |
pro = await message.reply("Processing your request...", quote=True)
|
289 |
+
user_id = message.from_user.id
|
290 |
+
user = await users_collection.find_one({"user_id": user_id})
|
291 |
+
lang = user.get("language") if user else LANGUAGES_DEFAULT
|
292 |
if not chat_user:
|
293 |
await pro.edit_text("Ok disable")
|
294 |
return
|
|
|
317 |
model="gpt-4o",
|
318 |
messages=backup_chat
|
319 |
)
|
320 |
+
output = await translate(response.choices[0].message.content, lang)
|
321 |
if len(output) > 4096:
|
322 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
323 |
out_file.write(output)
|