Opera8 commited on
Commit
c45166f
·
verified ·
1 Parent(s): aff10a7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +41 -13
main.py CHANGED
@@ -85,7 +85,8 @@ def save_db(db_data):
85
  user_credits_db = load_db()
86
 
87
  def get_user_credits(chat_id):
88
- str_chat_id = str(chat_id)
 
89
  today_str = datetime.date.today().isoformat()
90
 
91
  if str_chat_id not in user_credits_db:
@@ -381,7 +382,7 @@ user_last_request_time = {}
381
 
382
  # --- ۱. پردازش چت متنی و چندرسانه‌ای ---
383
  async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=None):
384
- str_chat_id = str(chat_id)
385
  creds = get_user_credits(str_chat_id)
386
  if creds["chat"] <= 0:
387
  return await send_with_keyboard(client, chat_id, "❌ اعتبار پیام‌های چت شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -478,7 +479,7 @@ async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=Non
478
 
479
  # --- ۲. پردازش ساخت عکس ---
480
  async def process_image(client, chat_id, prompt):
481
- str_chat_id = str(chat_id)
482
  creds = get_user_credits(str_chat_id)
483
  if creds["image"] <= 0:
484
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت عکس شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -554,7 +555,7 @@ async def process_image(client, chat_id, prompt):
554
 
555
  # --- ۲.۵. پردازش ویرایش عکس با FLUX.2-dev ---
556
  async def process_image_edit(client, chat_id, image_bytes, prompt):
557
- str_chat_id = str(chat_id)
558
  creds = get_user_credits(str_chat_id)
559
  if creds["edit_image"] <= 0:
560
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ویرایش عکس شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -612,7 +613,7 @@ async def process_image_edit(client, chat_id, image_bytes, prompt):
612
 
613
  # --- ۳. پردازش ساخت صدا ---
614
  async def process_tts(client, chat_id, user_text, speaker_id, speaker_name):
615
- str_chat_id = str(chat_id)
616
  creds = get_user_credits(str_chat_id)
617
  if creds["tts"] <= 0:
618
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل متن به صدای شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -663,7 +664,7 @@ async def process_tts(client, chat_id, user_text, speaker_id, speaker_name):
663
 
664
  # --- ۳.۵. پردازش پادکست ---
665
  async def process_podcast(client, chat_id, prompt):
666
- str_chat_id = str(chat_id)
667
  creds = get_user_credits(str_chat_id)
668
  if creds["podcast"] <= 0:
669
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت پادکست شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -753,7 +754,7 @@ async def process_podcast(client, chat_id, prompt):
753
 
754
  # --- ۴. پردازش تبدیل فایل صوتی/تصویری به متن ---
755
  async def process_stt(client, chat_id, audio_bytes, file_name):
756
- str_chat_id = str(chat_id)
757
  creds = get_user_credits(str_chat_id)
758
  if creds["stt"] <= 0:
759
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل صدا به متن شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -800,7 +801,7 @@ async def process_stt(client, chat_id, audio_bytes, file_name):
800
 
801
  # --- ۵. پردازش تحلیل فایل مستقل ---
802
  async def process_file_analysis(client, chat_id, file_bytes, file_name, prompt):
803
- str_chat_id = str(chat_id)
804
  creds = get_user_credits(str_chat_id)
805
  if creds["file"] <= 0:
806
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تحلیل فایل شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
@@ -910,10 +911,22 @@ else:
910
  if user_states[chat_id].get("is_admin"):
911
  if user_text_str.startswith("/upgrade"):
912
  parts = user_text_str.split()
913
- if len(parts) == 2:
914
- target_id = parts[1]
 
915
  if target_id not in user_credits_db:
916
- user_credits_db[target_id] = {"is_premium": False}
 
 
 
 
 
 
 
 
 
 
 
917
 
918
  user_credits_db[target_id]["is_premium"] = True
919
 
@@ -932,14 +945,21 @@ else:
932
 
933
  save_db(user_credits_db)
934
  await send_with_keyboard(client, chat_id, f"✅ حساب کاربر `{target_id}` به مدت ۳۰ روز شارژ شد و به پرو ارتقا یافت.", False)
 
 
 
 
 
 
 
935
  else:
936
  await send_with_keyboard(client, chat_id, "⚠️ فرمت صحیح: `/upgrade ID`", False)
937
  return
938
 
939
  if user_text_str.startswith("/downgrade"):
940
  parts = user_text_str.split()
941
- if len(parts) == 2:
942
- target_id = parts[1]
943
  if target_id in user_credits_db:
944
  user_credits_db[target_id]["is_premium"] = False
945
  user_credits_db[target_id]["expire_date"] = None
@@ -947,6 +967,14 @@ else:
947
  user_credits_db[target_id]["last_reset"] = ""
948
  save_db(user_credits_db)
949
  await send_with_keyboard(client, chat_id, f"✅ اشتراک کاربر `{target_id}` لغو شد و به رایگان تبدیل گشت.", False)
 
 
 
 
 
 
 
 
950
  return
951
 
952
  # تشخیص فایل
 
85
  user_credits_db = load_db()
86
 
87
  def get_user_credits(chat_id):
88
+ # اطمینان از پاک بودن استرینگ از علائم مزاحم
89
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
90
  today_str = datetime.date.today().isoformat()
91
 
92
  if str_chat_id not in user_credits_db:
 
382
 
383
  # --- ۱. پردازش چت متنی و چندرسانه‌ای ---
384
  async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=None):
385
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
386
  creds = get_user_credits(str_chat_id)
387
  if creds["chat"] <= 0:
388
  return await send_with_keyboard(client, chat_id, "❌ اعتبار پیام‌های چت شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
479
 
480
  # --- ۲. پردازش ساخت عکس ---
481
  async def process_image(client, chat_id, prompt):
482
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
483
  creds = get_user_credits(str_chat_id)
484
  if creds["image"] <= 0:
485
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت عکس شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
555
 
556
  # --- ۲.۵. پردازش ویرایش عکس با FLUX.2-dev ---
557
  async def process_image_edit(client, chat_id, image_bytes, prompt):
558
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
559
  creds = get_user_credits(str_chat_id)
560
  if creds["edit_image"] <= 0:
561
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ویرایش عکس شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
613
 
614
  # --- ۳. پردازش ساخت صدا ---
615
  async def process_tts(client, chat_id, user_text, speaker_id, speaker_name):
616
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
617
  creds = get_user_credits(str_chat_id)
618
  if creds["tts"] <= 0:
619
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل متن به صدای شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
664
 
665
  # --- ۳.۵. پردازش پادکست ---
666
  async def process_podcast(client, chat_id, prompt):
667
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
668
  creds = get_user_credits(str_chat_id)
669
  if creds["podcast"] <= 0:
670
  return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت پادکست شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
754
 
755
  # --- ۴. پردازش تبدیل فایل صوتی/تصویری به متن ---
756
  async def process_stt(client, chat_id, audio_bytes, file_name):
757
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
758
  creds = get_user_credits(str_chat_id)
759
  if creds["stt"] <= 0:
760
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل صدا به متن شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
801
 
802
  # --- ۵. پردازش تحلیل فایل مستقل ---
803
  async def process_file_analysis(client, chat_id, file_bytes, file_name, prompt):
804
+ str_chat_id = str(chat_id).replace("`", "").replace("'", "").replace('"', "").strip()
805
  creds = get_user_credits(str_chat_id)
806
  if creds["file"] <= 0:
807
  return await send_with_keyboard(client, chat_id, "❌ اعتبار تحلیل فایل شما تمام شده است. لطفاً از منوی اصلی وارد بخش «خرید اشتراک 💎» شوید.", False)
 
911
  if user_states[chat_id].get("is_admin"):
912
  if user_text_str.startswith("/upgrade"):
913
  parts = user_text_str.split()
914
+ if len(parts) >= 2:
915
+ # حذف علائم مزاحم از آیدی
916
+ target_id = parts[1].replace("`", "").replace("'", "").replace('"', "").strip()
917
  if target_id not in user_credits_db:
918
+ user_credits_db[target_id] = {
919
+ "is_premium": False,
920
+ "expire_date": None,
921
+ "last_reset": "",
922
+ "chat": 10,
923
+ "image": 5,
924
+ "edit_image": 1,
925
+ "podcast": 2,
926
+ "tts": 5,
927
+ "file": 1,
928
+ "stt": 5
929
+ }
930
 
931
  user_credits_db[target_id]["is_premium"] = True
932
 
 
945
 
946
  save_db(user_credits_db)
947
  await send_with_keyboard(client, chat_id, f"✅ حساب کاربر `{target_id}` به مدت ۳۰ روز شارژ شد و به پرو ارتقا یافت.", False)
948
+
949
+ # ارسال پیام اطلاع‌رسانی به خود کاربر هدف
950
+ try:
951
+ await send_with_keyboard(client, target_id, "🎉 **کاربر گرامی، تبریک!**\n\nحساب شما با موفقیت توسط پشتیبانی به **🌟 نسخه پرو (ویژه)** ارتقا یافت.\nهم‌اکنون بسته‌های یک‌ماهه شما فعال گردید.\n\nجهت مشاهده جزئیات روی دکمه «حساب کاربری 👤» کلیک کنید.", True)
952
+ except Exception as e:
953
+ print(f"Failed to notify target user: {e}")
954
+
955
  else:
956
  await send_with_keyboard(client, chat_id, "⚠️ فرمت صحیح: `/upgrade ID`", False)
957
  return
958
 
959
  if user_text_str.startswith("/downgrade"):
960
  parts = user_text_str.split()
961
+ if len(parts) >= 2:
962
+ target_id = parts[1].replace("`", "").replace("'", "").replace('"', "").strip()
963
  if target_id in user_credits_db:
964
  user_credits_db[target_id]["is_premium"] = False
965
  user_credits_db[target_id]["expire_date"] = None
 
967
  user_credits_db[target_id]["last_reset"] = ""
968
  save_db(user_credits_db)
969
  await send_with_keyboard(client, chat_id, f"✅ اشتراک کاربر `{target_id}` لغو شد و به رایگان تبدیل گشت.", False)
970
+
971
+ # ارسال پیام اطلاع‌رسانی لغو به کاربر هدف
972
+ try:
973
+ await send_with_keyboard(client, target_id, "⚠️ کاربر گرامی، اشتراک ویژه شما به پایان رسید و حساب شما به نسخه رایگان (آزمایشی) تغییر یافت.", True)
974
+ except Exception:
975
+ pass
976
+ else:
977
+ await send_with_keyboard(client, chat_id, "⚠️ فرمت صحیح: `/downgrade ID`", False)
978
  return
979
 
980
  # تشخیص فایل