Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,22 +16,18 @@ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInf
|
|
| 16 |
|
| 17 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 18 |
|
| 19 |
-
# Flask এর অপ্রয়োজনীয় socket.send() এরর লগস বন্ধ করার জন্য
|
| 20 |
log = logging.getLogger('werkzeug')
|
| 21 |
log.setLevel(logging.ERROR)
|
| 22 |
|
| 23 |
-
# ==================== PYROGRAM NEW ID RANGE FIX
|
| 24 |
def get_peer_type_new(peer_id: int) -> str:
|
| 25 |
peer_id_str = str(peer_id)
|
| 26 |
-
if not peer_id_str.startswith("-"):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
return "channel"
|
| 30 |
-
else:
|
| 31 |
-
return "chat"
|
| 32 |
|
| 33 |
utils.get_peer_type = get_peer_type_new
|
| 34 |
-
# ===================================================================
|
| 35 |
|
| 36 |
# ================= CONFIGURATION =================
|
| 37 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
|
@@ -393,7 +389,16 @@ async def start(client, message):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
@bot.on_message(filters.new_chat_members)
|
| 398 |
async def bot_added_to_group(client, message):
|
| 399 |
me = client.me
|
|
@@ -404,46 +409,35 @@ 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 |
-
# 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 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 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 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 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):
|
|
@@ -461,15 +455,6 @@ async def send_to_specific_group(client, message):
|
|
| 461 |
except Exception as e:
|
| 462 |
await status.edit_text(f"❌ <b>Failed to send!</b>\nError: {e}", parse_mode=enums.ParseMode.HTML)
|
| 463 |
|
| 464 |
-
async def save_progress(source_id, dest_id, msg_id):
|
| 465 |
-
try:
|
| 466 |
-
res = await db_query(lambda: supabase.table('clone_progress').select('id').eq('source_id', source_id).eq('dest_id', dest_id).execute())
|
| 467 |
-
if res.data:
|
| 468 |
-
await db_query(lambda: supabase.table('clone_progress').update({'last_copied_id': msg_id}).eq('id', res.data[0]['id']).execute())
|
| 469 |
-
else:
|
| 470 |
-
await db_query(lambda: supabase.table('clone_progress').insert({'source_id': source_id, 'dest_id': dest_id, 'last_copied_id': msg_id}).execute())
|
| 471 |
-
except Exception as e: print(f"Error saving progress: {e}")
|
| 472 |
-
|
| 473 |
async def clone_videos_background(client, source_id, dest_id, status_msg):
|
| 474 |
try:
|
| 475 |
progress_res = await db_query(lambda: supabase.table('clone_progress').select('last_copied_id').eq('source_id', source_id).eq('dest_id', dest_id).execute())
|
|
@@ -852,6 +837,10 @@ async def handle_media_upload(client, message):
|
|
| 852 |
height=vid_height,
|
| 853 |
thumb=thumb_path
|
| 854 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 855 |
except Exception as e:
|
| 856 |
await message.reply(f"❌ Failed to send final file to you: {e}")
|
| 857 |
return
|
|
|
|
| 16 |
|
| 17 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 18 |
|
|
|
|
| 19 |
log = logging.getLogger('werkzeug')
|
| 20 |
log.setLevel(logging.ERROR)
|
| 21 |
|
| 22 |
+
# ==================== PYROGRAM NEW ID RANGE FIX ====================
|
| 23 |
def get_peer_type_new(peer_id: int) -> str:
|
| 24 |
peer_id_str = str(peer_id)
|
| 25 |
+
if not peer_id_str.startswith("-"): return "user"
|
| 26 |
+
elif peer_id_str.startswith("-100"): return "channel"
|
| 27 |
+
else: return "chat"
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
utils.get_peer_type = get_peer_type_new
|
| 30 |
+
# ===================================================================
|
| 31 |
|
| 32 |
# ================= CONFIGURATION =================
|
| 33 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
|
|
|
| 389 |
await message.reply(welcome_text, parse_mode=enums.ParseMode.HTML, reply_markup=markup)
|
| 390 |
except Exception as e: print(f"Start error: {e}")
|
| 391 |
|
| 392 |
+
async def save_progress(source_id, dest_id, msg_id):
|
| 393 |
+
try:
|
| 394 |
+
res = await db_query(lambda: supabase.table('clone_progress').select('id').eq('source_id', source_id).eq('dest_id', dest_id).execute())
|
| 395 |
+
if res.data:
|
| 396 |
+
await db_query(lambda: supabase.table('clone_progress').update({'last_copied_id': msg_id}).eq('id', res.data[0]['id']).execute())
|
| 397 |
+
else:
|
| 398 |
+
await db_query(lambda: supabase.table('clone_progress').insert({'source_id': source_id, 'dest_id': dest_id, 'last_copied_id': msg_id}).execute())
|
| 399 |
+
except Exception as e: print(f"Error saving progress: {e}")
|
| 400 |
+
|
| 401 |
+
# ================= FIXED: AUTO BROADCAST TO NEW GROUPS =================
|
| 402 |
@bot.on_message(filters.new_chat_members)
|
| 403 |
async def bot_added_to_group(client, message):
|
| 404 |
me = client.me
|
|
|
|
| 409 |
for member in message.new_chat_members:
|
| 410 |
if member.id == me.id:
|
| 411 |
try:
|
|
|
|
| 412 |
await db_query(lambda: supabase.table('groups').upsert({
|
| 413 |
'group_id': message.chat.id,
|
| 414 |
'group_name': message.chat.title,
|
| 415 |
'added_by': message.from_user.id if message.from_user else None
|
| 416 |
}).execute())
|
| 417 |
|
|
|
|
| 418 |
group_name = message.chat.title
|
| 419 |
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>"
|
| 420 |
for admin_id in ADMIN_IDS:
|
| 421 |
try: await client.send_message(chat_id=admin_id, text=admin_msg, parse_mode=enums.ParseMode.HTML)
|
| 422 |
except: pass
|
| 423 |
+
|
| 424 |
+
# Fetching the latest broadcasted video stored with marker dest_id = 0
|
| 425 |
+
progress_res = await db_query(lambda: supabase.table('clone_progress').select('source_id', 'last_copied_id').eq('dest_id', 0).execute())
|
| 426 |
|
| 427 |
+
if progress_res.data:
|
| 428 |
+
last_record = progress_res.data[0]
|
| 429 |
+
src_chat = last_record['source_id']
|
| 430 |
+
msg_id = last_record['last_copied_id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
| 432 |
+
bot_link = f"https://t.me/{me.username}"
|
| 433 |
+
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>"
|
| 434 |
+
group_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🎬 Watch Full Video Here 🔞", url=bot_link)]])
|
| 435 |
+
|
| 436 |
+
await asyncio.sleep(2)
|
| 437 |
+
await client.copy_message(message.chat.id, src_chat, msg_id, caption=caption_text, reply_markup=group_markup)
|
|
|
|
|
|
|
| 438 |
except Exception as e:
|
| 439 |
print(f"Error handling new group logic: {e}")
|
| 440 |
+
# =======================================================================
|
| 441 |
|
| 442 |
@bot.on_message(filters.command("sendto") & filters.private & filters.user(ADMIN_IDS))
|
| 443 |
async def send_to_specific_group(client, message):
|
|
|
|
| 455 |
except Exception as e:
|
| 456 |
await status.edit_text(f"❌ <b>Failed to send!</b>\nError: {e}", parse_mode=enums.ParseMode.HTML)
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
async def clone_videos_background(client, source_id, dest_id, status_msg):
|
| 459 |
try:
|
| 460 |
progress_res = await db_query(lambda: supabase.table('clone_progress').select('last_copied_id').eq('source_id', source_id).eq('dest_id', dest_id).execute())
|
|
|
|
| 837 |
height=vid_height,
|
| 838 |
thumb=thumb_path
|
| 839 |
)
|
| 840 |
+
|
| 841 |
+
# সেভ করে রাখা হচ্ছে যাতে নতুন গ্রুপে এড হলে এই ভিডিওটা দিতে পারে
|
| 842 |
+
await save_progress(message.chat.id, 0, sent_to_admin.id)
|
| 843 |
+
|
| 844 |
except Exception as e:
|
| 845 |
await message.reply(f"❌ Failed to send final file to you: {e}")
|
| 846 |
return
|