randydev commited on
Commit
43be786
·
verified ·
1 Parent(s): 8cb3718

Update chatbot/plugins/chat.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/chat.py +52 -2
chatbot/plugins/chat.py CHANGED
@@ -931,10 +931,60 @@ async def chatbot_talk(client: Client, message: Message):
931
  if regex_all_blacklist(caption):
932
  return await message.reply_text("You been blocked blacklisted")
933
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
934
  if re.findall(r"\b(This is a picture of me)\b", caption, re.IGNORECASE):
935
  if caption == "picture" or len(caption) > 300:
936
  return await message.reply_text(
937
- "You can't write **picture** small, it has to be long OR short first\n"
938
  "OR Caption Too many `MAX_CAPTION: 300`"
939
  )
940
  try:
@@ -1162,7 +1212,7 @@ async def chatbot_talk(client: Client, message: Message):
1162
  if regex_all_blacklist(query_base):
1163
  return await message.reply_text("You been blocked blacklisted")
1164
 
1165
- if query_base in ["/", "/help"]:
1166
  await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
1167
  return
1168
 
 
931
  if regex_all_blacklist(caption):
932
  return await message.reply_text("You been blocked blacklisted")
933
 
934
+ if caption == "--stream-image":
935
+ return await message.reply_text(
936
+ "You can't --stream-image, it has to be long OR short first\n"
937
+ )
938
+
939
+ stream_image_now = re.sub(r"--stream-image", "", caption).strip()
940
+ if stream_image_now:
941
+ STREAM_IMAGE_PATH = await message.download()
942
+ try:
943
+ backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
944
+ backup_chat.append({"role": "user", "parts": [{"text": caption}]})
945
+ with open(STREAM_IMAGE_PATH, 'rb') as f:
946
+ image_bytes = f.read()
947
+ async for chunk in await gen.aio.models.generate_content_stream(
948
+ model='gemini-2.0-flash-001',
949
+ contents=[
950
+ str(caption),
951
+ ty.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
952
+ ]
953
+ ):
954
+ captions += chunk.text
955
+
956
+ if captions == "":
957
+ return await message.reply_text("Server busy try again later")
958
+
959
+ keyboard = create_keyboard(user_id=message.from_user.id)
960
+ await message.reply_text(
961
+ captions,
962
+ disable_web_page_preview=True,
963
+ reply_markup=keyboard
964
+ )
965
+
966
+ await db.backup_chatbot.update_one(
967
+ {"user_id": message.from_user.id},
968
+ {"$set": {"translate_text": captions}},
969
+ upsert=True
970
+ )
971
+ backup_chat.append({"role": "model", "parts": [{"text": captions}]})
972
+ await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
973
+ await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
974
+ return
975
+ except Exception as e:
976
+ return await message.reply_text("Server busy try again later")
977
+ finally:
978
+ if STREAM_IMAGE_PATH:
979
+ try:
980
+ os.remove(STREAM_IMAGE_PATH)
981
+ except:
982
+ pass
983
+
984
  if re.findall(r"\b(This is a picture of me)\b", caption, re.IGNORECASE):
985
  if caption == "picture" or len(caption) > 300:
986
  return await message.reply_text(
987
+ "You can't **picture** small, it has to be long OR short first\n"
988
  "OR Caption Too many `MAX_CAPTION: 300`"
989
  )
990
  try:
 
1212
  if regex_all_blacklist(query_base):
1213
  return await message.reply_text("You been blocked blacklisted")
1214
 
1215
+ if query_base in ["/", "/help", "about:", "enabled:", "disabled:"]:
1216
  await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
1217
  return
1218