Update main.py
Browse files
main.py
CHANGED
|
@@ -18,18 +18,12 @@ from huggingface_hub import AsyncInferenceClient, HfApi, hf_hub_download
|
|
| 18 |
from PIL import Image
|
| 19 |
from pydub import AudioSegment
|
| 20 |
|
| 21 |
-
# --- رمز عبور ادمین برای
|
| 22 |
-
|
| 23 |
|
| 24 |
# --- ثبت زمان روشن شدن ربات برای جلوگیری از پرتاب پیامهای قدیمی ---
|
| 25 |
BOT_STARTUP_TIME = time.time()
|
| 26 |
|
| 27 |
-
# --- تنظیمات سهمیه اکانتها ---
|
| 28 |
-
PLAN_LIMITS = {
|
| 29 |
-
"free": {"chat": 10, "image": 5, "edit_image": 1, "podcast": 1, "tts": 5, "file": 1, "stt": 5},
|
| 30 |
-
"premium": {"chat": 100, "image": 50, "edit_image": 10, "podcast": 50, "tts": 100, "file": 20, "stt": 50}
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
# --- سیستم دیتابیس حساب کاربری متصل به دیتاست هاگینگ فیس ---
|
| 34 |
DB_FILE = "users_db.json"
|
| 35 |
DATASET_REPO = "Opera8/Karbaran-rayegan-tedad"
|
|
@@ -95,21 +89,28 @@ def get_user_credits(chat_id):
|
|
| 95 |
today_str = datetime.date.today().isoformat()
|
| 96 |
|
| 97 |
if str_chat_id not in user_credits_db:
|
| 98 |
-
|
|
|
|
| 99 |
|
| 100 |
user_data = user_credits_db[str_chat_id]
|
| 101 |
-
|
| 102 |
|
| 103 |
-
#
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
user_data["last_reset"] = today_str
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
# اعمال محدودیتها بر اساس نوع اکانت
|
| 109 |
-
limits = PLAN_LIMITS.get(current_plan, PLAN_LIMITS["free"])
|
| 110 |
-
for key, val in limits.items():
|
| 111 |
-
user_data[key] = val
|
| 112 |
-
|
| 113 |
save_db(user_credits_db)
|
| 114 |
|
| 115 |
return user_data
|
|
@@ -129,7 +130,7 @@ app = Flask(__name__)
|
|
| 129 |
|
| 130 |
@app.route('/')
|
| 131 |
def home():
|
| 132 |
-
return "ربات یکپارچه آلفا (متصل به دیتاست + اشتراک
|
| 133 |
|
| 134 |
def run_flask():
|
| 135 |
app.run(host="0.0.0.0", port=7860)
|
|
@@ -353,7 +354,7 @@ async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=Non
|
|
| 353 |
str_chat_id = str(chat_id)
|
| 354 |
creds = get_user_credits(str_chat_id)
|
| 355 |
if creds["chat"] <= 0:
|
| 356 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار پیامهای چت شما برای امروز تمام شده است.
|
| 357 |
|
| 358 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلیدهای API جیمینای تنظیم نشدهاند.", False)
|
| 359 |
|
|
@@ -450,7 +451,7 @@ async def process_image(client, chat_id, prompt):
|
|
| 450 |
str_chat_id = str(chat_id)
|
| 451 |
creds = get_user_credits(str_chat_id)
|
| 452 |
if creds["image"] <= 0:
|
| 453 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت عکس روزانه شما تمام شده است.
|
| 454 |
|
| 455 |
if not HF_TOKENS: return await send_with_keyboard(client, chat_id, "❌ توکنهای هاگینگ فیس تنظیم نشدهاند.", False)
|
| 456 |
|
|
@@ -526,7 +527,7 @@ async def process_image_edit(client, chat_id, image_bytes, prompt):
|
|
| 526 |
str_chat_id = str(chat_id)
|
| 527 |
creds = get_user_credits(str_chat_id)
|
| 528 |
if creds["edit_image"] <= 0:
|
| 529 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار ویرایش عکس روزانه شما تمام شده است.
|
| 530 |
|
| 531 |
if not HF_TOKENS:
|
| 532 |
return await send_with_keyboard(client, chat_id, "❌ توکنهای هاگینگ فیس تنظیم نشدهاند.", False)
|
|
@@ -584,7 +585,7 @@ async def process_tts(client, chat_id, user_text, speaker_id, speaker_name):
|
|
| 584 |
str_chat_id = str(chat_id)
|
| 585 |
creds = get_user_credits(str_chat_id)
|
| 586 |
if creds["tts"] <= 0:
|
| 587 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل متن به صدای شما تمام شده است.
|
| 588 |
|
| 589 |
try:
|
| 590 |
proc_msg = await send_with_keyboard(client, chat_id, f"⏳ در حال ساخت صدا با «{speaker_name}»...\n(لطفاً صبور باشید)", False)
|
|
@@ -635,7 +636,7 @@ async def process_podcast(client, chat_id, prompt):
|
|
| 635 |
str_chat_id = str(chat_id)
|
| 636 |
creds = get_user_credits(str_chat_id)
|
| 637 |
if creds["podcast"] <= 0:
|
| 638 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت پادکست روزانه شما تمام شده است.
|
| 639 |
|
| 640 |
proc_msg = await send_with_keyboard(client, chat_id, "📻 در حال بررسی موضوع و نگارش سناریوی پادکست توسط هوش مصنوعی...\n(لطفاً صبور باشید)", False)
|
| 641 |
available_speakers = []
|
|
@@ -725,7 +726,7 @@ async def process_stt(client, chat_id, audio_bytes, file_name):
|
|
| 725 |
str_chat_id = str(chat_id)
|
| 726 |
creds = get_user_credits(str_chat_id)
|
| 727 |
if creds["stt"] <= 0:
|
| 728 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل صدا به متن شما تمام شده است.
|
| 729 |
|
| 730 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلیدهای جیمینای تنظیم نشدهاند.", False)
|
| 731 |
|
|
@@ -772,7 +773,7 @@ async def process_file_analysis(client, chat_id, file_bytes, file_name, prompt):
|
|
| 772 |
str_chat_id = str(chat_id)
|
| 773 |
creds = get_user_credits(str_chat_id)
|
| 774 |
if creds["file"] <= 0:
|
| 775 |
-
return await send_with_keyboard(client, chat_id, "❌ اعتبار تحلیل فایل روزانه شما تمام شده است.
|
| 776 |
|
| 777 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلید جیمینای تنظیم نیست.", False)
|
| 778 |
|
|
@@ -862,54 +863,46 @@ else:
|
|
| 862 |
# تشخیص محتوای متنی
|
| 863 |
user_text = getattr(update, "text", "") or getattr(msg_obj, "text", "")
|
| 864 |
user_text_str = str(user_text).strip() if user_text else ""
|
| 865 |
-
str_chat_id = str(chat_id)
|
| 866 |
-
|
| 867 |
-
# ==========================================
|
| 868 |
-
# 🔐 بخش ادمین و مدیریت اشتراکها 🔐
|
| 869 |
-
# ==========================================
|
| 870 |
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
# ۲. دستور فعالسازی اشتراک توسط ادمین
|
| 884 |
-
if is_admin and user_text_str.startswith("/premium "):
|
| 885 |
-
target_id = user_text_str.replace("/premium ", "").strip()
|
| 886 |
-
if target_id not in user_credits_db:
|
| 887 |
-
user_credits_db[target_id] = {"plan": "free"}
|
| 888 |
-
user_credits_db[target_id]["plan"] = "premium"
|
| 889 |
-
user_credits_db[target_id]["last_reset"] = "" # ریست اجباری سهمیهها برای اعمال آنی
|
| 890 |
-
save_db(user_credits_db)
|
| 891 |
-
await send_with_keyboard(client, chat_id, f"✅ اشتراک پرو برای کاربر {target_id} با موفقیت فعال شد.", True)
|
| 892 |
-
try:
|
| 893 |
-
await client.send_message(target_id, "🎉 **تبریک!**\nاشتراک ویژه (نسخه پرو) شما توسط مدیریت فعال شد. هماکنون میتوانید از تمام امکانات پیشرفته و نامحدود ربات لذت ببرید.")
|
| 894 |
-
except: pass
|
| 895 |
-
return
|
| 896 |
-
|
| 897 |
-
# ۳. دستور لغو اشتراک توسط ادمین
|
| 898 |
-
if is_admin and user_text_str.startswith("/free "):
|
| 899 |
-
target_id = user_text_str.replace("/free ", "").strip()
|
| 900 |
-
if target_id in user_credits_db:
|
| 901 |
-
user_credits_db[target_id]["plan"] = "free"
|
| 902 |
-
user_credits_db[target_id]["last_reset"] = ""
|
| 903 |
-
save_db(user_credits_db)
|
| 904 |
-
await send_with_keyboard(client, chat_id, f"✅ اکانت کاربر {target_id} به حالت رایگان برگشت داده شد.", True)
|
| 905 |
-
try:
|
| 906 |
-
await client.send_message(target_id, "⚠️ **توجه:**\nاشتراک ویژه شما به پایان رسید و حساب شما به نسخه رایگان (محدود) تغییر یافت.")
|
| 907 |
-
except: pass
|
| 908 |
return
|
| 909 |
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
|
| 914 |
# تشخیص فایل
|
| 915 |
is_file = False
|
|
@@ -932,23 +925,36 @@ else:
|
|
| 932 |
file_name = file_attr.get('file_name', file_name) if isinstance(file_attr, dict) else file_name
|
| 933 |
break
|
| 934 |
|
| 935 |
-
if chat_id not in user_states:
|
| 936 |
-
user_states[chat_id] = {"mode": None, "text": "", "history": [], "file_bytes": None, "file_name": None}
|
| 937 |
-
|
| 938 |
if user_text_str in ["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
|
| 939 |
-
user_states[chat_id]
|
|
|
|
| 940 |
await send_with_keyboard(client, chat_id, "سلام! به ربات هوشمند آلفا خوش آمدید 🤖\n\nلطفاً برای شروع، از کیبورد پایین یکی از بخشها را انتخاب کنید:", True)
|
| 941 |
return
|
| 942 |
|
| 943 |
-
# --- حساب کاربری پویا
|
| 944 |
if user_text_str in ["/account", "حساب کاربری 👤"]:
|
| 945 |
creds = get_user_credits(chat_id)
|
| 946 |
-
|
|
|
|
| 947 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 948 |
account_profile = f"""👤 **اطلاعات حساب کاربری شما**
|
| 949 |
|
| 950 |
🔹 **شناسه یکتا:** `{chat_id}`
|
| 951 |
-
🔹 **وضعیت اشتراک:** {
|
| 952 |
|
| 953 |
📊 **سهمیه باقیمانده شما در امروز:**
|
| 954 |
- 💬 چت هوشمند: {creds['chat']} پیام
|
|
@@ -957,56 +963,46 @@ else:
|
|
| 957 |
- 🎙 ساخت پادکست: {creds['podcast']} برنامه
|
| 958 |
- 🗣 تبدیل متن به صدا: {creds['tts']} فایل
|
| 959 |
- 📁 تحلیل فایل: {creds['file']} فایل
|
| 960 |
-
- 📝 تبدیل صدا به متن: {creds['stt']} فایل
|
| 961 |
-
|
| 962 |
-
if creds.get("plan") != "premium":
|
| 963 |
-
account_profile += """
|
| 964 |
-
|
| 965 |
-
💎 **ارتقا به نسخه پرو (نامحدود):**
|
| 966 |
-
با ارتقا به نسخه پرو امکانات شما بینهایت افزایش یافته و محدودیتها برداشته میشود.
|
| 967 |
-
|
| 968 |
-
💰 **هزینه اشتراک ماهانه:** 199 هزار تومان
|
| 969 |
-
💳 **شماره کارت:** `6104338667771394`
|
| 970 |
-
|
| 971 |
-
جهت فعالسازی، لطفاً «رسید واریز» و «شناسه یکتا» خود را به پشتیبانی تلگرام/روبیکا ارسال کنید:
|
| 972 |
-
👨💻 **پشتیبانی:** @H_a_m_e_d100
|
| 973 |
-
*(پس از ارسال رسید، اشتراک شما سریعاً فعال میگردد)*"""
|
| 974 |
-
|
| 975 |
await send_with_keyboard(client, chat_id, account_profile, True)
|
| 976 |
return
|
| 977 |
|
| 978 |
if user_text_str in ["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
|
| 979 |
-
user_states[chat_id]
|
|
|
|
| 980 |
await send_with_keyboard(client, chat_id, "💬 شما وارد بخش **چت با هوش مصنوعی** شدید.\n\nهر سوالی دارید بفرستید تا جواب بدم:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 981 |
return
|
| 982 |
|
| 983 |
if user_text_str in ["/image", "🎨 عکس", "ساخت تصاویر🎨"]:
|
| 984 |
-
user_states[chat_id]
|
| 985 |
await send_with_keyboard(client, chat_id, "🎨 شما وارد بخش **ساخت عکس پیشرفته** شدید.\n\nمتن خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 986 |
return
|
| 987 |
|
| 988 |
if user_text_str in ["/edit_image", "ویرایش تصاویر 🪄"]:
|
| 989 |
-
user_states[chat_id]
|
|
|
|
| 990 |
await send_with_keyboard(client, chat_id, "🪄 به بخش **ویرایش عکس (Flux.2)** ��وش آمدید.\n\nلطفاً ابتدا عکسی که میخواهید ویرایش کنید را بفرستید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 991 |
return
|
| 992 |
|
| 993 |
if user_text_str in ["/tts", "🎙️ صدا", "تبدیل متن به صدا🗣️"]:
|
| 994 |
-
user_states[chat_id]
|
| 995 |
await send_with_keyboard(client, chat_id, "🎙️ شما وارد بخش **تبدیل متن به صدا** شدید.\n\nلطفاً متنی که میخواهید به صدا تبدیل شود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 996 |
return
|
| 997 |
|
| 998 |
if user_text_str in ["/podcast", "📻 پادکست", "ساخت پادکست 🎙️"]:
|
| 999 |
-
user_states[chat_id]
|
| 1000 |
await send_with_keyboard(client, chat_id, "📻 شما وارد بخش **ساخت پادکست** شدید.\n\nلطفاً موضوع پادکست خود را بفرستید.\nمثال: درباره تاریخچه پیدایش قهوه با ۳ گوینده یک پادکست جذاب بساز\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 1001 |
return
|
| 1002 |
|
| 1003 |
if user_text_str in ["/file", "تحلیل فایل 📁"]:
|
| 1004 |
-
user_states[chat_id]
|
|
|
|
| 1005 |
await send_with_keyboard(client, chat_id, "📁 شما وارد بخش **تحلیل فایل اختصاصی** شدید.\n\nلطفاً فایل خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 1006 |
return
|
| 1007 |
|
| 1008 |
if user_text_str in ["/stt", "فایل صوتی به متن 📝"]:
|
| 1009 |
-
user_states[chat_id]
|
| 1010 |
await send_with_keyboard(client, chat_id, "📝 شما وارد بخش **تبدیل صدا به متن** شدید.\n\nلطفاً فایل خود (ویس، آهنگ، ویدیو و...) را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 1011 |
return
|
| 1012 |
|
|
@@ -1124,5 +1120,5 @@ else:
|
|
| 1124 |
if __name__ == "__main__":
|
| 1125 |
threading.Thread(target=run_flask, daemon=True).start()
|
| 1126 |
if bot_token:
|
| 1127 |
-
print("ربات آلفا
|
| 1128 |
bot.run()
|
|
|
|
| 18 |
from PIL import Image
|
| 19 |
from pydub import AudioSegment
|
| 20 |
|
| 21 |
+
# --- رمز عبور ادمین برای ارتقای کاربران (اینجا میتوانید تغییر دهید) ---
|
| 22 |
+
ADMIN_PASSWORD = "alpha2026"
|
| 23 |
|
| 24 |
# --- ثبت زمان روشن شدن ربات برای جلوگیری از پرتاب پیامهای قدیمی ---
|
| 25 |
BOT_STARTUP_TIME = time.time()
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# --- سیستم دیتابیس حساب کاربری متصل به دیتاست هاگینگ فیس ---
|
| 28 |
DB_FILE = "users_db.json"
|
| 29 |
DATASET_REPO = "Opera8/Karbaran-rayegan-tedad"
|
|
|
|
| 89 |
today_str = datetime.date.today().isoformat()
|
| 90 |
|
| 91 |
if str_chat_id not in user_credits_db:
|
| 92 |
+
# کاربر جدید پیشفرض رایگان است
|
| 93 |
+
user_credits_db[str_chat_id] = {"is_premium": False}
|
| 94 |
|
| 95 |
user_data = user_credits_db[str_chat_id]
|
| 96 |
+
is_premium = user_data.get("is_premium", False)
|
| 97 |
|
| 98 |
+
# تعریف سهمیهها بر اساس وضعیت کاربری (رایگان یا ویژه)
|
| 99 |
+
limits = {
|
| 100 |
+
"chat": 100 if is_premium else 10,
|
| 101 |
+
"image": 50 if is_premium else 5,
|
| 102 |
+
"edit_image": 10 if is_premium else 1,
|
| 103 |
+
"podcast": 50 if is_premium else 1,
|
| 104 |
+
"tts": 100 if is_premium else 5,
|
| 105 |
+
"file": 20 if is_premium else 1,
|
| 106 |
+
"stt": 50 if is_premium else 5
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
# بازنشانی خودکار سهمیه روزانه یا هنگام تغییر اشتراک
|
| 110 |
+
if user_data.get("last_reset") != today_str:
|
| 111 |
user_data["last_reset"] = today_str
|
| 112 |
+
for k, v in limits.items():
|
| 113 |
+
user_data[k] = v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
save_db(user_credits_db)
|
| 115 |
|
| 116 |
return user_data
|
|
|
|
| 130 |
|
| 131 |
@app.route('/')
|
| 132 |
def home():
|
| 133 |
+
return "ربات یکپارچه آلفا (متصل به دیتاست + سیستم اشتراکی VIP + پادکست + ویرایش عکس) روشن است! 🚀"
|
| 134 |
|
| 135 |
def run_flask():
|
| 136 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 354 |
str_chat_id = str(chat_id)
|
| 355 |
creds = get_user_credits(str_chat_id)
|
| 356 |
if creds["chat"] <= 0:
|
| 357 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار پیامهای چت شما برای امروز تمام شده است.", False)
|
| 358 |
|
| 359 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلیدهای API جیمینای تنظیم نشدهاند.", False)
|
| 360 |
|
|
|
|
| 451 |
str_chat_id = str(chat_id)
|
| 452 |
creds = get_user_credits(str_chat_id)
|
| 453 |
if creds["image"] <= 0:
|
| 454 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت عکس روزانه شما تمام شده است.", False)
|
| 455 |
|
| 456 |
if not HF_TOKENS: return await send_with_keyboard(client, chat_id, "❌ توکنهای هاگینگ فیس تنظیم نشدهاند.", False)
|
| 457 |
|
|
|
|
| 527 |
str_chat_id = str(chat_id)
|
| 528 |
creds = get_user_credits(str_chat_id)
|
| 529 |
if creds["edit_image"] <= 0:
|
| 530 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار ویرایش عکس روزانه شما تمام شده است.", False)
|
| 531 |
|
| 532 |
if not HF_TOKENS:
|
| 533 |
return await send_with_keyboard(client, chat_id, "❌ توکنهای هاگینگ فیس تنظیم نشدهاند.", False)
|
|
|
|
| 585 |
str_chat_id = str(chat_id)
|
| 586 |
creds = get_user_credits(str_chat_id)
|
| 587 |
if creds["tts"] <= 0:
|
| 588 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل متن به صدای شما تمام شده است.", False)
|
| 589 |
|
| 590 |
try:
|
| 591 |
proc_msg = await send_with_keyboard(client, chat_id, f"⏳ در حال ساخت صدا با «{speaker_name}»...\n(لطفاً صبور باشید)", False)
|
|
|
|
| 636 |
str_chat_id = str(chat_id)
|
| 637 |
creds = get_user_credits(str_chat_id)
|
| 638 |
if creds["podcast"] <= 0:
|
| 639 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار ساخت پادکست روزانه شما تمام شده است.", False)
|
| 640 |
|
| 641 |
proc_msg = await send_with_keyboard(client, chat_id, "📻 در حال بررسی موضوع و نگارش سناریوی پادکست توسط هوش مصنوعی...\n(لطفاً صبور باشید)", False)
|
| 642 |
available_speakers = []
|
|
|
|
| 726 |
str_chat_id = str(chat_id)
|
| 727 |
creds = get_user_credits(str_chat_id)
|
| 728 |
if creds["stt"] <= 0:
|
| 729 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار تبدیل صدا به متن شما تمام شده است.", False)
|
| 730 |
|
| 731 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلیدهای جیمینای تنظیم نشدهاند.", False)
|
| 732 |
|
|
|
|
| 773 |
str_chat_id = str(chat_id)
|
| 774 |
creds = get_user_credits(str_chat_id)
|
| 775 |
if creds["file"] <= 0:
|
| 776 |
+
return await send_with_keyboard(client, chat_id, "❌ اعتبار تحلیل فایل روزانه شما تمام شده است.", False)
|
| 777 |
|
| 778 |
if not GEMINI_KEYS: return await send_with_keyboard(client, chat_id, "❌ کلید جیمینای تنظیم نیست.", False)
|
| 779 |
|
|
|
|
| 863 |
# تشخیص محتوای متنی
|
| 864 |
user_text = getattr(update, "text", "") or getattr(msg_obj, "text", "")
|
| 865 |
user_text_str = str(user_text).strip() if user_text else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 866 |
|
| 867 |
+
if chat_id not in user_states:
|
| 868 |
+
user_states[chat_id] = {"mode": None, "text": "", "history": [], "file_bytes": None, "file_name": None, "is_admin": False}
|
| 869 |
+
|
| 870 |
+
# 🛠 --- بخش مدیریت ادمین --- 🛠
|
| 871 |
+
if user_text_str.startswith("/admin_login"):
|
| 872 |
+
parts = user_text_str.split()
|
| 873 |
+
if len(parts) == 2 and parts[1] == ADMIN_PASSWORD:
|
| 874 |
+
user_states[chat_id]["is_admin"] = True
|
| 875 |
+
await send_with_keyboard(client, chat_id, "✅ با موفقیت به عنوان ادمین وارد شدید.\n\nبرای ارتقای یک کاربر به نسخه پرو:\n`/upgrade <شناسه_کاربر>`\n\nبرای لغو اشتراک یک کاربر:\n`/downgrade <شناسه_کاربر>`", False)
|
| 876 |
+
else:
|
| 877 |
+
await send_with_keyboard(client, chat_id, "❌ رمز عبور اشتباه است.", False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
return
|
| 879 |
|
| 880 |
+
if user_states[chat_id].get("is_admin"):
|
| 881 |
+
if user_text_str.startswith("/upgrade"):
|
| 882 |
+
parts = user_text_str.split()
|
| 883 |
+
if len(parts) == 2:
|
| 884 |
+
target_id = parts[1]
|
| 885 |
+
if target_id not in user_credits_db:
|
| 886 |
+
user_credits_db[target_id] = {"is_premium": False}
|
| 887 |
+
|
| 888 |
+
user_credits_db[target_id]["is_premium"] = True
|
| 889 |
+
user_credits_db[target_id]["last_reset"] = "" # برای اینکه در درخواست بعدی محدودیتها ۱۰۰ برابری شوند
|
| 890 |
+
save_db(user_credits_db)
|
| 891 |
+
await send_with_keyboard(client, chat_id, f"✅ اشتراک ویژه برای کاربر `{target_id}` فعال شد.", False)
|
| 892 |
+
else:
|
| 893 |
+
await send_with_keyboard(client, chat_id, "⚠️ فرمت صحیح: `/upgrade ID`", False)
|
| 894 |
+
return
|
| 895 |
+
|
| 896 |
+
if user_text_str.startswith("/downgrade"):
|
| 897 |
+
parts = user_text_str.split()
|
| 898 |
+
if len(parts) == 2:
|
| 899 |
+
target_id = parts[1]
|
| 900 |
+
if target_id in user_credits_db:
|
| 901 |
+
user_credits_db[target_id]["is_premium"] = False
|
| 902 |
+
user_credits_db[target_id]["last_reset"] = ""
|
| 903 |
+
save_db(user_credits_db)
|
| 904 |
+
await send_with_keyboard(client, chat_id, f"✅ اشتراک کاربر `{target_id}` لغو و به رایگان تبدیل شد.", False)
|
| 905 |
+
return
|
| 906 |
|
| 907 |
# تشخیص فایل
|
| 908 |
is_file = False
|
|
|
|
| 925 |
file_name = file_attr.get('file_name', file_name) if isinstance(file_attr, dict) else file_name
|
| 926 |
break
|
| 927 |
|
|
|
|
|
|
|
|
|
|
| 928 |
if user_text_str in ["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
|
| 929 |
+
user_states[chat_id]["mode"] = None
|
| 930 |
+
user_states[chat_id]["file_bytes"] = None
|
| 931 |
await send_with_keyboard(client, chat_id, "سلام! به ربات هوشمند آلفا خوش آمدید 🤖\n\nلطفاً برای شروع، از کیبورد پایین یکی از بخشها را انتخاب کنید:", True)
|
| 932 |
return
|
| 933 |
|
| 934 |
+
# --- حساب کاربری پویا (با تفکیک رایگان/ویژه) ---
|
| 935 |
if user_text_str in ["/account", "حساب کاربری 👤"]:
|
| 936 |
creds = get_user_credits(chat_id)
|
| 937 |
+
is_prem = creds.get("is_premium", False)
|
| 938 |
+
status_text = "🌟 نسخه پرو (اشتراک ویژه)" if is_prem else "🥉 نسخه رایگان (آزمایشی)"
|
| 939 |
|
| 940 |
+
upgrade_text = ""
|
| 941 |
+
if not is_prem:
|
| 942 |
+
upgrade_text = """
|
| 943 |
+
🎁 **ارتقا به نسخه پرو (ویژه):**
|
| 944 |
+
با تهیه اشتراک ویژه، محدودیتهای شما به شکل زیر افزایش مییابد:
|
| 945 |
+
- ۱۰۰ پیام چت، ۲۰ تحلیل فایل، ۵۰ پادکست، ۱۰۰ تبدیل متن به صدا، ۱۰ ویرایش تصویر در روز!
|
| 946 |
+
|
| 947 |
+
💳 **هزینه اشتراک ماهانه:** ۱۹۹,۰۰۰ تومان
|
| 948 |
+
شماره کارت: `6104338667771394`
|
| 949 |
+
|
| 950 |
+
پس از واریز، رسید خود را به همراه **شناسه یکتا** (که در بالا نوشته شده) به پشتیبانی زیر ارسال کنید تا اشتراکتان فعال شود:
|
| 951 |
+
🆔 پشتیبانی: @H_a_m_e_d100
|
| 952 |
+
"""
|
| 953 |
+
|
| 954 |
account_profile = f"""👤 **اطلاعات حساب کاربری شما**
|
| 955 |
|
| 956 |
🔹 **شناسه یکتا:** `{chat_id}`
|
| 957 |
+
🔹 **وضعیت اشتراک:** {status_text}
|
| 958 |
|
| 959 |
📊 **سهمیه باقیمانده شما در امروز:**
|
| 960 |
- 💬 چت هوشمند: {creds['chat']} پیام
|
|
|
|
| 963 |
- 🎙 ساخت پادکست: {creds['podcast']} برنامه
|
| 964 |
- 🗣 تبدیل متن به صدا: {creds['tts']} فایل
|
| 965 |
- 📁 تحلیل فایل: {creds['file']} فایل
|
| 966 |
+
- 📝 تبدیل صدا به متن: {creds['stt']} فایل
|
| 967 |
+
{upgrade_text}"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 968 |
await send_with_keyboard(client, chat_id, account_profile, True)
|
| 969 |
return
|
| 970 |
|
| 971 |
if user_text_str in ["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
|
| 972 |
+
user_states[chat_id]["mode"] = "chat"
|
| 973 |
+
user_states[chat_id]["history"] = []
|
| 974 |
await send_with_keyboard(client, chat_id, "💬 شما وارد بخش **چت با هوش مصنوعی** شدید.\n\nهر سوالی دارید بفرستید تا جواب بدم:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 975 |
return
|
| 976 |
|
| 977 |
if user_text_str in ["/image", "🎨 عکس", "ساخت تصاویر🎨"]:
|
| 978 |
+
user_states[chat_id]["mode"] = "image_waiting_for_text"
|
| 979 |
await send_with_keyboard(client, chat_id, "🎨 شما وارد بخش **ساخت عکس پیشرفته** شدید.\n\nمتن خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 980 |
return
|
| 981 |
|
| 982 |
if user_text_str in ["/edit_image", "ویرایش تصاویر 🪄"]:
|
| 983 |
+
user_states[chat_id]["mode"] = "image_edit_waiting_for_image"
|
| 984 |
+
user_states[chat_id]["file_bytes"] = None
|
| 985 |
await send_with_keyboard(client, chat_id, "🪄 به بخش **ویرایش عکس (Flux.2)** ��وش آمدید.\n\nلطفاً ابتدا عکسی که میخواهید ویرایش کنید را بفرستید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 986 |
return
|
| 987 |
|
| 988 |
if user_text_str in ["/tts", "🎙️ صدا", "تبدیل متن به صدا🗣️"]:
|
| 989 |
+
user_states[chat_id]["mode"] = "tts_waiting_for_text"
|
| 990 |
await send_with_keyboard(client, chat_id, "🎙️ شما وارد بخش **تبدیل متن به صدا** شدید.\n\nلطفاً متنی که میخواهید به صدا تبدیل شود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 991 |
return
|
| 992 |
|
| 993 |
if user_text_str in ["/podcast", "📻 پادکست", "ساخت پادکست 🎙️"]:
|
| 994 |
+
user_states[chat_id]["mode"] = "podcast_waiting_for_topic"
|
| 995 |
await send_with_keyboard(client, chat_id, "📻 شما وارد بخش **ساخت پادکست** شدید.\n\nلطفاً موضوع پادکست خود را بفرستید.\nمثال: درباره تاریخچه پیدایش قهوه با ۳ گوینده یک پادکست جذاب بساز\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 996 |
return
|
| 997 |
|
| 998 |
if user_text_str in ["/file", "تحلیل فایل 📁"]:
|
| 999 |
+
user_states[chat_id]["mode"] = "file_waiting_for_file"
|
| 1000 |
+
user_states[chat_id]["file_bytes"] = None
|
| 1001 |
await send_with_keyboard(client, chat_id, "📁 شما وارد بخش **تحلیل فایل اختصاصی** شدید.\n\nلطفاً فایل خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 1002 |
return
|
| 1003 |
|
| 1004 |
if user_text_str in ["/stt", "فایل صوتی به متن 📝"]:
|
| 1005 |
+
user_states[chat_id]["mode"] = "stt_waiting_for_audio"
|
| 1006 |
await send_with_keyboard(client, chat_id, "📝 شما وارد بخش **تبدیل صدا به متن** شدید.\n\nلطفاً فایل خود (ویس، آهنگ، ویدیو و...) را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True)
|
| 1007 |
return
|
| 1008 |
|
|
|
|
| 1120 |
if __name__ == "__main__":
|
| 1121 |
threading.Thread(target=run_flask, daemon=True).start()
|
| 1122 |
if bot_token:
|
| 1123 |
+
print("ربات آلفا پرو با سیستم اشتراک VIP روشن شد...")
|
| 1124 |
bot.run()
|