Agnivesh10M commited on
Commit
017d0ef
·
verified ·
1 Parent(s): ff99e35

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +72 -33
bot.py CHANGED
@@ -2,7 +2,7 @@ import asyncio
2
  import time
3
  from datetime import datetime, timezone
4
  from pyrogram import Client, filters
5
- from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, InputMediaPhoto
6
  from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
7
  from config import API_ID, API_HASH, BOT_TOKEN, ADMINS, OWNER_HANDLE, SUPPORT_GROUP
8
  from db import db
@@ -16,6 +16,9 @@ PAYMENT_IMG_URL = "https://files.catbox.moe/vnrhxg.jpg"
16
  TUTORIAL_VIDEO_URL = "https://t.me/srcbysachin/19"
17
  PHONEPE_LINK = "https://phon.pe/4fjyavab"
18
 
 
 
 
19
  class Bot(Client):
20
  def __init__(self):
21
  super().__init__(
@@ -83,7 +86,7 @@ def get_start_panel(name: str, is_adm: bool = False):
83
 
84
  def get_back_button():
85
  return InlineKeyboardMarkup([
86
- [InlineKeyboardButton("🔙 मुख्य मेन्यू પર लौटें", callback_data="nav_home")]
87
  ])
88
 
89
  def get_plans_text():
@@ -145,7 +148,7 @@ def get_howtouse_text():
145
  "• `/clone` कमांड भेजें।\n"
146
  "• स्टार्ट लिंक (जहाँ से शुरू करना है) भेजें।\n"
147
  "• एंड लिंक भेजें (सिंगल पोस्ट के लिए `/single` लिखें)।\n"
148
- "• टारगेट चैनल की ID/लिंक भेजें (बॉट में पाने के लिए `/skip` लिखें)।\n\n"
149
  "3️⃣ **स्टेप 3 — सेटिंग्स & स्टार्ट:**\n"
150
  "• अपना कस्टम कैप्शन या थंबनेल सेट करें और **Confirm & Start** दबा दें!\n\n"
151
  "🔄 **ऑटो-रिज्यूम:** टास्क बीच में रुकने पर `/resume` भेजें।\n"
@@ -261,6 +264,60 @@ async def bot_callback_router(client: Client, query: CallbackQuery):
261
  user_id = query.from_user.id
262
  name = query.from_user.first_name
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  if data == "nav_home":
265
  text, buttons = get_start_panel(name, is_admin(user_id))
266
  try:
@@ -467,6 +524,7 @@ async def remove_user_admin(client: Client, message: Message):
467
  except Exception as e:
468
  await message.reply_text(f"Error: {e}")
469
 
 
470
  @bot.on_message(filters.command("broadcast") & filters.private)
471
  async def broadcast_command(client: Client, message: Message):
472
  if not is_admin(message.from_user.id):
@@ -474,38 +532,19 @@ async def broadcast_command(client: Client, message: Message):
474
  if not message.reply_to_message:
475
  return await message.reply_text("⚠️ **इस्तेमाल का तरीका:** जिस मैसेज को सभी को भेजना है, उस पर रिप्लाई करके `/broadcast` लिखें।")
476
 
477
- users = db.get_all_users()
478
- total_users = len(users)
479
- if total_users == 0:
480
- return await message.reply_text("❌ डेटाबेस में कोई यूज़र नहीं मिला।")
481
 
482
- b_msg = await message.reply_text(f"📢 **ब्रॉडकास्ट शुरू हो रहा है...**\nकुल यूज़र्स: `{total_users}`")
483
- success, blocked, failed = 0, 0, 0
 
 
 
 
484
 
485
- for user in users:
486
- u_id = user["user_id"]
487
- try:
488
- await message.reply_to_message.copy(u_id)
489
- success += 1
490
- except FloodWait as f:
491
- await asyncio.sleep(f.value)
492
- try:
493
- await message.reply_to_message.copy(u_id)
494
- success += 1
495
- except Exception:
496
- failed += 1
497
- except (UserIsBlocked, InputUserDeactivated):
498
- blocked += 1
499
- except Exception:
500
- failed += 1
501
- await asyncio.sleep(0.05)
502
-
503
- await b_msg.edit_text(
504
- f"✅ **ब्रॉडकास्ट पूरा हुआ!**\n━━━━━━━━━━━━━━━━━━━━\n"
505
- f"👥 कुल यूज़र्स: `{total_users}`\n"
506
- f"✔️ सफल: `{success}`\n"
507
- f"🚫 बॉट ब्लॉक किया: `{blocked}`\n"
508
- f"❌ असफल: `{failed}`"
509
  )
510
 
511
  if __name__ == "__main__":
 
2
  import time
3
  from datetime import datetime, timezone
4
  from pyrogram import Client, filters
5
+ from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
6
  from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
7
  from config import API_ID, API_HASH, BOT_TOKEN, ADMINS, OWNER_HANDLE, SUPPORT_GROUP
8
  from db import db
 
16
  TUTORIAL_VIDEO_URL = "https://t.me/srcbysachin/19"
17
  PHONEPE_LINK = "https://phon.pe/4fjyavab"
18
 
19
+ # ब्रॉडकास्ट स्टेट ट्रैकर
20
+ PENDING_BROADCASTS = {}
21
+
22
  class Bot(Client):
23
  def __init__(self):
24
  super().__init__(
 
86
 
87
  def get_back_button():
88
  return InlineKeyboardMarkup([
89
+ [InlineKeyboardButton("🔙 मुख्य मेन्यू पर लौटें", callback_data="nav_home")]
90
  ])
91
 
92
  def get_plans_text():
 
148
  "• `/clone` कमांड भेजें।\n"
149
  "• स्टार्ट लिंक (जहाँ से शुरू करना है) भेजें।\n"
150
  "• एंड लिंक भेजें (सिंगल पोस्ट के लिए `/single` लिखें)।\n"
151
+ "• टारगेट चैनल की ID/लिंक भेजें (सीधे बॉट में पाने के लिए `/skip` लिखें)।\n\n"
152
  "3️⃣ **स्टेप 3 — सेटिंग्स & स्टार्ट:**\n"
153
  "• अपना कस्टम कैप्शन या थंबनेल सेट करें और **Confirm & Start** दबा दें!\n\n"
154
  "🔄 **ऑटो-रिज्यूम:** टास्क बीच में रुकने पर `/resume` भेजें।\n"
 
264
  user_id = query.from_user.id
265
  name = query.from_user.first_name
266
 
267
+ # 📌 ब्रॉडकास्ट पिन / नॉर्मल हैंडलर
268
+ if data.startswith("bc_"):
269
+ if not is_admin(user_id):
270
+ return await query.answer("❌ केवल एडमिन के लिए!", show_alert=True)
271
+
272
+ should_pin = (data == "bc_pin")
273
+ msg_id_to_copy = PENDING_BROADCASTS.get(user_id)
274
+ if not msg_id_to_copy:
275
+ return await query.message.edit_text("⚠️ ब्रॉडकास्ट सेशन समाप्त हो गया। दोबारा `/broadcast` करें।")
276
+
277
+ await query.message.edit_text("⏳ **ब्रॉडकास्ट शुरू हो रहा है... कृपया इंतज़ार करें।**")
278
+ users = db.get_all_users()
279
+ total_users = len(users)
280
+
281
+ success, blocked, failed = 0, 0, 0
282
+ for u in users:
283
+ u_id = u["user_id"]
284
+ try:
285
+ sent = await client.copy_message(chat_id=u_id, from_chat_id=user_id, message_id=msg_id_to_copy)
286
+ if should_pin:
287
+ try:
288
+ await sent.pin(both_sides=True)
289
+ except Exception:
290
+ pass
291
+ success += 1
292
+ except FloodWait as f:
293
+ await asyncio.sleep(f.value)
294
+ try:
295
+ sent = await client.copy_message(chat_id=u_id, from_chat_id=user_id, message_id=msg_id_to_copy)
296
+ if should_pin:
297
+ try:
298
+ await sent.pin(both_sides=True)
299
+ except Exception:
300
+ pass
301
+ success += 1
302
+ except Exception:
303
+ failed += 1
304
+ except (UserIsBlocked, InputUserDeactivated):
305
+ blocked += 1
306
+ except Exception:
307
+ failed += 1
308
+ await asyncio.sleep(0.05)
309
+
310
+ PENDING_BROADCASTS.pop(user_id, None)
311
+ pin_status_str = "हाँ (पिन किया गया ✅)" if should_pin else "नहीं (सामान्य ⏩)"
312
+ return await query.message.edit_text(
313
+ f"✅ **ब्रॉडकास्ट पूरा हुआ!**\n━━━━━━━━━━━━━━━━━━━━\n"
314
+ f"👥 कुल यूज़र्स: `{total_users}`\n"
315
+ f"✔️ सफल: `{success}`\n"
316
+ f"🚫 बॉट ब्लॉक किया: `{blocked}`\n"
317
+ f"❌ असफल: `{failed}`\n"
318
+ f"📌 पिन स्टेटस: {pin_status_str}"
319
+ )
320
+
321
  if data == "nav_home":
322
  text, buttons = get_start_panel(name, is_admin(user_id))
323
  try:
 
524
  except Exception as e:
525
  await message.reply_text(f"Error: {e}")
526
 
527
+ # ----------------- BROADCAST WITH PIN OPTION ----------------- #
528
  @bot.on_message(filters.command("broadcast") & filters.private)
529
  async def broadcast_command(client: Client, message: Message):
530
  if not is_admin(message.from_user.id):
 
532
  if not message.reply_to_message:
533
  return await message.reply_text("⚠️ **इस्तेमाल का तरीका:** जिस मैसेज को सभी को भेजना है, उस पर रिप्लाई करके `/broadcast` लिखें।")
534
 
535
+ admin_id = message.from_user.id
536
+ PENDING_BROADCASTS[admin_id] = message.reply_to_message.id
 
 
537
 
538
+ pin_ask_buttons = InlineKeyboardMarkup([
539
+ [
540
+ InlineKeyboardButton("📌 हाँ, सभी के लिए पिन करें", callback_data="bc_pin"),
541
+ InlineKeyboardButton("⏩ नहीं, सामान्य भेजें", callback_data="bc_nopin")
542
+ ]
543
+ ])
544
 
545
+ await message.reply_text(
546
+ "📢 **ब्रॉडकास्ट पुष्टिकरण:**\n\nक्या आप चाहते हैं कि यह मैसेज सभी यूज़र्स के इनबॉक्स में **पिन (Pin)** भी हो जाए?",
547
+ reply_markup=pin_ask_buttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
  )
549
 
550
  if __name__ == "__main__":