Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,6 @@ def run_async(coro):
|
|
| 74 |
bot = Client("file_unlocker_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 75 |
|
| 76 |
# ==================== ROBUST DB QUERY WITH AUTO-RETRY ====================
|
| 77 |
-
# ডাটাবেজ কানেকশন ডিসকানেক্ট হলে যেন ক্র্যাশ না করে, সেজন্য 3-বার রিট্রাই করবে
|
| 78 |
async def db_query(func, max_retries=3):
|
| 79 |
last_error = None
|
| 80 |
for attempt in range(max_retries):
|
|
@@ -85,7 +84,7 @@ async def db_query(func, max_retries=3):
|
|
| 85 |
err_msg = str(e).lower()
|
| 86 |
if "terminated" in err_msg or "disconnect" in err_msg or "timeout" in err_msg or "connection" in err_msg:
|
| 87 |
if attempt < max_retries - 1:
|
| 88 |
-
await asyncio.sleep(1.5)
|
| 89 |
continue
|
| 90 |
raise e
|
| 91 |
raise last_error
|
|
@@ -394,6 +393,7 @@ async def start(client, message):
|
|
| 394 |
await message.reply(welcome_text, parse_mode=enums.ParseMode.HTML, reply_markup=markup)
|
| 395 |
except Exception as e: print(f"Start error: {e}")
|
| 396 |
|
|
|
|
| 397 |
@bot.on_message(filters.new_chat_members)
|
| 398 |
async def bot_added_to_group(client, message):
|
| 399 |
me = client.me
|
|
@@ -404,18 +404,46 @@ async def bot_added_to_group(client, message):
|
|
| 404 |
for member in message.new_chat_members:
|
| 405 |
if member.id == me.id:
|
| 406 |
try:
|
|
|
|
| 407 |
await db_query(lambda: supabase.table('groups').upsert({
|
| 408 |
'group_id': message.chat.id,
|
| 409 |
'group_name': message.chat.title,
|
| 410 |
'added_by': message.from_user.id if message.from_user else None
|
| 411 |
}).execute())
|
| 412 |
|
|
|
|
| 413 |
group_name = message.chat.title
|
| 414 |
admin_msg = f"✅ <b>Bot added to a new group!</b>\n\n📌 <b>Group Name:</b> {group_name}\n🆔 <b>ID:</b> <code>{message.chat.id}</code>"
|
| 415 |
for admin_id in ADMIN_IDS:
|
| 416 |
try: await client.send_message(chat_id=admin_id, text=admin_msg, parse_mode=enums.ParseMode.HTML)
|
| 417 |
except: pass
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
@bot.on_message(filters.command("sendto") & filters.private & filters.user(ADMIN_IDS))
|
| 421 |
async def send_to_specific_group(client, message):
|
|
|
|
| 74 |
bot = Client("file_unlocker_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 75 |
|
| 76 |
# ==================== ROBUST DB QUERY WITH AUTO-RETRY ====================
|
|
|
|
| 77 |
async def db_query(func, max_retries=3):
|
| 78 |
last_error = None
|
| 79 |
for attempt in range(max_retries):
|
|
|
|
| 84 |
err_msg = str(e).lower()
|
| 85 |
if "terminated" in err_msg or "disconnect" in err_msg or "timeout" in err_msg or "connection" in err_msg:
|
| 86 |
if attempt < max_retries - 1:
|
| 87 |
+
await asyncio.sleep(1.5)
|
| 88 |
continue
|
| 89 |
raise e
|
| 90 |
raise last_error
|
|
|
|
| 393 |
await message.reply(welcome_text, parse_mode=enums.ParseMode.HTML, reply_markup=markup)
|
| 394 |
except Exception as e: print(f"Start error: {e}")
|
| 395 |
|
| 396 |
+
# ================= NEW: AUTO BROADCAST TO NEW GROUPS =================
|
| 397 |
@bot.on_message(filters.new_chat_members)
|
| 398 |
async def bot_added_to_group(client, message):
|
| 399 |
me = client.me
|
|
|
|
| 404 |
for member in message.new_chat_members:
|
| 405 |
if member.id == me.id:
|
| 406 |
try:
|
| 407 |
+
# 1. ডাটাবেজে গ্রুপ সেভ করা
|
| 408 |
await db_query(lambda: supabase.table('groups').upsert({
|
| 409 |
'group_id': message.chat.id,
|
| 410 |
'group_name': message.chat.title,
|
| 411 |
'added_by': message.from_user.id if message.from_user else None
|
| 412 |
}).execute())
|
| 413 |
|
| 414 |
+
# 2. এডমিনকে নোটিফিকেশন দেওয়া
|
| 415 |
group_name = message.chat.title
|
| 416 |
admin_msg = f"✅ <b>Bot added to a new group!</b>\n\n📌 <b>Group Name:</b> {group_name}\n🆔 <b>ID:</b> <code>{message.chat.id}</code>"
|
| 417 |
for admin_id in ADMIN_IDS:
|
| 418 |
try: await client.send_message(chat_id=admin_id, text=admin_msg, parse_mode=enums.ParseMode.HTML)
|
| 419 |
except: pass
|
| 420 |
+
|
| 421 |
+
# 3. স্টোরেজ চ্যানেল থেকে সর্বশেষ ভিডিওটি নিয়ে এই গ্রুপে ব্রডকাস্ট করা
|
| 422 |
+
bot_link = f"https://t.me/{me.username}"
|
| 423 |
+
caption_text = f"🔥 <b>New Premium Viral Video Leaked!</b> 🔞\n\n🎬 <b>Watch HD Video Here:</b>\n👉 <b><a href='{bot_link}'>▶️ Click Here to Watch</a></b>\n\n👇 <i>Click the button below to open Bot!</i>"
|
| 424 |
+
group_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🎬 Watch Full Video Here 🔞", url=bot_link)]])
|
| 425 |
+
|
| 426 |
+
last_media_msg = None
|
| 427 |
+
async for msg in client.get_chat_history(STORAGE_CHANNEL_ID, limit=10):
|
| 428 |
+
if msg.video or msg.photo or msg.animation or msg.document:
|
| 429 |
+
last_media_msg = msg
|
| 430 |
+
break
|
| 431 |
+
|
| 432 |
+
if last_media_msg:
|
| 433 |
+
media_file_id = get_msg_file_id(last_media_msg)
|
| 434 |
+
is_photo = bool(last_media_msg.photo)
|
| 435 |
+
|
| 436 |
+
if media_file_id:
|
| 437 |
+
# একটু অপেক্ষা করে মেসেজ পাঠানো (যাতে টেলিগ্রাম স্প্যাম না ভাবে)
|
| 438 |
+
await asyncio.sleep(2)
|
| 439 |
+
if is_photo:
|
| 440 |
+
await client.send_photo(message.chat.id, media_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 441 |
+
else:
|
| 442 |
+
await client.send_video(message.chat.id, media_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 443 |
+
|
| 444 |
+
except Exception as e:
|
| 445 |
+
print(f"Error handling new group logic: {e}")
|
| 446 |
+
# =====================================================================
|
| 447 |
|
| 448 |
@bot.on_message(filters.command("sendto") & filters.private & filters.user(ADMIN_IDS))
|
| 449 |
async def send_to_specific_group(client, message):
|