Spaces:
Running
Running
Update chatbot/plugins/chat.py
Browse files- chatbot/plugins/chat.py +14 -1
chatbot/plugins/chat.py
CHANGED
@@ -27,6 +27,7 @@ import re
|
|
27 |
from PIL import Image
|
28 |
|
29 |
from pyrogram import *
|
|
|
30 |
from pyrogram import Client, filters
|
31 |
from pyrogram.types import *
|
32 |
from pyrogram.errors import *
|
@@ -53,7 +54,7 @@ USER_TRACK = """
|
|
53 |
|
54 |
UserID: {user_id}
|
55 |
First Name: {first_name}
|
56 |
-
Username:
|
57 |
"""
|
58 |
|
59 |
@Client.on_message(
|
@@ -75,6 +76,8 @@ Username: @{username}
|
|
75 |
async def chatbot_talk(client: Client, message: Message):
|
76 |
genai.configure(api_key=GOOGLE_API_KEY)
|
77 |
if message.photo:
|
|
|
|
|
78 |
file_path = await message.download()
|
79 |
caption = message.caption or "What's this?"
|
80 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
@@ -107,6 +110,7 @@ async def chatbot_talk(client: Client, message: Message):
|
|
107 |
)
|
108 |
backup_chat.append({"role": "model", "parts": [{"text": response_reads}]})
|
109 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
|
|
110 |
os.remove(file_path)
|
111 |
return
|
112 |
except InvalidArgument as e:
|
@@ -115,6 +119,8 @@ async def chatbot_talk(client: Client, message: Message):
|
|
115 |
return await ai_reply.edit_text(f"Error: {e}")
|
116 |
|
117 |
if message.audio or message.voice:
|
|
|
|
|
118 |
if client.me.is_premium:
|
119 |
ai_reply = await message.reply_text(f"{custom_loading}Processing...")
|
120 |
else:
|
@@ -171,6 +177,7 @@ async def chatbot_talk(client: Client, message: Message):
|
|
171 |
)
|
172 |
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
173 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
|
|
174 |
audio_file.delete()
|
175 |
os.remove(audio_file_name)
|
176 |
return
|
@@ -180,6 +187,8 @@ async def chatbot_talk(client: Client, message: Message):
|
|
180 |
return await ai_reply.edit_text(f"Error: {e}")
|
181 |
|
182 |
if message.video:
|
|
|
|
|
183 |
if client.me.is_premium:
|
184 |
ai_reply = await message.reply_text(f"{custom_loading}Processing...")
|
185 |
else:
|
@@ -233,6 +242,7 @@ async def chatbot_talk(client: Client, message: Message):
|
|
233 |
)
|
234 |
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
235 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
|
|
236 |
video_file.delete()
|
237 |
os.remove(video_file_name)
|
238 |
return
|
@@ -242,6 +252,8 @@ async def chatbot_talk(client: Client, message: Message):
|
|
242 |
return await ai_reply.edit_text(f"Error: {e}")
|
243 |
|
244 |
if message.text:
|
|
|
|
|
245 |
query = message.text.strip()
|
246 |
match = re.search(r"\b(Randy|Rendi)\b(.*)", query, flags=re.IGNORECASE)
|
247 |
if match:
|
@@ -281,5 +293,6 @@ async def chatbot_talk(client: Client, message: Message):
|
|
281 |
)
|
282 |
backup_chat.append({"role": "model", "parts": [{"text": output}]})
|
283 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
|
|
284 |
except Exception as e:
|
285 |
return await message.reply_text(str(e))
|
|
|
27 |
from PIL import Image
|
28 |
|
29 |
from pyrogram import *
|
30 |
+
from pyrogram import enums
|
31 |
from pyrogram import Client, filters
|
32 |
from pyrogram.types import *
|
33 |
from pyrogram.errors import *
|
|
|
54 |
|
55 |
UserID: {user_id}
|
56 |
First Name: {first_name}
|
57 |
+
Username: `{username}`
|
58 |
"""
|
59 |
|
60 |
@Client.on_message(
|
|
|
76 |
async def chatbot_talk(client: Client, message: Message):
|
77 |
genai.configure(api_key=GOOGLE_API_KEY)
|
78 |
if message.photo:
|
79 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
80 |
+
await asyncio.sleep(1.5)
|
81 |
file_path = await message.download()
|
82 |
caption = message.caption or "What's this?"
|
83 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
|
|
110 |
)
|
111 |
backup_chat.append({"role": "model", "parts": [{"text": response_reads}]})
|
112 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
113 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
114 |
os.remove(file_path)
|
115 |
return
|
116 |
except InvalidArgument as e:
|
|
|
119 |
return await ai_reply.edit_text(f"Error: {e}")
|
120 |
|
121 |
if message.audio or message.voice:
|
122 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
123 |
+
await asyncio.sleep(1.5)
|
124 |
if client.me.is_premium:
|
125 |
ai_reply = await message.reply_text(f"{custom_loading}Processing...")
|
126 |
else:
|
|
|
177 |
)
|
178 |
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
179 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
180 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
181 |
audio_file.delete()
|
182 |
os.remove(audio_file_name)
|
183 |
return
|
|
|
187 |
return await ai_reply.edit_text(f"Error: {e}")
|
188 |
|
189 |
if message.video:
|
190 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
191 |
+
await asyncio.sleep(1.5)
|
192 |
if client.me.is_premium:
|
193 |
ai_reply = await message.reply_text(f"{custom_loading}Processing...")
|
194 |
else:
|
|
|
242 |
)
|
243 |
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
244 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
245 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
246 |
video_file.delete()
|
247 |
os.remove(video_file_name)
|
248 |
return
|
|
|
252 |
return await ai_reply.edit_text(f"Error: {e}")
|
253 |
|
254 |
if message.text:
|
255 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
256 |
+
await asyncio.sleep(1.5)
|
257 |
query = message.text.strip()
|
258 |
match = re.search(r"\b(Randy|Rendi)\b(.*)", query, flags=re.IGNORECASE)
|
259 |
if match:
|
|
|
293 |
)
|
294 |
backup_chat.append({"role": "model", "parts": [{"text": output}]})
|
295 |
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
296 |
+
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
297 |
except Exception as e:
|
298 |
return await message.reply_text(str(e))
|