Update main.py
Browse files
main.py
CHANGED
|
@@ -31,8 +31,6 @@ asyncio_helper.FILE_URL = "https://tapi.bale.ai/file/bot{0}/{1}"
|
|
| 31 |
|
| 32 |
# --- کد مدیریت برای ارتقای کاربران بدون نیاز به لاگین ---
|
| 33 |
ADMIN_CODE = "3011"
|
| 34 |
-
|
| 35 |
-
# متغیر سراسری برای ذخیره آیدی خود ربات (جلوگیری از جواب دادن ربات به خودش)
|
| 36 |
BOT_GUID = None
|
| 37 |
|
| 38 |
# --- سیستم دیتابیس حساب کاربری متصل به دیتاست هاگینگ فیس ---
|
|
@@ -287,9 +285,7 @@ async def helper_upload_file(client, chat_id, file_name, file_type="Image", capt
|
|
| 287 |
return f"Bale Send Error: {str(e)[:100]}"
|
| 288 |
|
| 289 |
|
| 290 |
-
WORKER_URLS =[
|
| 291 |
-
"https://opera8-ttspro.hf.space/generate",
|
| 292 |
-
]
|
| 293 |
|
| 294 |
SPEAKERS = {
|
| 295 |
"1": ("شهاب (مرد)", "Charon"), "2": ("آوا (زن)", "Zephyr"), "3": ("نوید (مرد)", "Achird"),
|
|
@@ -305,7 +301,7 @@ SPEAKERS = {
|
|
| 305 |
}
|
| 306 |
|
| 307 |
user_states = {}
|
| 308 |
-
|
| 309 |
|
| 310 |
# --- ۱. پردازش چت متنی و چندرسانهای ---
|
| 311 |
async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=None):
|
|
@@ -327,14 +323,7 @@ async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=Non
|
|
| 327 |
base64_data = base64.b64encode(file_bytes).decode('utf-8')
|
| 328 |
mime_type, _ = mimetypes.guess_type(file_name)
|
| 329 |
if not mime_type:
|
| 330 |
-
|
| 331 |
-
elif file_name.endswith('.png'): mime_type = "image/png"
|
| 332 |
-
elif file_name.endswith('.pdf'): mime_type = "application/pdf"
|
| 333 |
-
elif file_name.endswith('.mp4'): mime_type = "video/mp4"
|
| 334 |
-
elif file_name.endswith('.mp3'): mime_type = "audio/mp3"
|
| 335 |
-
elif file_name.endswith(('.ogg', '.oga')): mime_type = "audio/ogg"
|
| 336 |
-
elif file_name.endswith('.wav'): mime_type = "audio/wav"
|
| 337 |
-
else: mime_type = "image/jpeg"
|
| 338 |
new_parts.append({"inlineData": {"mimeType": mime_type, "data": base64_data}})
|
| 339 |
|
| 340 |
if history and history[-1]["role"] == "user": history[-1]["parts"].extend(new_parts)
|
|
@@ -361,7 +350,6 @@ async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=Non
|
|
| 361 |
except (KeyError, IndexError): continue
|
| 362 |
except Exception: continue
|
| 363 |
|
| 364 |
-
# --- Fallback to Hugging Face Gemma 4 ---
|
| 365 |
if not final_answer and HF_TOKENS:
|
| 366 |
hf_messages =[]
|
| 367 |
for msg in history:
|
|
@@ -386,11 +374,7 @@ async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=Non
|
|
| 386 |
for hf_key in keys_to_try_hf:
|
| 387 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 388 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 389 |
-
payload = {
|
| 390 |
-
"model": "google/gemma-4-31B-it:novita",
|
| 391 |
-
"messages": hf_messages,
|
| 392 |
-
"max_tokens": 4096
|
| 393 |
-
}
|
| 394 |
try:
|
| 395 |
async with session.post(url, headers=headers, json=payload, timeout=60) as response:
|
| 396 |
if response.status == 200:
|
|
@@ -475,11 +459,7 @@ async def process_image(client, chat_id, prompt):
|
|
| 475 |
for hf_key in keys_to_try_hf:
|
| 476 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 477 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 478 |
-
payload = {
|
| 479 |
-
"model": "google/gemma-4-31B-it:novita",
|
| 480 |
-
"messages":[{"role": "user", "content":[{"type": "text", "text": gemini_sys_prompt}]}],
|
| 481 |
-
"max_tokens": 1024
|
| 482 |
-
}
|
| 483 |
try:
|
| 484 |
async with session.post(url, headers=headers, json=payload, timeout=20) as response:
|
| 485 |
if response.status == 200:
|
|
@@ -899,11 +879,7 @@ async def process_create_file(client, chat_id, topic):
|
|
| 899 |
for hf_key in keys_to_try_hf:
|
| 900 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 901 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 902 |
-
payload = {
|
| 903 |
-
"model": "google/gemma-4-31B-it:novita",
|
| 904 |
-
"messages":[{"role": "user", "content":[{"type": "text", "text": ai_prompt}]}],
|
| 905 |
-
"max_tokens": 4096
|
| 906 |
-
}
|
| 907 |
try:
|
| 908 |
async with session.post(url, headers=headers, json=payload, timeout=60) as response:
|
| 909 |
if response.status == 200:
|
|
@@ -985,6 +961,39 @@ async def process_create_file(client, chat_id, topic):
|
|
| 985 |
else:
|
| 986 |
await send_with_keyboard(client, chat_id, "❌ فایلها ساخته شدند اما بله در ارسال آنها دچار مشکل شد.", True)
|
| 987 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 988 |
|
| 989 |
# --- راهاندازی و اتصال هندلرها به بله ---
|
| 990 |
bot = AsyncTeleBot(bot_token) if bot_token else None
|
|
@@ -993,19 +1002,27 @@ if bot:
|
|
| 993 |
@bot.message_handler(func=lambda message: True, content_types=['text', 'photo', 'document', 'voice', 'audio', 'video'])
|
| 994 |
async def main_handler(message):
|
| 995 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
global BOT_GUID
|
| 997 |
if not BOT_GUID:
|
| 998 |
try:
|
| 999 |
me_info = await bot.get_me()
|
| 1000 |
if me_info: BOT_GUID = me_info.id
|
| 1001 |
-
except Exception:
|
| 1002 |
-
pass
|
| 1003 |
|
| 1004 |
author_id = message.from_user.id
|
| 1005 |
if BOT_GUID and author_id == BOT_GUID:
|
| 1006 |
return
|
| 1007 |
-
|
| 1008 |
-
chat_id = message.chat.id
|
| 1009 |
|
| 1010 |
user_text = message.text or message.caption or ""
|
| 1011 |
user_text_str = str(user_text).strip() if user_text else ""
|
|
@@ -1033,10 +1050,7 @@ if bot:
|
|
| 1033 |
user_credits_db[target_id]["file"] = 999999
|
| 1034 |
user_credits_db[target_id]["stt"] = 999999
|
| 1035 |
save_db(user_credits_db)
|
| 1036 |
-
|
| 1037 |
-
try:
|
| 1038 |
-
await send_with_keyboard(bot, target_id, "🎉 **کاربر گرامی، تبریک!**\n\nحساب شما با موفقیت توسط پشتیبانی به **🌟 نسخه پرو (ویژه)** ارتقا یافت.\nهماکنون بستههای نامحدود و طلایی یکماهه شما فعال گردید.\n\nجهت مشاهده جزئیات روی دکمه «حساب کاربری 👤» کلیک کنید.", True)
|
| 1039 |
-
except Exception: pass
|
| 1040 |
return
|
| 1041 |
|
| 1042 |
if user_text_lower.startswith(f"{ADMIN_CODE} free=") or user_text_lower.startswith(f"{ADMIN_CODE}free="):
|
|
@@ -1049,10 +1063,7 @@ if bot:
|
|
| 1049 |
user_credits_db[target_id]["expire_date"] = None
|
| 1050 |
user_credits_db[target_id]["last_reset"] = ""
|
| 1051 |
save_db(user_credits_db)
|
| 1052 |
-
|
| 1053 |
-
try:
|
| 1054 |
-
await send_with_keyboard(bot, target_id, "⚠️ کاربر گرامی، اشتراک ویژه شما به پایان رسید و حساب شما به نسخه رایگان (آزمایشی) تغییر یافت.", True)
|
| 1055 |
-
except Exception: pass
|
| 1056 |
return
|
| 1057 |
|
| 1058 |
if user_text_lower.startswith(f"{ADMIN_CODE} =") or user_text_lower.startswith(f"{ADMIN_CODE}="):
|
|
@@ -1078,9 +1089,9 @@ if bot:
|
|
| 1078 |
status_text = "🥉 نسخه رایگان (آزمایشی)\n⏳ سهمیه روزانه"
|
| 1079 |
|
| 1080 |
info_msg = f"🔍 **اطلاعات کاربر `{target_id}`:**\n\n🔹 **وضعیت:** {status_text}\n\n📊 **سهمیه:**\n- چت: {t_creds.get('chat',0)}\n- تولید عکس: {t_creds.get('image',0)}\n- ویرایش عکس: {t_creds.get('edit_image',0)}\n- پادکست: {t_creds.get('podcast',0)}\n- متن به صدا: {t_creds.get('tts',0)}\n- تحلیل فایل: {t_creds.get('file',0)}\n- صدا به متن: {t_creds.get('stt',0)}"
|
| 1081 |
-
|
| 1082 |
else:
|
| 1083 |
-
|
| 1084 |
return
|
| 1085 |
|
| 1086 |
is_file = False
|
|
@@ -1109,24 +1120,23 @@ if bot:
|
|
| 1109 |
if not creds.get("has_joined", False):
|
| 1110 |
user_credits_db[str_chat_id]["has_joined"] = True
|
| 1111 |
save_db(user_credits_db)
|
| 1112 |
-
|
| 1113 |
return
|
| 1114 |
else:
|
| 1115 |
-
|
| 1116 |
return
|
| 1117 |
|
| 1118 |
if not creds.get("has_joined", False):
|
| 1119 |
join_msg = "👋 **سلام کاربر گرامی!**\n\nجهت استفاده از خدمات ربات هوش مصنوعی آلفا و مطلع شدن از آخرین آپدیتها، لطفا ابتدا در کانال رسمی ما عضو شوید:\n\n📢 **آیدی کانال:** @aialpha\n\n👇 پس از عضویت در کانال، بر روی دکمه **«✅ عضو شدم»** کلیک کنید تا ربات برای شما فعال شود."
|
| 1120 |
-
|
| 1121 |
return
|
| 1122 |
|
| 1123 |
if user_text_str in["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
|
| 1124 |
user_states[chat_id]["mode"] = None
|
| 1125 |
user_states[chat_id]["file_bytes"] = None
|
| 1126 |
-
|
| 1127 |
return
|
| 1128 |
|
| 1129 |
-
# --- حساب کاربری ---
|
| 1130 |
if user_text_str in["/account", "حساب کاربری 👤"]:
|
| 1131 |
creds = get_user_credits(chat_id)
|
| 1132 |
is_prem = creds.get("is_premium", False)
|
|
@@ -1156,142 +1166,84 @@ if bot:
|
|
| 1156 |
image_rem = creds['image']
|
| 1157 |
edit_image_rem = creds['edit_image']
|
| 1158 |
|
| 1159 |
-
account_profile = f"
|
| 1160 |
-
|
| 1161 |
-
🔹 **شناسه یکتا:** `{chat_id}`
|
| 1162 |
-
🔹 **وضعیت اشتراک:** {status_text}{expire_info}
|
| 1163 |
-
|
| 1164 |
-
📊 **سهمیه باقیمانده شما:**
|
| 1165 |
-
- 💬 چت هوشمند: {chat_rem}
|
| 1166 |
-
- 🎨 تولید تصویر: {image_rem} عدد
|
| 1167 |
-
- 🪄 ویرایش تصویر: {edit_image_rem} عدد
|
| 1168 |
-
- 🎙 ساخت پادکست: {podcast_rem}
|
| 1169 |
-
- 🗣 تبدیل متن به صدا: {tts_rem}
|
| 1170 |
-
- 📁 تحلیل فایل و سند: {file_rem}
|
| 1171 |
-
- 📝 تبدیل صدا به متن: {stt_rem}
|
| 1172 |
-
|
| 1173 |
-
{daily_note}"""
|
| 1174 |
-
await send_with_keyboard(bot, chat_id, account_profile, True)
|
| 1175 |
return
|
| 1176 |
|
| 1177 |
if user_text_str in["/buy", "خرید اشتراک 💎"]:
|
| 1178 |
-
buy_text = f"
|
| 1179 |
-
|
| 1180 |
-
با تهیه اشتراک ویژه، محدودیتها را کنار بزنید و از نهایت قدرت هوش مصنوعی لذت ببرید! 🚀
|
| 1181 |
-
|
| 1182 |
-
🎁 **بسته طلایی یکماهه شامل:**
|
| 1183 |
-
🤖 چت با هوش مصنوعی بصورت نامحدود
|
| 1184 |
-
🗣 تبدیل متن به صدا بصورت نامحدود با ۳۰ گوینده
|
| 1185 |
-
🎙 ساخت پادکست بصورت نامحدود
|
| 1186 |
-
|
| 1187 |
-
🪄 ۱۰ ویرایش تصویر
|
| 1188 |
-
🎨 ۲۰ تولید تصویر
|
| 1189 |
-
📁 تحلیل نامحدود فایل و سند
|
| 1190 |
-
📝 تبدیل فایل صوتی به متن نامحدود
|
| 1191 |
-
|
| 1192 |
-
💳 **هزینه اشتراک یک ماهه:** 250 هزار تومان
|
| 1193 |
-
|
| 1194 |
-
💳 **شماره کارت جهت واریز:**
|
| 1195 |
-
`6219861411958035`
|
| 1196 |
-
👤 **به نام:** کوهی
|
| 1197 |
-
|
| 1198 |
-
✅ **نحوه فعالسازی:**
|
| 1199 |
-
پس از واریز مبلغ، لطفاً رسید پرداختی را به همراه **شناسه یکتای خود** (که در پایین آمده) به آیدی پشتیبانی زیر ارسال کنید تا اشتراک شما فعال گردد:
|
| 1200 |
-
|
| 1201 |
-
🔑 **شناسه یکتای شما:** `{chat_id}`
|
| 1202 |
-
|
| 1203 |
-
👨💻 **ارتباط با پشتیبانی:**
|
| 1204 |
-
🆔 @H_a_m_e_d100"""
|
| 1205 |
-
await send_with_keyboard(bot, chat_id, buy_text, True)
|
| 1206 |
return
|
| 1207 |
|
| 1208 |
if user_text_str in["/transfer", "انتقال اکانت از برنامه به ربات"]:
|
| 1209 |
-
transfer_text = f"
|
| 1210 |
-
|
| 1211 |
-
کاربر گرامی، در صورتی که داخل برنامه «هوش مصنوعی آلفا» پیشتر اشتراک تهیه کردهاید، نیازی به خرید مجدد اشتراک داخل ربات نیست! 🎉
|
| 1212 |
-
|
| 1213 |
-
کافیست **شناسه یکتای** ربات خود را کپی کرده و برای پشتیبانی ما ارسال کنید تا اکانت اشتراکی شما به سرعت انتقال داده شود.
|
| 1214 |
-
|
| 1215 |
-
🔑 **شناسه یکتای ربات شما:** `{chat_id}`
|
| 1216 |
-
|
| 1217 |
-
👨💻 **پشتیبانی:**
|
| 1218 |
-
🆔 @H_a_m_e_d100"""
|
| 1219 |
-
await send_with_keyboard(bot, chat_id, transfer_text, True)
|
| 1220 |
return
|
| 1221 |
|
| 1222 |
if user_text_str in["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
|
| 1223 |
user_states[chat_id]["mode"] = "chat"
|
| 1224 |
user_states[chat_id]["history"] =[]
|
| 1225 |
-
|
| 1226 |
return
|
| 1227 |
|
| 1228 |
if user_text_str in ["/image", "🎨 عکس", "ساخت تصاویر🎨"]:
|
| 1229 |
user_states[chat_id]["mode"] = "image_waiting_for_text"
|
| 1230 |
-
|
| 1231 |
return
|
| 1232 |
|
| 1233 |
if user_text_str in["/edit_image", "ویرایش تصاویر 🪄"]:
|
| 1234 |
user_states[chat_id]["mode"] = "image_edit_waiting_for_image"
|
| 1235 |
user_states[chat_id]["file_bytes"] = None
|
| 1236 |
-
|
| 1237 |
return
|
| 1238 |
|
| 1239 |
if user_text_str in["/tts", "🎙️ صدا", "تبدیل متن به صدا🗣️"]:
|
| 1240 |
user_states[chat_id]["mode"] = "tts_waiting_for_text"
|
| 1241 |
-
|
| 1242 |
return
|
| 1243 |
|
| 1244 |
if user_text_str in["/podcast", "📻 پادکست", "ساخت پادکست 🎙️"]:
|
| 1245 |
user_states[chat_id]["mode"] = "podcast_waiting_for_topic"
|
| 1246 |
-
|
| 1247 |
return
|
| 1248 |
|
| 1249 |
-
if user_text_str in
|
| 1250 |
user_states[chat_id]["mode"] = "file_waiting_for_file"
|
| 1251 |
user_states[chat_id]["file_bytes"] = None
|
| 1252 |
-
|
| 1253 |
return
|
| 1254 |
|
| 1255 |
if user_text_str in["/stt", "فایل صوتی به متن 📝"]:
|
| 1256 |
user_states[chat_id]["mode"] = "stt_waiting_for_audio"
|
| 1257 |
-
|
| 1258 |
return
|
| 1259 |
|
| 1260 |
if user_text_str in["/create_file", "ساخت فایل 📄"]:
|
| 1261 |
user_states[chat_id]["mode"] = "create_file_waiting_for_topic"
|
| 1262 |
-
|
| 1263 |
return
|
| 1264 |
|
| 1265 |
current_mode = user_states[chat_id].get("mode")
|
| 1266 |
|
| 1267 |
if current_mode is None:
|
| 1268 |
if is_file: pass
|
| 1269 |
-
elif user_text_str:
|
| 1270 |
return
|
| 1271 |
|
| 1272 |
elif current_mode == "chat":
|
| 1273 |
-
if is_file:
|
| 1274 |
-
|
| 1275 |
-
try:
|
| 1276 |
-
file_bytes = await helper_download_file(bot, message)
|
| 1277 |
-
await process_gemini(bot, chat_id, user_text_str, file_bytes=file_bytes, file_name=file_name)
|
| 1278 |
-
except Exception as dl_err: await send_with_keyboard(bot, chat_id, f"❌ خطا در دریافت فایل!\n{str(dl_err)}", False)
|
| 1279 |
-
elif user_text_str: await process_gemini(bot, chat_id, user_text_str)
|
| 1280 |
return
|
| 1281 |
|
| 1282 |
elif current_mode == "image_waiting_for_text":
|
| 1283 |
-
if user_text_str:
|
| 1284 |
return
|
| 1285 |
|
| 1286 |
elif current_mode == "image_edit_waiting_for_image":
|
| 1287 |
-
if not is_file:
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
user_states[chat_id]["file_bytes"] = file_bytes
|
| 1292 |
-
user_states[chat_id]["mode"] = "image_edit_waiting_for_prompt"
|
| 1293 |
-
await send_with_keyboard(bot, chat_id, "✅ عکس با موفقیت دریافت شد.\n\nحالا دستور خود را به صورت متنی تایپ کنید.\nمثال: یک کلاه قرمز روی سر این گربه بگذار.", False)
|
| 1294 |
-
except Exception as dl_err: await send_with_keyboard(bot, chat_id, f"❌ خطا در دریافت عکس!\n{str(dl_err)}", False)
|
| 1295 |
return
|
| 1296 |
|
| 1297 |
elif current_mode == "image_edit_waiting_for_prompt":
|
|
@@ -1299,67 +1251,49 @@ if bot:
|
|
| 1299 |
saved_bytes = user_states[chat_id].get("file_bytes")
|
| 1300 |
user_states[chat_id]["mode"] = None
|
| 1301 |
user_states[chat_id]["file_bytes"] = None
|
| 1302 |
-
|
| 1303 |
-
else:
|
| 1304 |
return
|
| 1305 |
|
| 1306 |
elif current_mode == "tts_waiting_for_text":
|
| 1307 |
if user_text_str:
|
| 1308 |
-
if len(user_text_str) > 2500:
|
|
|
|
|
|
|
| 1309 |
user_states[chat_id]["text"] = user_text_str
|
| 1310 |
user_states[chat_id]["mode"] = "tts_waiting_for_speaker"
|
| 1311 |
-
|
| 1312 |
-
|
| 1313 |
-
لطفاً **شماره** گوینده مورد نظر خود را بفرستید:
|
| 1314 |
-
1. شهاب | 2. آوا | 3. نوید
|
| 1315 |
-
4. آرمان | 5. مهسا | 6. دانا
|
| 1316 |
-
7. سامان | 8. آرش | 9. شبنم
|
| 1317 |
-
10. سحر | 11. مریم | 12. بهرام
|
| 1318 |
-
13. نیکان| 14. فرناز | 15. سارا
|
| 1319 |
-
16. مانی | 17. آرتین | 18. دلنواز
|
| 1320 |
-
19. روژان | 20. امید | 21. بردیا
|
| 1321 |
-
22. ترانه | 23. نیکو | 24. هستی
|
| 1322 |
-
25. کامیار| 26. کیانوش| 27. پویا
|
| 1323 |
-
28. مهتاب | 29. سام | 30. لیدا"""
|
| 1324 |
-
await send_with_keyboard(bot, chat_id, speakers_menu, False)
|
| 1325 |
return
|
| 1326 |
|
| 1327 |
elif current_mode == "tts_waiting_for_speaker":
|
| 1328 |
normalized_text = to_english_digits(user_text_str)
|
| 1329 |
-
|
| 1330 |
if normalized_text.isdigit() and normalized_text in SPEAKERS:
|
| 1331 |
spk_name, spk_id = SPEAKERS[normalized_text]
|
| 1332 |
txt = user_states[chat_id]["text"]
|
| 1333 |
user_states[chat_id]["mode"] = "tts_waiting_for_text"
|
| 1334 |
-
|
| 1335 |
else:
|
| 1336 |
-
|
| 1337 |
return
|
| 1338 |
|
| 1339 |
elif current_mode == "podcast_waiting_for_topic":
|
| 1340 |
-
if user_text_str:
|
| 1341 |
-
else:
|
| 1342 |
return
|
| 1343 |
|
| 1344 |
elif current_mode == "stt_waiting_for_audio":
|
| 1345 |
-
if not is_file:
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
|
| 1349 |
-
await process_stt(bot, chat_id, audio_bytes, file_name)
|
| 1350 |
-
except Exception as dl_err: await send_with_keyboard(bot, chat_id, f"❌ خطا در دانلود فایل!\n{str(dl_err)}", False)
|
| 1351 |
return
|
| 1352 |
|
| 1353 |
elif current_mode == "file_waiting_for_file":
|
| 1354 |
-
if not is_file:
|
| 1355 |
-
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
user_states[chat_id]["file_bytes"] = file_bytes
|
| 1359 |
-
user_states[chat_id]["file_name"] = file_name
|
| 1360 |
-
user_states[chat_id]["mode"] = "file_waiting_for_prompt"
|
| 1361 |
-
await send_with_keyboard(bot, chat_id, "✅ فایل با موفقیت دریافت شد.\n\nحالا لطفاً متنی بگویید **چگونه تحلیل شود؟**", False)
|
| 1362 |
-
except Exception as dl_err: await send_with_keyboard(bot, chat_id, f"❌ خطا در دریافت فایل!\n{str(dl_err)}", False)
|
| 1363 |
return
|
| 1364 |
|
| 1365 |
elif current_mode == "file_waiting_for_prompt":
|
|
@@ -1367,19 +1301,16 @@ if bot:
|
|
| 1367 |
saved_bytes = user_states[chat_id].get("file_bytes")
|
| 1368 |
saved_name = user_states[chat_id].get("file_name", "file.jpeg")
|
| 1369 |
user_states[chat_id]["mode"] = "file_waiting_for_file"
|
| 1370 |
-
|
| 1371 |
-
else:
|
| 1372 |
return
|
| 1373 |
|
| 1374 |
elif current_mode == "create_file_waiting_for_topic":
|
| 1375 |
-
if user_text_str:
|
| 1376 |
-
|
| 1377 |
-
else:
|
| 1378 |
-
await send_with_keyboard(bot, chat_id, "⚠️ لطفاً موضوع مقاله خود را به صورت متنی بفرستید.", False)
|
| 1379 |
return
|
| 1380 |
|
| 1381 |
except Exception as e:
|
| 1382 |
-
print("خطا در پردازش:", e)
|
| 1383 |
traceback.print_exc()
|
| 1384 |
|
| 1385 |
if __name__ == "__main__":
|
|
@@ -1388,5 +1319,5 @@ if __name__ == "__main__":
|
|
| 1388 |
print("خطا: توکن ربات بله وارد نشده است! لطفا متغیر BALE_TOKEN را تنظیم کنید.")
|
| 1389 |
else:
|
| 1390 |
print("ربات آلفا پرو با سیستم اشتراک نامحدود + سپر امنیتی متصل به پیامرسان «بله» روشن شد... 🚀")
|
| 1391 |
-
#
|
| 1392 |
-
asyncio.run(bot.polling(non_stop=True, timeout=20, request_timeout=30))
|
|
|
|
| 31 |
|
| 32 |
# --- کد مدیریت برای ارتقای کاربران بدون نیاز به لاگین ---
|
| 33 |
ADMIN_CODE = "3011"
|
|
|
|
|
|
|
| 34 |
BOT_GUID = None
|
| 35 |
|
| 36 |
# --- سیستم دیتابیس حساب کاربری متصل به دیتاست هاگینگ فیس ---
|
|
|
|
| 285 |
return f"Bale Send Error: {str(e)[:100]}"
|
| 286 |
|
| 287 |
|
| 288 |
+
WORKER_URLS = ["https://opera8-ttspro.hf.space/generate"]
|
|
|
|
|
|
|
| 289 |
|
| 290 |
SPEAKERS = {
|
| 291 |
"1": ("شهاب (مرد)", "Charon"), "2": ("آوا (زن)", "Zephyr"), "3": ("نوید (مرد)", "Achird"),
|
|
|
|
| 301 |
}
|
| 302 |
|
| 303 |
user_states = {}
|
| 304 |
+
processed_message_ids = set()
|
| 305 |
|
| 306 |
# --- ۱. پردازش چت متنی و چندرسانهای ---
|
| 307 |
async def process_gemini(client, chat_id, prompt, file_bytes=None, file_name=None):
|
|
|
|
| 323 |
base64_data = base64.b64encode(file_bytes).decode('utf-8')
|
| 324 |
mime_type, _ = mimetypes.guess_type(file_name)
|
| 325 |
if not mime_type:
|
| 326 |
+
mime_type = "image/jpeg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
new_parts.append({"inlineData": {"mimeType": mime_type, "data": base64_data}})
|
| 328 |
|
| 329 |
if history and history[-1]["role"] == "user": history[-1]["parts"].extend(new_parts)
|
|
|
|
| 350 |
except (KeyError, IndexError): continue
|
| 351 |
except Exception: continue
|
| 352 |
|
|
|
|
| 353 |
if not final_answer and HF_TOKENS:
|
| 354 |
hf_messages =[]
|
| 355 |
for msg in history:
|
|
|
|
| 374 |
for hf_key in keys_to_try_hf:
|
| 375 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 376 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 377 |
+
payload = {"model": "google/gemma-4-31B-it:novita", "messages": hf_messages, "max_tokens": 4096}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
try:
|
| 379 |
async with session.post(url, headers=headers, json=payload, timeout=60) as response:
|
| 380 |
if response.status == 200:
|
|
|
|
| 459 |
for hf_key in keys_to_try_hf:
|
| 460 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 461 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 462 |
+
payload = {"model": "google/gemma-4-31B-it:novita", "messages":[{"role": "user", "content":[{"type": "text", "text": gemini_sys_prompt}]}], "max_tokens": 1024}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
try:
|
| 464 |
async with session.post(url, headers=headers, json=payload, timeout=20) as response:
|
| 465 |
if response.status == 200:
|
|
|
|
| 879 |
for hf_key in keys_to_try_hf:
|
| 880 |
url = "https://router.huggingface.co/v1/chat/completions"
|
| 881 |
headers = {"Authorization": f"Bearer {hf_key}", "Content-Type": "application/json"}
|
| 882 |
+
payload = {"model": "google/gemma-4-31B-it:novita", "messages":[{"role": "user", "content":[{"type": "text", "text": ai_prompt}]}], "max_tokens": 4096}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 883 |
try:
|
| 884 |
async with session.post(url, headers=headers, json=payload, timeout=60) as response:
|
| 885 |
if response.status == 200:
|
|
|
|
| 961 |
else:
|
| 962 |
await send_with_keyboard(client, chat_id, "❌ فایلها ساخته شدند اما بله در ارسال آنها دچار مشکل شد.", True)
|
| 963 |
|
| 964 |
+
# --- توابع واسط (Wrappers) برای جلوگیری از مسدود شدن سیستم ضد اسپم ---
|
| 965 |
+
async def task_chat_file(client, chat_id, text, message, file_name):
|
| 966 |
+
try:
|
| 967 |
+
file_bytes = await helper_download_file(client, message)
|
| 968 |
+
await process_gemini(client, chat_id, text, file_bytes=file_bytes, file_name=file_name)
|
| 969 |
+
except Exception as e: await send_with_keyboard(client, chat_id, f"❌ خطا در دریافت فایل!\n{str(e)}", False)
|
| 970 |
+
|
| 971 |
+
async def task_image_edit(client, chat_id, message):
|
| 972 |
+
await send_with_keyboard(client, chat_id, "📥 در حال دانلود عکس...", False)
|
| 973 |
+
try:
|
| 974 |
+
file_bytes = await helper_download_file(client, message)
|
| 975 |
+
user_states[chat_id]["file_bytes"] = file_bytes
|
| 976 |
+
user_states[chat_id]["mode"] = "image_edit_waiting_for_prompt"
|
| 977 |
+
await send_with_keyboard(client, chat_id, "✅ عکس با موفقیت دریافت شد.\n\nحالا دستور خود را به صورت متنی تایپ کنید.\nمثال: یک کلاه قرمز روی سر این گربه بگذار.", False)
|
| 978 |
+
except Exception as e: await send_with_keyboard(client, chat_id, f"❌ خطا در دریافت عکس!\n{str(e)}", False)
|
| 979 |
+
|
| 980 |
+
async def task_stt(client, chat_id, message, file_name):
|
| 981 |
+
await send_with_keyboard(client, chat_id, "📥 در حال دانلود فایل...", False)
|
| 982 |
+
try:
|
| 983 |
+
audio_bytes = await helper_download_file(client, message)
|
| 984 |
+
await process_stt(client, chat_id, audio_bytes, file_name)
|
| 985 |
+
except Exception as e: await send_with_keyboard(client, chat_id, f"❌ خطا در دانلود فایل!\n{str(e)}", False)
|
| 986 |
+
|
| 987 |
+
async def task_file_analysis(client, chat_id, message, file_name):
|
| 988 |
+
await send_with_keyboard(client, chat_id, "📥 در حال دریافت فایل...", False)
|
| 989 |
+
try:
|
| 990 |
+
file_bytes = await helper_download_file(client, message)
|
| 991 |
+
user_states[chat_id]["file_bytes"] = file_bytes
|
| 992 |
+
user_states[chat_id]["file_name"] = file_name
|
| 993 |
+
user_states[chat_id]["mode"] = "file_waiting_for_prompt"
|
| 994 |
+
await send_with_keyboard(client, chat_id, "✅ فایل با موفقیت دریافت شد.\n\nحالا لطفاً متنی بگویید **چگونه تحلیل شود؟**", False)
|
| 995 |
+
except Exception as e: await send_with_keyboard(client, chat_id, f"❌ خطا در دریافت فایل!\n{str(e)}", False)
|
| 996 |
+
|
| 997 |
|
| 998 |
# --- راهاندازی و اتصال هندلرها به بله ---
|
| 999 |
bot = AsyncTeleBot(bot_token) if bot_token else None
|
|
|
|
| 1002 |
@bot.message_handler(func=lambda message: True, content_types=['text', 'photo', 'document', 'voice', 'audio', 'video'])
|
| 1003 |
async def main_handler(message):
|
| 1004 |
try:
|
| 1005 |
+
chat_id = message.chat.id
|
| 1006 |
+
msg_id = message.message_id
|
| 1007 |
+
|
| 1008 |
+
# سیستم ضد تکرار و اسپم
|
| 1009 |
+
unique_msg_key = f"{chat_id}_{msg_id}"
|
| 1010 |
+
if unique_msg_key in processed_message_ids:
|
| 1011 |
+
return
|
| 1012 |
+
processed_message_ids.add(unique_msg_key)
|
| 1013 |
+
if len(processed_message_ids) > 10000:
|
| 1014 |
+
processed_message_ids.clear()
|
| 1015 |
+
|
| 1016 |
global BOT_GUID
|
| 1017 |
if not BOT_GUID:
|
| 1018 |
try:
|
| 1019 |
me_info = await bot.get_me()
|
| 1020 |
if me_info: BOT_GUID = me_info.id
|
| 1021 |
+
except Exception: pass
|
|
|
|
| 1022 |
|
| 1023 |
author_id = message.from_user.id
|
| 1024 |
if BOT_GUID and author_id == BOT_GUID:
|
| 1025 |
return
|
|
|
|
|
|
|
| 1026 |
|
| 1027 |
user_text = message.text or message.caption or ""
|
| 1028 |
user_text_str = str(user_text).strip() if user_text else ""
|
|
|
|
| 1050 |
user_credits_db[target_id]["file"] = 999999
|
| 1051 |
user_credits_db[target_id]["stt"] = 999999
|
| 1052 |
save_db(user_credits_db)
|
| 1053 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, f"✅ حساب کاربر `{target_id}` به مدت ۳۰ روز شارژ شد و به پرو ارتقا یافت.", False))
|
|
|
|
|
|
|
|
|
|
| 1054 |
return
|
| 1055 |
|
| 1056 |
if user_text_lower.startswith(f"{ADMIN_CODE} free=") or user_text_lower.startswith(f"{ADMIN_CODE}free="):
|
|
|
|
| 1063 |
user_credits_db[target_id]["expire_date"] = None
|
| 1064 |
user_credits_db[target_id]["last_reset"] = ""
|
| 1065 |
save_db(user_credits_db)
|
| 1066 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, f"✅ اشتراک کاربر `{target_id}` لغو شد و به رایگان تبدیل گشت.", False))
|
|
|
|
|
|
|
|
|
|
| 1067 |
return
|
| 1068 |
|
| 1069 |
if user_text_lower.startswith(f"{ADMIN_CODE} =") or user_text_lower.startswith(f"{ADMIN_CODE}="):
|
|
|
|
| 1089 |
status_text = "🥉 نسخه رایگان (آزمایشی)\n⏳ سهمیه روزانه"
|
| 1090 |
|
| 1091 |
info_msg = f"🔍 **اطلاعات کاربر `{target_id}`:**\n\n🔹 **وضعیت:** {status_text}\n\n📊 **سهمیه:**\n- چت: {t_creds.get('chat',0)}\n- تولید عکس: {t_creds.get('image',0)}\n- ویرایش عکس: {t_creds.get('edit_image',0)}\n- پادکست: {t_creds.get('podcast',0)}\n- متن به صدا: {t_creds.get('tts',0)}\n- تحلیل فایل: {t_creds.get('file',0)}\n- صدا به متن: {t_creds.get('stt',0)}"
|
| 1092 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, info_msg, False))
|
| 1093 |
else:
|
| 1094 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, f"❌ کاربری با شناسه `{target_id}` در دیتابیس یافت نشد.", False))
|
| 1095 |
return
|
| 1096 |
|
| 1097 |
is_file = False
|
|
|
|
| 1120 |
if not creds.get("has_joined", False):
|
| 1121 |
user_credits_db[str_chat_id]["has_joined"] = True
|
| 1122 |
save_db(user_credits_db)
|
| 1123 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "🎉 **عضویت شما با موفقیت تایید شد! خیلی خوش آمدید.**\n\nحالا میتوانید از تمامی امکانات ربات استفاده کنید.\nلطفاً یکی از گزینههای منو را انتخاب کنید:", True))
|
| 1124 |
return
|
| 1125 |
else:
|
| 1126 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "✅ شما قبلاً عضو شدهاید! لطفا از منوی اصلی استفاده کنید.", True))
|
| 1127 |
return
|
| 1128 |
|
| 1129 |
if not creds.get("has_joined", False):
|
| 1130 |
join_msg = "👋 **سلام کاربر گرامی!**\n\nجهت استفاده از خدمات ربات هوش مصنوعی آلفا و مطلع شدن از آخرین آپدیتها، لطفا ابتدا در کانال رسمی ما عضو شوید:\n\n📢 **آیدی کانال:** @aialpha\n\n👇 پس از عضویت در کانال، بر روی دکمه **«✅ عضو شدم»** کلیک کنید تا ربات برای شما فعال شود."
|
| 1131 |
+
asyncio.create_task(bot.send_message(chat_id, join_msg, reply_markup=get_join_keyboard()))
|
| 1132 |
return
|
| 1133 |
|
| 1134 |
if user_text_str in["/start", "سلام", "لغو", "/cancel", "❌ لغو", "برگشت♻️"]:
|
| 1135 |
user_states[chat_id]["mode"] = None
|
| 1136 |
user_states[chat_id]["file_bytes"] = None
|
| 1137 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "سلام! به ربات هوش مصنوعی آلفا خوش آمدید 🤖\n\nلطفاً برای شروع، از کیبورد پایین یکی از بخشها را انتخاب کنید:", True))
|
| 1138 |
return
|
| 1139 |
|
|
|
|
| 1140 |
if user_text_str in["/account", "حساب کاربری 👤"]:
|
| 1141 |
creds = get_user_credits(chat_id)
|
| 1142 |
is_prem = creds.get("is_premium", False)
|
|
|
|
| 1166 |
image_rem = creds['image']
|
| 1167 |
edit_image_rem = creds['edit_image']
|
| 1168 |
|
| 1169 |
+
account_profile = f"👤 **اطلاعات حساب کاربری شما**\n\n🔹 **شناسه یکتا:** `{chat_id}`\n🔹 **وضعیت اشتراک:** {status_text}{expire_info}\n\n📊 **سهمیه باقیمانده شما:**\n- 💬 چت هوشمند: {chat_rem}\n- 🎨 تولید تصویر: {image_rem} عدد\n- 🪄 ویرایش تصویر: {edit_image_rem} عدد\n- 🎙 ساخت پادکست: {podcast_rem}\n- 🗣 تبدیل متن به صدا: {tts_rem}\n- 📁 تحلیل فایل و سند: {file_rem}\n- 📝 تبدیل صدا به متن: {stt_rem}\n\n{daily_note}"
|
| 1170 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, account_profile, True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1171 |
return
|
| 1172 |
|
| 1173 |
if user_text_str in["/buy", "خرید اشتراک 💎"]:
|
| 1174 |
+
buy_text = f"💎 **خرید اشتراک ویژه آلفا پرو (یک ماهه)**\n\nبا تهیه اشتراک ویژه، محدودیتها را کنار بزنید و از نهایت قدرت هوش مصنوعی لذت ببرید! 🚀\n\n🎁 **بسته طلایی یکماهه شامل:**\n🤖 چت با هوش مصنوعی بصورت نامحدود\n🗣 تبدیل متن به صدا بصورت نامحدود با ۳۰ گوینده\n🎙 ساخت پادکست بصورت نامحدود \n\n🪄 ۱۰ ویرایش تصویر\n🎨 ۲۰ تولید تصویر \n📁 تحلیل نامحدود فایل و سند\n📝 تبدیل فایل صوتی به متن نامحدود\n\n💳 **هزینه اشتراک یک ماهه:** 250 هزار تومان\n\n💳 **شماره کارت جهت واریز:**\n`6219861411958035`\n👤 **به نام:** کوهی\n\n✅ **نحوه فعالسازی:**\nپس از واریز مبلغ، لطفاً رسید پرداختی را به همراه **شناسه یکتای خود** (که در پایین آمده) به آیدی پشتیبانی زیر ارسال کنید تا اشتراک شما فعال گردد:\n\n🔑 **شناسه یکتای شما:** `{chat_id}`\n\n👨💻 **ارتباط با پشتیبانی:**\n🆔 @H_a_m_e_d100"
|
| 1175 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, buy_text, True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1176 |
return
|
| 1177 |
|
| 1178 |
if user_text_str in["/transfer", "انتقال اکانت از برنامه به ربات"]:
|
| 1179 |
+
transfer_text = f"🔄 **انتقال اکانت از برنامه به ربات**\n\nکاربر گرامی، در صورتی که داخل برنامه «هوش مصنوعی آلفا» پیشتر اشتراک تهیه کردهاید، نیازی به خرید مجدد اشتراک داخل ربات نیست! 🎉\n\nکافیست **شناسه یکتای** ربات خود را کپی کرده و برای پشتیبانی ما ارسال کنید تا اکانت اشتراکی شما به سرعت انتقال داده شود.\n\n🔑 **شناسه یکتای ربات شما:** `{chat_id}`\n\n👨💻 **پشتیبانی:**\n🆔 @H_a_m_e_d100"
|
| 1180 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, transfer_text, True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1181 |
return
|
| 1182 |
|
| 1183 |
if user_text_str in["/chat", "💬 چت", "چت با هوش مصنوعی 🤖"]:
|
| 1184 |
user_states[chat_id]["mode"] = "chat"
|
| 1185 |
user_states[chat_id]["history"] =[]
|
| 1186 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "💬 شما وارد بخش **چت با هوش مصنوعی** شدید.\n\nهر سوالی دارید بفرستید تا جواب بدم:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1187 |
return
|
| 1188 |
|
| 1189 |
if user_text_str in ["/image", "🎨 عکس", "ساخت تصاویر🎨"]:
|
| 1190 |
user_states[chat_id]["mode"] = "image_waiting_for_text"
|
| 1191 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "🎨 شما وارد بخش **ساخت عکس پیشرفته** شدید.\n\nمتن خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1192 |
return
|
| 1193 |
|
| 1194 |
if user_text_str in["/edit_image", "ویرایش تصاویر 🪄"]:
|
| 1195 |
user_states[chat_id]["mode"] = "image_edit_waiting_for_image"
|
| 1196 |
user_states[chat_id]["file_bytes"] = None
|
| 1197 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "🪄 به بخش **ویرایش عکس (Flux.2)** خوش آمدید.\n\nلطفاً ابتدا عکسی که میخواهید ویرایش کنید را بفرستید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1198 |
return
|
| 1199 |
|
| 1200 |
if user_text_str in["/tts", "🎙️ صدا", "تبدیل متن به صدا🗣️"]:
|
| 1201 |
user_states[chat_id]["mode"] = "tts_waiting_for_text"
|
| 1202 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "🎙️ شما وارد بخش **تبدیل متن به صدا** شدید.\n\nلطفاً متنی که میخواهید به صدا تبدیل شود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1203 |
return
|
| 1204 |
|
| 1205 |
if user_text_str in["/podcast", "📻 پادکست", "ساخت پادکست 🎙️"]:
|
| 1206 |
user_states[chat_id]["mode"] = "podcast_waiting_for_topic"
|
| 1207 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "📻 شما وارد بخش **ساخت پادکست** شدید.\n\nلطفاً موضوع پادکست خود را بفرستید.\nمثال: درباره تاریخچه پیدایش قهوه با ۳ گوینده یک پادکست جذاب بساز .\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1208 |
return
|
| 1209 |
|
| 1210 |
+
if user_text_str in["/file", "تحلیل فایل 📁"]:
|
| 1211 |
user_states[chat_id]["mode"] = "file_waiting_for_file"
|
| 1212 |
user_states[chat_id]["file_bytes"] = None
|
| 1213 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "📁 شما وارد بخش **تحلیل فایل اختصاصی** شدید.\n\nلطفاً فایل خود را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1214 |
return
|
| 1215 |
|
| 1216 |
if user_text_str in["/stt", "فایل صوتی به متن 📝"]:
|
| 1217 |
user_states[chat_id]["mode"] = "stt_waiting_for_audio"
|
| 1218 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "📝 شما وارد بخش **تبدیل صدا به متن** شدید.\n\nلطفاً فایل خود (ویس، آهنگ، ویدیو و...) را ارسال کنید:\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1219 |
return
|
| 1220 |
|
| 1221 |
if user_text_str in["/create_file", "ساخت فایل 📄"]:
|
| 1222 |
user_states[chat_id]["mode"] = "create_file_waiting_for_topic"
|
| 1223 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "📄 شما وارد بخش **ساخت فایل** شدید.\n\nلطفاً موضوع مقالهای که میخواهید را کامل بفرستید.\nمثال: نحوه مدیریت زمان\n\n(برای خروج دکمه «برگشت♻️» را بزنید)", True))
|
| 1224 |
return
|
| 1225 |
|
| 1226 |
current_mode = user_states[chat_id].get("mode")
|
| 1227 |
|
| 1228 |
if current_mode is None:
|
| 1229 |
if is_file: pass
|
| 1230 |
+
elif user_text_str: asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً ابتدا از کیبورد پایین، بخش مورد نظرتان را انتخاب کنید:", True))
|
| 1231 |
return
|
| 1232 |
|
| 1233 |
elif current_mode == "chat":
|
| 1234 |
+
if is_file: asyncio.create_task(task_chat_file(bot, chat_id, user_text_str, message, file_name))
|
| 1235 |
+
elif user_text_str: asyncio.create_task(process_gemini(bot, chat_id, user_text_str))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1236 |
return
|
| 1237 |
|
| 1238 |
elif current_mode == "image_waiting_for_text":
|
| 1239 |
+
if user_text_str: asyncio.create_task(process_image(bot, chat_id, user_text_str))
|
| 1240 |
return
|
| 1241 |
|
| 1242 |
elif current_mode == "image_edit_waiting_for_image":
|
| 1243 |
+
if not is_file:
|
| 1244 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً ابتدا یک عکس ارسال کنید.", False))
|
| 1245 |
+
return
|
| 1246 |
+
asyncio.create_task(task_image_edit(bot, chat_id, message))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1247 |
return
|
| 1248 |
|
| 1249 |
elif current_mode == "image_edit_waiting_for_prompt":
|
|
|
|
| 1251 |
saved_bytes = user_states[chat_id].get("file_bytes")
|
| 1252 |
user_states[chat_id]["mode"] = None
|
| 1253 |
user_states[chat_id]["file_bytes"] = None
|
| 1254 |
+
asyncio.create_task(process_image_edit(bot, chat_id, saved_bytes, user_text_str))
|
| 1255 |
+
else: asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً درخواست خود را متنی بنویسید.", False))
|
| 1256 |
return
|
| 1257 |
|
| 1258 |
elif current_mode == "tts_waiting_for_text":
|
| 1259 |
if user_text_str:
|
| 1260 |
+
if len(user_text_str) > 2500:
|
| 1261 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً متنی کوتاهتر از 2500 کاراکتر بفرستید.", False))
|
| 1262 |
+
return
|
| 1263 |
user_states[chat_id]["text"] = user_text_str
|
| 1264 |
user_states[chat_id]["mode"] = "tts_waiting_for_speaker"
|
| 1265 |
+
speakers_menu = "✅ متن شما ذخیره شد.\nلطفاً **شماره** گوینده مورد نظر خود را بفرستید:\n1. شهاب | 2. آوا | 3. نوید\n4. آرمان | 5. مهسا | 6. دانا\n7. سامان | 8. آرش | 9. شبنم\n10. سحر | 11. مریم | 12. بهرام\n13. نیکان| 14. فرناز | 15. سارا\n16. مانی | 17. آرتین | 18. دلنواز\n19. روژان | 20. امید | 21. بردیا\n22. ترانه | 23. نیکو | 24. هستی\n25. کامیار| 26. کیانوش| 27. پویا\n28. مهتاب | 29. سام | 30. لیدا"
|
| 1266 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, speakers_menu, False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1267 |
return
|
| 1268 |
|
| 1269 |
elif current_mode == "tts_waiting_for_speaker":
|
| 1270 |
normalized_text = to_english_digits(user_text_str)
|
|
|
|
| 1271 |
if normalized_text.isdigit() and normalized_text in SPEAKERS:
|
| 1272 |
spk_name, spk_id = SPEAKERS[normalized_text]
|
| 1273 |
txt = user_states[chat_id]["text"]
|
| 1274 |
user_states[chat_id]["mode"] = "tts_waiting_for_text"
|
| 1275 |
+
asyncio.create_task(process_tts(bot, chat_id, txt, spk_id, spk_name))
|
| 1276 |
else:
|
| 1277 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "❌ شماره نامعتبر است! لطفاً فقط یک عدد بین 1 تا 30 بفرستید.", False))
|
| 1278 |
return
|
| 1279 |
|
| 1280 |
elif current_mode == "podcast_waiting_for_topic":
|
| 1281 |
+
if user_text_str: asyncio.create_task(process_podcast(bot, chat_id, user_text_str))
|
| 1282 |
+
else: asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً موضوع پادکست خود را به صورت متنی بفرستید.", False))
|
| 1283 |
return
|
| 1284 |
|
| 1285 |
elif current_mode == "stt_waiting_for_audio":
|
| 1286 |
+
if not is_file:
|
| 1287 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً یک فایل ارسال کنید.", False))
|
| 1288 |
+
return
|
| 1289 |
+
asyncio.create_task(task_stt(bot, chat_id, message, file_name))
|
|
|
|
|
|
|
| 1290 |
return
|
| 1291 |
|
| 1292 |
elif current_mode == "file_waiting_for_file":
|
| 1293 |
+
if not is_file:
|
| 1294 |
+
asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً ابتدا یک فایل ارسال کنید.", False))
|
| 1295 |
+
return
|
| 1296 |
+
asyncio.create_task(task_file_analysis(bot, chat_id, message, file_name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1297 |
return
|
| 1298 |
|
| 1299 |
elif current_mode == "file_waiting_for_prompt":
|
|
|
|
| 1301 |
saved_bytes = user_states[chat_id].get("file_bytes")
|
| 1302 |
saved_name = user_states[chat_id].get("file_name", "file.jpeg")
|
| 1303 |
user_states[chat_id]["mode"] = "file_waiting_for_file"
|
| 1304 |
+
asyncio.create_task(process_file_analysis(bot, chat_id, saved_bytes, saved_name, user_text_str))
|
| 1305 |
+
else: asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً درخواست خود را متنی بنویسید.", False))
|
| 1306 |
return
|
| 1307 |
|
| 1308 |
elif current_mode == "create_file_waiting_for_topic":
|
| 1309 |
+
if user_text_str: asyncio.create_task(process_create_file(bot, chat_id, user_text_str))
|
| 1310 |
+
else: asyncio.create_task(send_with_keyboard(bot, chat_id, "⚠️ لطفاً موضوع مقاله خود را به صورت متنی بفرستید.", False))
|
|
|
|
|
|
|
| 1311 |
return
|
| 1312 |
|
| 1313 |
except Exception as e:
|
|
|
|
| 1314 |
traceback.print_exc()
|
| 1315 |
|
| 1316 |
if __name__ == "__main__":
|
|
|
|
| 1319 |
print("خطا: توکن ربات بله وارد نشده است! لطفا متغیر BALE_TOKEN را تنظیم کنید.")
|
| 1320 |
else:
|
| 1321 |
print("ربات آلفا پرو با سیستم اشتراک نامحدود + سپر امنیتی متصل به پیامرسان «بله» روشن شد... 🚀")
|
| 1322 |
+
# کلید حل مشکل اسپم: skip_pending=True
|
| 1323 |
+
asyncio.run(bot.polling(non_stop=True, skip_pending=True, timeout=20, request_timeout=30))
|