Opera8 commited on
Commit
c3ae020
·
verified ·
1 Parent(s): 808c524

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -13
main.py CHANGED
@@ -93,7 +93,7 @@ async def helper_download_file(client, msg_obj):
93
 
94
  file_id = None
95
  file_obj = None
96
- for attr in['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
97
  val = getattr(msg_obj, attr, None)
98
  if val:
99
  file_obj = val
@@ -156,7 +156,7 @@ async def helper_upload_file(client, chat_id, file_name, file_type="Image", capt
156
  abs_path = os.path.abspath(file_name)
157
  error_logs =[]
158
 
159
- api_file_type = "Image" if file_type in["photo", "Image", "image"] else "Voice" if file_type in["voice", "Voice", "audio"] else "File"
160
 
161
  try:
162
  url_request = f"https://botapi.rubika.ir/v3/{bot_token}/requestSendFile"
@@ -659,7 +659,7 @@ else:
659
  msg_obj = getattr(update, "message", None) or getattr(update, "new_message", None)
660
 
661
  if msg_obj:
662
- for attr in['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
663
  file_attr = getattr(msg_obj, attr, None)
664
  if file_attr:
665
  is_file = True
@@ -668,7 +668,7 @@ else:
668
 
669
  if not is_file and hasattr(msg_obj, 'to_dict'):
670
  msg_dict = msg_obj.to_dict()
671
- for attr in['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
672
  if attr in msg_dict:
673
  is_file = True
674
  file_attr = msg_dict.get(attr, {})
@@ -681,38 +681,38 @@ else:
681
  if chat_id not in user_states:
682
  user_states[chat_id] = {"mode": None, "text": "", "history":[], "file_bytes": None, "file_name": None}
683
 
684
- if user_text_str in["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
685
  user_states[chat_id] = {"mode": None, "text": "", "history":[], "file_bytes": None, "file_name": None}
686
  await send_with_keyboard(client, chat_id, "سلام! به ربات هوشمند آلفا خوش آمدید 🤖\n\nلطفاً برای شروع، از کیبورد پایین یکی از بخش‌ها را انتخاب کنید:", True)
687
  return
688
 
689
- if user_text_str in["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
 
690
  user_states[chat_id] = {"mode": "chat", "text": "", "history":[]}
691
  await send_with_keyboard(client, chat_id, "💬 شما وارد بخش **چت با هوش مصنوعی** شدید.\n\nهر سوالی دارید بفرستید تا جواب بدم:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
692
  return
693
 
694
- if user_text_str in["/image", "🎨 عکس", "ساخت تصاویر با هوش مصنوعی🎨"]:
695
  user_states[chat_id] = {"mode": "image_waiting_for_text", "text": "", "history":[]}
696
  await send_with_keyboard(client, chat_id, "🎨 شما وارد بخش **ساخت عکس پیشرفته** شدید.\n\nمتن خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
697
  return
698
 
699
- if user_text_str in["/tts", "🎙️ صدا", "تبدیل متن به صدا با هوش مصنوعی🎙️"]:
700
  user_states[chat_id] = {"mode": "tts_waiting_for_text", "text": "", "history":[]}
701
  await send_with_keyboard(client, chat_id, "🎙️ شما وارد بخش **تبدیل متن به صدا** شدید.\n\nلطفاً متنی که می‌خواهید به صدا تبدیل شود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
702
  return
703
 
704
- # --- دکمه جدید برای پادکست ---
705
- if user_text_str in["/podcast", "📻 پادکست", "ساخت پادکست با هوش مصنوعی 📻"]:
706
  user_states[chat_id] = {"mode": "podcast_waiting_for_topic", "text": "", "history":[]}
707
  await send_with_keyboard(client, chat_id, "📻 شما وارد بخش **ساخت پادکست** شدید.\n\nلطفاً موضوع پادکست خود را بفرستید.\nمثال: درباره تاریخچه پیدایش قهوه با ۳ گوینده یک پادکست جذاب بساز\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
708
  return
709
 
710
- if user_text_str in["/file", "تحلیل فایل با هوش مصنوعی 📁"]:
711
  user_states[chat_id] = {"mode": "file_waiting_for_file", "text": "", "history":[], "file_bytes": None, "file_name": None}
712
  await send_with_keyboard(client, chat_id, "📁 شما وارد بخش **تحلیل فایل اختصاصی** شدید.\n\nلطفاً فایل خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
713
  return
714
 
715
- if user_text_str in["/stt", "تبدیل فایل صوتی به متن 📝"]:
716
  user_states[chat_id] = {"mode": "stt_waiting_for_audio", "text": "", "history":[]}
717
  await send_with_keyboard(client, chat_id, "📝 شما وارد بخش **تبدیل صدا به متن** شدید.\n\nلطفاً فایل خود (ویس، آهنگ، ویدیو و...) را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
718
  return
@@ -819,4 +819,4 @@ if __name__ == "__main__":
819
 
820
  if bot_token:
821
  print("ربات یکپارچه آلفا روشن شد...")
822
- bot.run()
 
93
 
94
  file_id = None
95
  file_obj = None
96
+ for attr in ['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
97
  val = getattr(msg_obj, attr, None)
98
  if val:
99
  file_obj = val
 
156
  abs_path = os.path.abspath(file_name)
157
  error_logs =[]
158
 
159
+ api_file_type = "Image" if file_type in ["photo", "Image", "image"] else "Voice" if file_type in ["voice", "Voice", "audio"] else "File"
160
 
161
  try:
162
  url_request = f"https://botapi.rubika.ir/v3/{bot_token}/requestSendFile"
 
659
  msg_obj = getattr(update, "message", None) or getattr(update, "new_message", None)
660
 
661
  if msg_obj:
662
+ for attr in ['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
663
  file_attr = getattr(msg_obj, attr, None)
664
  if file_attr:
665
  is_file = True
 
668
 
669
  if not is_file and hasattr(msg_obj, 'to_dict'):
670
  msg_dict = msg_obj.to_dict()
671
+ for attr in ['file', 'file_inline', 'photo', 'voice', 'audio', 'document', 'video']:
672
  if attr in msg_dict:
673
  is_file = True
674
  file_attr = msg_dict.get(attr, {})
 
681
  if chat_id not in user_states:
682
  user_states[chat_id] = {"mode": None, "text": "", "history":[], "file_bytes": None, "file_name": None}
683
 
684
+ if user_text_str in ["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
685
  user_states[chat_id] = {"mode": None, "text": "", "history":[], "file_bytes": None, "file_name": None}
686
  await send_with_keyboard(client, chat_id, "سلام! به ربات هوشمند آلفا خوش آمدید 🤖\n\nلطفاً برای شروع، از کیبورد پایین یکی از بخش‌ها را انتخاب کنید:", True)
687
  return
688
 
689
+ # اصلاح شرط‌های if منطبق با متن دکمه‌های جدید
690
+ if user_text_str in ["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
691
  user_states[chat_id] = {"mode": "chat", "text": "", "history":[]}
692
  await send_with_keyboard(client, chat_id, "💬 شما وارد بخش **چت با هوش مصنوعی** شدید.\n\nهر سوالی دارید بفرستید تا جواب بدم:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
693
  return
694
 
695
+ if user_text_str in ["/image", "🎨 عکس", "ساخت تصاویر🎨"]:
696
  user_states[chat_id] = {"mode": "image_waiting_for_text", "text": "", "history":[]}
697
  await send_with_keyboard(client, chat_id, "🎨 شما وارد بخش **ساخت عکس پیشرفته** شدید.\n\nمتن خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
698
  return
699
 
700
+ if user_text_str in ["/tts", "🎙️ صدا", "تبدیل متن به صدا🗣️"]:
701
  user_states[chat_id] = {"mode": "tts_waiting_for_text", "text": "", "history":[]}
702
  await send_with_keyboard(client, chat_id, "🎙️ شما وارد بخش **تبدیل متن به صدا** شدید.\n\nلطفاً متنی که می‌خواهید به صدا تبدیل شود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
703
  return
704
 
705
+ if user_text_str in ["/podcast", "📻 پادکست", اخت پادکست 🎙️"]:
 
706
  user_states[chat_id] = {"mode": "podcast_waiting_for_topic", "text": "", "history":[]}
707
  await send_with_keyboard(client, chat_id, "📻 شما وارد بخش **ساخت پادکست** شدید.\n\nلطفاً موضوع پادکست خود را بفرستید.\nمثال: درباره تاریخچه پیدایش قهوه با ۳ گوینده یک پادکست جذاب بساز\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
708
  return
709
 
710
+ if user_text_str in ["/file", "تحلیل فایل 📁"]:
711
  user_states[chat_id] = {"mode": "file_waiting_for_file", "text": "", "history":[], "file_bytes": None, "file_name": None}
712
  await send_with_keyboard(client, chat_id, "📁 شما وارد بخش **تحلیل فایل اختصاصی** شدید.\n\nلطفاً فایل خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
713
  return
714
 
715
+ if user_text_str in ["/stt", "فایل صوتی به متن 📝"]:
716
  user_states[chat_id] = {"mode": "stt_waiting_for_audio", "text": "", "history":[]}
717
  await send_with_keyboard(client, chat_id, "📝 شما وارد بخش **تبدیل صدا به متن** شدید.\n\nلطفاً فایل خود (ویس، آهنگ، ویدیو و...) را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
718
  return
 
819
 
820
  if bot_token:
821
  print("ربات یکپارچه آلفا روشن شد...")
822
+ bot.run()