Agnivesh10M commited on
Commit
9789e4c
·
verified ·
1 Parent(s): 8de7108

Update TechVJ/start.py

Browse files
Files changed (1) hide show
  1. TechVJ/start.py +175 -46
TechVJ/start.py CHANGED
@@ -5,7 +5,7 @@ import math
5
  import re
6
  import subprocess
7
  from pyrogram import Client, filters, enums
8
- from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
9
  from pyrogram.errors import FloodWait, RPCError
10
  from config import API_ID, API_HASH, ADMINS, CHANNEL_ID, WAITING_TIME
11
  from db import db
@@ -18,6 +18,8 @@ except ImportError:
18
  except ImportError:
19
  from fast_download import fast_download_file
20
 
 
 
21
  class batch_temp(object):
22
  IS_BATCH = {}
23
  CLONE_DATA = {}
@@ -99,6 +101,51 @@ def strip_all_urls(text: str) -> str:
99
  text = re.sub(r'\n{3,}', '\n\n', text).strip()
100
  return text
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  # ==================== सामान्य व सूचना कमांड्स ====================
103
 
104
  @Client.on_message(filters.command("start") & filters.private)
@@ -116,7 +163,7 @@ async def start_msg_handler(client: Client, message: Message):
116
  "• टॉपिक (Forum Topics) सपोर्ट\n"
117
  "• कैप्शन रिप्लेसमेंट, लिंक्स रिमूवर व हाइपरलिंक टूल\n"
118
  "• ऑटो थंबनेल व रेज़्यूम सपोर्ट\n\n"
119
- "👉 शुरू करने के लिए **/clone** लिखें या नीचे दिए गए बटन्स का उपयोग करें।"
120
  )
121
  buttons = InlineKeyboardMarkup([
122
  [InlineKeyboardButton("📖 उपयोग कैसे करें (Guide)", callback_data="nav_howtouse"),
@@ -167,7 +214,8 @@ async def myplan_handler(client: Client, message: Message):
167
  is_vip = db.is_user_vip(user_id, ADMINS)
168
  user_data = db.get_user(user_id)
169
 
170
- if user_id in ADMINS:
 
171
  return await message.reply_text("👑 **आप बॉट के एडमिन हैं!** आपके पास आजीवन असीमित VIP एक्सेस है।")
172
 
173
  if is_vip and user_data and user_data.get("plan_expiry"):
@@ -196,11 +244,11 @@ async def howtouse_handler(client: Client, message: Message):
196
  "📖 **बॉट का उपयोग कैसे करें? (Quick Guide)**\n"
197
  "━━━━━━━━━━━━━━━━━━━━\n"
198
  "1️⃣ सबसे पहले **/login** कमांड भेजकर अपना टेलीग्राम अकाउंट बॉट से कनेक्ट करें।\n"
199
- "2️⃣ इसके बाद **/clone** कमांड भेजें।\n"
200
  "3️⃣ जहाँ से कंटेंट कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें।\n"
201
- "4️⃣ इसके बाद **अंतिम लिंक (End Link)** भेजें (अगर एक ही मैसेज चाहिए तो `/single` लिखें)।\n"
202
  "5️⃣ जिस चैनल में अपलोड करना है, उसका लिंक/आईडी भेजें (सीधे बॉट में पाने के लिए `/skip` लिखें)।\n"
203
- "6️⃣ कस्टमाइज़ेशन मेन्यू खुलेगा, जहाँ आप नया कैप्शन, वर्ड रिप्लेसमेंट, लिंक्स रिमूवर या थंबनेल सेट करके **🚀 Confirm & Start** दबाएँ।"
204
  )
205
  await message.reply_text(help_text)
206
 
@@ -240,19 +288,18 @@ async def lang_handler(client: Client, message: Message):
240
  @Client.on_message(filters.command("users") & filters.private)
241
  async def users_admin_handler(client: Client, message: Message):
242
  user_id = message.from_user.id
243
- if user_id not in ADMINS:
 
244
  return
245
  users = db.get_all_users()
246
- vip_count = 0
247
- for u in users:
248
- if u.get("plan_expiry"):
249
- vip_count += 1
250
  await message.reply_text(f"📊 **बॉट आँकड़े (Admin Panel):**\n\n👥 कुल रजिस्टर्ड यूजर्स: `{len(users)}`\n💎 एक्टिव VIP यूजर्स: `{vip_count}`")
251
 
252
  @Client.on_message(filters.command("setprice") & filters.private)
253
  async def setprice_handler(client: Client, message: Message):
254
  user_id = message.from_user.id
255
- if user_id not in ADMINS:
 
256
  return
257
  args = message.text.split()
258
  if len(args) != 3:
@@ -264,7 +311,8 @@ async def setprice_handler(client: Client, message: Message):
264
  @Client.on_message(filters.command("broadcast") & filters.private)
265
  async def broadcast_handler(client: Client, message: Message):
266
  user_id = message.from_user.id
267
- if user_id not in ADMINS:
 
268
  return
269
  if not message.reply_to_message:
270
  return await message.reply_text("⚠️ कृपया जिस मैसेज को ब्रॉडकास्ट करना है, उसे रिप्लाई करते हुए `/broadcast` लिखें।")
@@ -297,27 +345,22 @@ async def send_cancel(client: Client, message: Message):
297
  def parse_telegram_link(link: str):
298
  link = link.strip().replace("?single", "")
299
 
300
- # 1. प्राइवेट फोरम टॉपिक लिंक: t.me/c/1234567/5/100
301
  c_topic = re.search(r"t\.me/c/(\d+)/(\d+)/(\d+)", link)
302
  if c_topic:
303
  return int("-100" + c_topic.group(1)), int(c_topic.group(3)), int(c_topic.group(2))
304
 
305
- # 2. पब्लिक फोरम टॉपिक लिंक: t.me/channelname/5/100
306
  p_topic = re.search(r"t\.me/([^/]+)/(\d+)/(\d+)", link)
307
  if p_topic and p_topic.group(1) not in ["c", "b"]:
308
  return p_topic.group(1), int(p_topic.group(3)), int(p_topic.group(2))
309
 
310
- # 3. प्राइवेट सामान्य लिंक: t.me/c/1234567/100
311
  c_match = re.search(r"t\.me/c/(\d+)/(\d+)", link)
312
  if c_match:
313
  return int("-100" + c_match.group(1)), int(c_match.group(2)), None
314
 
315
- # 4. बॉट लिंक: t.me/b/username/100
316
  b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
317
  if b_match:
318
  return b_match.group(1), int(b_match.group(2)), None
319
 
320
- # 5. पब्लिक सामान्य लिंक: t.me/username/100
321
  p_match = re.search(r"t\.me/([^/]+)/(\d+)", link)
322
  if p_match:
323
  return p_match.group(1), int(p_match.group(2)), None
@@ -333,7 +376,7 @@ async def resume_command(client: Client, message: Message):
333
  task = batch_temp.CLONE_DATA.get(user_id)
334
  last_id = batch_temp.LAST_SAVED_ID.get(user_id)
335
  if not task or last_id is None:
336
- return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला। नया टास्क शुरू करने के लिए `/clone` करें।")
337
 
338
  if last_id >= task["end_id"]:
339
  return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
@@ -343,8 +386,17 @@ async def resume_command(client: Client, message: Message):
343
  await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक, शेष: {total_remaining})")
344
  await start_clone_task(client, user_id)
345
 
 
346
  @Client.on_message(filters.command(["clone", "clon"]) & filters.private)
347
  async def clone_command(client: Client, message: Message):
 
 
 
 
 
 
 
 
348
  user_id = message.from_user.id
349
  if not db.is_user_vip(user_id, ADMINS):
350
  return await message.reply_text(
@@ -357,11 +409,11 @@ async def clone_command(client: Client, message: Message):
357
  if not user_session:
358
  return await message.reply_text("🔑 पहले **/login** करें ताकि आपके अकाउंट से फाइल्स ट्रांसफर हो सकें।")
359
 
 
360
  guide_text = (
361
- "📖 **कंटेंट क्लोनिंग निर्देश:**\n"
362
  "━━━━━━━━━━━━━━━━━━━━\n"
363
  "👉 **स्टेप 1:** जहाँ से कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें:\n"
364
- "(पब्लिक, प्राइवेट, बॉट लिंक या टॉपिक लिंक मान्य हैं)\n"
365
  "(रद्द करने के लिए /cancel लिखें)"
366
  )
367
  first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
@@ -371,7 +423,7 @@ async def clone_command(client: Client, message: Message):
371
  start_link = first_msg.text.strip()
372
  s_chat, s_id, s_topic = parse_telegram_link(start_link)
373
  if not s_id:
374
- return await first_msg.reply("❌ अमान्य टेलीग्राम लिंक! दोबारा /clone करें।")
375
 
376
  last_msg = await client.ask(
377
  user_id,
@@ -388,7 +440,7 @@ async def clone_command(client: Client, message: Message):
388
  end_link = last_msg.text.strip()
389
  e_chat, e_id, e_topic = parse_telegram_link(end_link)
390
  if not e_id:
391
- return await last_msg.reply("❌ अमान्य अंतिम लिंक! दोबारा /clone करें।")
392
 
393
  dest_msg = await client.ask(
394
  user_id,
@@ -415,6 +467,8 @@ async def clone_command(client: Client, message: Message):
415
  "target_chat": target_chat,
416
  "target_topic_id": None,
417
  "is_direct_bot": is_direct_bot,
 
 
418
  "custom_caption": None,
419
  "extra_caption": None,
420
  "replace_find": None,
@@ -447,6 +501,8 @@ async def clone_command(client: Client, message: Message):
447
  "target_chat": target_chat,
448
  "target_topic_id": target_topic_id,
449
  "is_direct_bot": is_direct_bot,
 
 
450
  "custom_caption": None,
451
  "extra_caption": None,
452
  "replace_find": None,
@@ -472,6 +528,33 @@ async def clone_command(client: Client, message: Message):
472
 
473
  async def show_customization_menu(client: Client, user_id: int):
474
  data = batch_temp.CLONE_DATA.get(user_id, {})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  cap_status = "कस्टम सेट है ✅" if data.get("custom_caption") else "ओरिजिनल"
476
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
477
  thm_status = "सेट है ✅" if data.get("thumb_path") else "डिफ़ॉल्ट"
@@ -480,12 +563,6 @@ async def show_customization_menu(client: Client, user_id: int):
480
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
481
  link_attach_status = f"[{data.get('hyperlink_word')}]({data.get('hyperlink_url')})" if data.get("hyperlink_word") else "कोई नहीं"
482
 
483
- dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
484
- if data.get("target_topic_id"):
485
- dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
486
-
487
- total_msgs = (data.get('end_id', 0) - data.get('start_id', 0)) + 1
488
-
489
  panel_text = (
490
  "⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
491
  "━━━━━━━━━━━━━━━━━━━━\n"
@@ -538,9 +615,21 @@ async def callback_handler(client: Client, query: CallbackQuery):
538
  return await query.message.edit_text(f"✅ भाषा बदलकर **{lang_name}** कर दी गई है!")
539
 
540
  if user_id not in batch_temp.CLONE_DATA:
541
- return await query.answer("⚠️ सेशन एक्सपायर हो गया, दोबारा /clone करें।", show_alert=True)
542
 
543
- if data == "ask_topic_yes":
 
 
 
 
 
 
 
 
 
 
 
 
544
  await query.message.delete()
545
  t_msg = await client.ask(
546
  user_id,
@@ -696,7 +785,6 @@ async def start_clone_task(client: Client, user_id: int):
696
  if batch_temp.IS_BATCH.get(user_id):
697
  break
698
  try:
699
- # बड़ी 2GB तक की फाइल्स के लिए पर्याप्त समय सीमा (1800 सेकंड / 30 मिनट)
700
  ok, sz = await asyncio.wait_for(
701
  process_media(
702
  client, acc, user_id, source_chat, msgid,
@@ -831,19 +919,60 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
831
  if not msg or msg.empty or msg.service:
832
  return False, 0
833
 
834
- raw_caption = msg.caption.markdown if msg.caption else ""
835
- final_caption = format_caption_text(raw_caption, task)
836
-
837
  is_direct_bot = task.get("is_direct_bot", False)
 
838
  sender_client = client if is_direct_bot else acc
839
  topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
840
 
841
- # सादा टेक्स्ट मैसेज
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842
  if msg.text:
843
  text_to_send = format_caption_text(msg.text.markdown, task)
844
  await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
845
  return True, len(text_to_send.encode('utf-8'))
846
 
 
 
 
 
 
 
 
 
847
  file_name = get_file_name_from_msg(msg)
848
  user_down_dir = os.path.join("downloads", str(user_id))
849
  os.makedirs(user_down_dir, exist_ok=True)
@@ -851,7 +980,6 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
851
 
852
  remaining = max(0, total_count - current_idx)
853
 
854
- # 1. अगर फ़ाइल पहले से पूरी डाउनलोड है, तो दोबारा डाउनलोड करने की ज़रूरत नहीं
855
  file_path = None
856
  if os.path.exists(down_path) and os.path.getsize(down_path) > 1024:
857
  file_path = down_path
@@ -914,26 +1042,30 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
914
  created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
915
  thumb_to_use = created_temp_thumb
916
 
 
 
 
 
 
 
917
  try:
918
  if msg.photo:
919
  await sender_client.send_photo(
920
- target_chat, file_path, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs
921
  )
922
  elif msg.video:
923
- # बड़ी वीडियो के लिए अपलोड प्रयास
924
  for up_retry in range(3):
925
  try:
926
  await sender_client.send_video(
927
  target_chat,
928
  video=file_path,
929
  thumb=thumb_to_use,
930
- caption=final_caption,
931
- parse_mode=enums.ParseMode.MARKDOWN,
932
  duration=getattr(msg.video, "duration", 0) or 0,
933
  width=getattr(msg.video, "width", 0) or 0,
934
  height=getattr(msg.video, "height", 0) or 0,
935
  progress=progress_bar,
936
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
 
937
  **topic_kwargs
938
  )
939
  break
@@ -948,11 +1080,10 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
948
  target_chat,
949
  audio=file_path,
950
  thumb=thumb_to_use,
951
- caption=final_caption,
952
- parse_mode=enums.ParseMode.MARKDOWN,
953
  duration=getattr(msg.audio, "duration", 0) or 0,
954
  progress=progress_bar,
955
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
 
956
  **topic_kwargs
957
  )
958
  else:
@@ -962,10 +1093,9 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
962
  target_chat,
963
  document=file_path,
964
  thumb=thumb_to_use,
965
- caption=final_caption,
966
- parse_mode=enums.ParseMode.MARKDOWN,
967
  progress=progress_bar,
968
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
 
969
  **topic_kwargs
970
  )
971
  break
@@ -986,7 +1116,6 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
986
  print(f"Upload error on msg {msgid}: {e}")
987
  return False, 0
988
  finally:
989
- # केवल तभी फ़ाइल डिलीट होगी जब वह सुरक्षित सेंड हो जाए या पूरी तरह कैंसल हो
990
  if os.path.exists(file_path):
991
  try:
992
  os.remove(file_path)
 
5
  import re
6
  import subprocess
7
  from pyrogram import Client, filters, enums
8
+ from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, MessageEntity
9
  from pyrogram.errors import FloodWait, RPCError
10
  from config import API_ID, API_HASH, ADMINS, CHANNEL_ID, WAITING_TIME
11
  from db import db
 
18
  except ImportError:
19
  from fast_download import fast_download_file
20
 
21
+ DEFAULT_UPSC_LINK = "https://t.me/Avigat1210"
22
+
23
  class batch_temp(object):
24
  IS_BATCH = {}
25
  CLONE_DATA = {}
 
101
  text = re.sub(r'\n{3,}', '\n\n', text).strip()
102
  return text
103
 
104
+ def build_upsc_entities_and_text(raw_text: str, raw_entities: list, target_url: str):
105
+ """
106
+ 1. सोर्स पोस्ट के सभी पुराने लिंक्स (TEXT_LINK, URL, MENTION) को हटाता है।
107
+ 2. Table, Blockquote, Italic, Underline आदि सभी मूल फॉर्मेटिंग को 100% सुरक्षित रखता है।
108
+ 3. जितने भी BOLD शब्द/हेडिंग्स हैं, उन सभी के ऊपर दी गई लिंक (target_url) मर्ज करता है।
109
+ """
110
+ if not raw_text:
111
+ return "", []
112
+
113
+ clean_entities = []
114
+ if raw_entities:
115
+ for ent in raw_entities:
116
+ # पुराने सभी बाहरी लिंक्स को स्किप करें
117
+ if ent.type in (
118
+ enums.MessageEntityType.TEXT_LINK,
119
+ enums.MessageEntityType.URL,
120
+ enums.MessageEntityType.MENTION,
121
+ enums.MessageEntityType.TEXT_MENTION
122
+ ):
123
+ continue
124
+
125
+ # मूल फॉर्मेटिंग (Bold, Table, Pre, Blockquote आदि) सुरक्षित रखें
126
+ clean_entities.append(
127
+ MessageEntity(
128
+ type=ent.type,
129
+ offset=ent.offset,
130
+ length=ent.length,
131
+ language=getattr(ent, "language", None),
132
+ custom_emoji_id=getattr(ent, "custom_emoji_id", None)
133
+ )
134
+ )
135
+
136
+ # हर BOLD एंटिटी के ऊपर आपकी लिंक मर्ज करें
137
+ if ent.type == enums.MessageEntityType.BOLD and target_url:
138
+ clean_entities.append(
139
+ MessageEntity(
140
+ type=enums.MessageEntityType.TEXT_LINK,
141
+ offset=ent.offset,
142
+ length=ent.length,
143
+ url=target_url
144
+ )
145
+ )
146
+
147
+ return raw_text, clean_entities
148
+
149
  # ==================== सामान्य व सूचना कमांड्स ====================
150
 
151
  @Client.on_message(filters.command("start") & filters.private)
 
163
  "• टॉपिक (Forum Topics) सपोर्ट\n"
164
  "• कैप्शन रिप्लेसमेंट, लिंक्स रिमूवर व हाइपरलिंक टूल\n"
165
  "• ऑटो थंबनेल व रेज़्यूम सपोर्ट\n\n"
166
+ "👉 शुरू करने के लिए **/clone** या **/upscclone** लिखें।"
167
  )
168
  buttons = InlineKeyboardMarkup([
169
  [InlineKeyboardButton("📖 उपयोग कैसे करें (Guide)", callback_data="nav_howtouse"),
 
214
  is_vip = db.is_user_vip(user_id, ADMINS)
215
  user_data = db.get_user(user_id)
216
 
217
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
218
+ if user_id in adm_list:
219
  return await message.reply_text("👑 **आप बॉट के एडमिन हैं!** आपके पास आजीवन असीमित VIP एक्सेस है।")
220
 
221
  if is_vip and user_data and user_data.get("plan_expiry"):
 
244
  "📖 **बॉट का उपयोग कैसे करें? (Quick Guide)**\n"
245
  "━━━━━━━━━━━━━━━━━━━━\n"
246
  "1️⃣ सबसे पहले **/login** कमांड भेजकर अपना टेलीग्राम अकाउंट बॉट से कनेक्ट करें।\n"
247
+ "2️⃣ सामान्य मीडिया/फ़ाइल क्लोन के लिए **/clone** और UPSC टेबल/करंट अफेयर्स पोस्ट के लिए **/upscclone** भेजें।\n"
248
  "3️⃣ जहाँ से कंटेंट कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें।\n"
249
+ "4️⃣ इसके बाद **अंतिम लिंक (End Link)** भेजें (सिंगल पोस्ट के लिए `/single` लिखें)।\n"
250
  "5️⃣ जिस चैनल में अपलोड करना है, उसका लिंक/आईडी भेजें (सीधे बॉट में पाने के लिए `/skip` लिखें)।\n"
251
+ "6️⃣ कस्टमाइज़ेशन मेन्यू में अपनी सेटिंग्स जाँचें और **🚀 Confirm & Start** दबाएँ।"
252
  )
253
  await message.reply_text(help_text)
254
 
 
288
  @Client.on_message(filters.command("users") & filters.private)
289
  async def users_admin_handler(client: Client, message: Message):
290
  user_id = message.from_user.id
291
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
292
+ if user_id not in adm_list:
293
  return
294
  users = db.get_all_users()
295
+ vip_count = sum(1 for u in users if u.get("plan_expiry"))
 
 
 
296
  await message.reply_text(f"📊 **बॉट आँकड़े (Admin Panel):**\n\n👥 कुल रजिस्टर्ड यूजर्स: `{len(users)}`\n💎 एक्टिव VIP यूजर्स: `{vip_count}`")
297
 
298
  @Client.on_message(filters.command("setprice") & filters.private)
299
  async def setprice_handler(client: Client, message: Message):
300
  user_id = message.from_user.id
301
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
302
+ if user_id not in adm_list:
303
  return
304
  args = message.text.split()
305
  if len(args) != 3:
 
311
  @Client.on_message(filters.command("broadcast") & filters.private)
312
  async def broadcast_handler(client: Client, message: Message):
313
  user_id = message.from_user.id
314
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
315
+ if user_id not in adm_list:
316
  return
317
  if not message.reply_to_message:
318
  return await message.reply_text("⚠️ कृपया जिस मैसेज को ब्रॉडकास्ट करना है, उसे रिप्लाई करते हुए `/broadcast` लिखें।")
 
345
  def parse_telegram_link(link: str):
346
  link = link.strip().replace("?single", "")
347
 
 
348
  c_topic = re.search(r"t\.me/c/(\d+)/(\d+)/(\d+)", link)
349
  if c_topic:
350
  return int("-100" + c_topic.group(1)), int(c_topic.group(3)), int(c_topic.group(2))
351
 
 
352
  p_topic = re.search(r"t\.me/([^/]+)/(\d+)/(\d+)", link)
353
  if p_topic and p_topic.group(1) not in ["c", "b"]:
354
  return p_topic.group(1), int(p_topic.group(3)), int(p_topic.group(2))
355
 
 
356
  c_match = re.search(r"t\.me/c/(\d+)/(\d+)", link)
357
  if c_match:
358
  return int("-100" + c_match.group(1)), int(c_match.group(2)), None
359
 
 
360
  b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
361
  if b_match:
362
  return b_match.group(1), int(b_match.group(2)), None
363
 
 
364
  p_match = re.search(r"t\.me/([^/]+)/(\d+)", link)
365
  if p_match:
366
  return p_match.group(1), int(p_match.group(2)), None
 
376
  task = batch_temp.CLONE_DATA.get(user_id)
377
  last_id = batch_temp.LAST_SAVED_ID.get(user_id)
378
  if not task or last_id is None:
379
+ return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला। नया टास्क शुरू करने के लिए `/clone` या `/upscclone` करें।")
380
 
381
  if last_id >= task["end_id"]:
382
  return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
 
386
  await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक, शेष: {total_remaining})")
387
  await start_clone_task(client, user_id)
388
 
389
+ # सामान्य क्लोन कमांड (पुराना सिस्टम 100% सुरक्षित)
390
  @Client.on_message(filters.command(["clone", "clon"]) & filters.private)
391
  async def clone_command(client: Client, message: Message):
392
+ await init_clone_workflow(client, message, is_upsc_mode=False)
393
+
394
+ # विशेष UPSC करंट अफेयर्स / टेबल क्लोन कमांड
395
+ @Client.on_message(filters.command(["upscclone"]) & filters.private)
396
+ async def upsc_clone_command(client: Client, message: Message):
397
+ await init_clone_workflow(client, message, is_upsc_mode=True)
398
+
399
+ async def init_clone_workflow(client: Client, message: Message, is_upsc_mode: bool = False):
400
  user_id = message.from_user.id
401
  if not db.is_user_vip(user_id, ADMINS):
402
  return await message.reply_text(
 
409
  if not user_session:
410
  return await message.reply_text("🔑 पहले **/login** करें ताकि आपके अकाउंट से फाइल्स ट्रांसफर हो सकें।")
411
 
412
+ mode_banner = "📚 **UPSC पोस्ट & टेबल क्लोनिंग मोड:**" if is_upsc_mode else "📖 **कंटेंट क्लोनिंग निर्देश:**"
413
  guide_text = (
414
+ f"{mode_banner}\n"
415
  "━━━━━━━━━━━━━━━━━━━━\n"
416
  "👉 **स्टेप 1:** जहाँ से कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें:\n"
 
417
  "(रद्द करने के लिए /cancel लिखें)"
418
  )
419
  first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
 
423
  start_link = first_msg.text.strip()
424
  s_chat, s_id, s_topic = parse_telegram_link(start_link)
425
  if not s_id:
426
+ return await first_msg.reply("❌ अमान्य टेलीग्राम लिंक! दोबारा प्रयास करें।")
427
 
428
  last_msg = await client.ask(
429
  user_id,
 
440
  end_link = last_msg.text.strip()
441
  e_chat, e_id, e_topic = parse_telegram_link(end_link)
442
  if not e_id:
443
+ return await last_msg.reply("❌ अमान्य अंतिम लिंक! दोबारा प्रयास करें।")
444
 
445
  dest_msg = await client.ask(
446
  user_id,
 
467
  "target_chat": target_chat,
468
  "target_topic_id": None,
469
  "is_direct_bot": is_direct_bot,
470
+ "is_upsc_mode": is_upsc_mode,
471
+ "upsc_link": DEFAULT_UPSC_LINK,
472
  "custom_caption": None,
473
  "extra_caption": None,
474
  "replace_find": None,
 
501
  "target_chat": target_chat,
502
  "target_topic_id": target_topic_id,
503
  "is_direct_bot": is_direct_bot,
504
+ "is_upsc_mode": is_upsc_mode,
505
+ "upsc_link": DEFAULT_UPSC_LINK,
506
  "custom_caption": None,
507
  "extra_caption": None,
508
  "replace_find": None,
 
528
 
529
  async def show_customization_menu(client: Client, user_id: int):
530
  data = batch_temp.CLONE_DATA.get(user_id, {})
531
+ is_upsc = data.get("is_upsc_mode", False)
532
+ dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
533
+ if data.get("target_topic_id"):
534
+ dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
535
+ total_msgs = (data.get('end_id', 0) - data.get('start_id', 0)) + 1
536
+
537
+ # यदि /upscclone मोड सक्रिय है तो उसका समर्पित पैनल दिखाएँ
538
+ if is_upsc:
539
+ upsc_url = data.get("upsc_link", DEFAULT_UPSC_LINK)
540
+ panel_text = (
541
+ "📚 **UPSC POST CLONER SETTINGS:**\n"
542
+ "━━━━━━━━━━━━━━━━━━━━\n"
543
+ "✨ **मोड:** टेबल, मैप प्रीव्यू & Show More सुरक्षित\n"
544
+ "🚫 **पुराने चैनल लिंक्स:** ऑटो-डिलीट (100% साफ)\n"
545
+ f"🔗 **सभी Bold शब्दों पर लिंक:** `{upsc_url}`\n"
546
+ f"🎯 **टारगेट:** {dest_display}\n"
547
+ f"📊 **रेंज:** `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_msgs} पोस्ट)\n"
548
+ "━━━━━━━━━━━━━━━━━━━━\n"
549
+ "लिंक बदलने के लिए नीचे बटन दबाएँ या **🚀 Confirm & Start** करें:"
550
+ )
551
+ buttons = InlineKeyboardMarkup([
552
+ [InlineKeyboardButton("🔗 Change UPSC Link (लिंक बदलें)", callback_data="set_upsc_link")],
553
+ [InlineKeyboardButton("🚀 Confirm & Start", callback_data="confirm_start")]
554
+ ])
555
+ return await client.send_message(user_id, panel_text, reply_markup=buttons, disable_web_page_preview=True)
556
+
557
+ # सामान्य /clone मोड का पैनल (पहले जैसा ही)
558
  cap_status = "कस्टम सेट है ✅" if data.get("custom_caption") else "ओरिजिनल"
559
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
560
  thm_status = "सेट है ✅" if data.get("thumb_path") else "डिफ़ॉल्ट"
 
563
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
564
  link_attach_status = f"[{data.get('hyperlink_word')}]({data.get('hyperlink_url')})" if data.get("hyperlink_word") else "कोई नहीं"
565
 
 
 
 
 
 
 
566
  panel_text = (
567
  "⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
568
  "━━━━━━━━━━━━━━━━━━━━\n"
 
615
  return await query.message.edit_text(f"✅ भाषा बदलकर **{lang_name}** कर दी गई है!")
616
 
617
  if user_id not in batch_temp.CLONE_DATA:
618
+ return await query.answer("⚠️ सेशन एक्सपायर हो गया, दोबारा /clone या /upscclone करें।", show_alert=True)
619
 
620
+ if data == "set_upsc_link":
621
+ await query.message.delete()
622
+ l_msg = await client.ask(
623
+ user_id,
624
+ "🔗 **नई लिंक भेजें** जो सभी Bold शब्दों पर लगानी है:\n(उदाहरण: `https://t.me/Avigat1210`)\n\nरद्द करने के लिए `/cancel` लिखें:",
625
+ filters=filters.text,
626
+ timeout=180
627
+ )
628
+ if l_msg.text != "/cancel":
629
+ batch_temp.CLONE_DATA[user_id]["upsc_link"] = l_msg.text.strip()
630
+ await show_customization_menu(client, user_id)
631
+
632
+ elif data == "ask_topic_yes":
633
  await query.message.delete()
634
  t_msg = await client.ask(
635
  user_id,
 
785
  if batch_temp.IS_BATCH.get(user_id):
786
  break
787
  try:
 
788
  ok, sz = await asyncio.wait_for(
789
  process_media(
790
  client, acc, user_id, source_chat, msgid,
 
919
  if not msg or msg.empty or msg.service:
920
  return False, 0
921
 
 
 
 
922
  is_direct_bot = task.get("is_direct_bot", False)
923
+ is_upsc_mode = task.get("is_upsc_mode", False)
924
  sender_client = client if is_direct_bot else acc
925
  topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
926
 
927
+ # ==================== UPSC CLONE विशेष हैंडलर ====================
928
+ if is_upsc_mode:
929
+ upsc_url = task.get("upsc_link", DEFAULT_UPSC_LINK)
930
+
931
+ # यदि यह UPSC करंट अफेयर्स टेक्स्ट/टेबल पोस्ट है (जिसमें बीच में मैप प्रीव्यू भी हो सकता है)
932
+ if msg.text:
933
+ clean_txt, custom_ents = build_upsc_entities_and_text(msg.text, msg.entities, upsc_url)
934
+
935
+ # यदि पोस्ट के बीच में कोई मैप/इमेज प्रीव्यू (WebPage Preview) लगा है तो उसे हूबहू अटैच करें
936
+ wp_kwargs = {}
937
+ if getattr(msg, "web_page", None) and getattr(msg.web_page, "url", None):
938
+ try:
939
+ from pyrogram.types import LinkPreviewOptions
940
+ wp_kwargs["link_preview_options"] = LinkPreviewOptions(
941
+ url=msg.web_page.url,
942
+ prefer_large_media=True,
943
+ show_above_text=getattr(msg, "show_caption_above_media", False)
944
+ )
945
+ except ImportError:
946
+ wp_kwargs["disable_web_page_preview"] = False
947
+ else:
948
+ wp_kwargs["disable_web_page_preview"] = True
949
+
950
+ await sender_client.send_message(
951
+ target_chat,
952
+ text=clean_txt,
953
+ entities=custom_ents,
954
+ **wp_kwargs,
955
+ **topic_kwargs
956
+ )
957
+ return True, len(clean_txt.encode('utf-8'))
958
+
959
+ # ==================== सामान्य टेक्स्ट मैसेज (/clone) ====================
960
+ raw_caption = msg.caption.markdown if msg.caption else ""
961
+ final_caption = format_caption_text(raw_caption, task)
962
+
963
  if msg.text:
964
  text_to_send = format_caption_text(msg.text.markdown, task)
965
  await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
966
  return True, len(text_to_send.encode('utf-8'))
967
 
968
+ # ==================== मीडिया / इमेज / PDF / वीडियो हैंडलिंग ====================
969
+ upsc_caption_text = None
970
+ upsc_caption_entities = None
971
+ if is_upsc_mode and msg.caption:
972
+ upsc_caption_text, upsc_caption_entities = build_upsc_entities_and_text(
973
+ msg.caption, msg.caption_entities, task.get("upsc_link", DEFAULT_UPSC_LINK)
974
+ )
975
+
976
  file_name = get_file_name_from_msg(msg)
977
  user_down_dir = os.path.join("downloads", str(user_id))
978
  os.makedirs(user_down_dir, exist_ok=True)
 
980
 
981
  remaining = max(0, total_count - current_idx)
982
 
 
983
  file_path = None
984
  if os.path.exists(down_path) and os.path.getsize(down_path) > 1024:
985
  file_path = down_path
 
1042
  created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
1043
  thumb_to_use = created_temp_thumb
1044
 
1045
+ caption_args = (
1046
+ {"caption": upsc_caption_text, "caption_entities": upsc_caption_entities}
1047
+ if is_upsc_mode
1048
+ else {"caption": final_caption, "parse_mode": enums.ParseMode.MARKDOWN}
1049
+ )
1050
+
1051
  try:
1052
  if msg.photo:
1053
  await sender_client.send_photo(
1054
+ target_chat, file_path, **caption_args, **topic_kwargs
1055
  )
1056
  elif msg.video:
 
1057
  for up_retry in range(3):
1058
  try:
1059
  await sender_client.send_video(
1060
  target_chat,
1061
  video=file_path,
1062
  thumb=thumb_to_use,
 
 
1063
  duration=getattr(msg.video, "duration", 0) or 0,
1064
  width=getattr(msg.video, "width", 0) or 0,
1065
  height=getattr(msg.video, "height", 0) or 0,
1066
  progress=progress_bar,
1067
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1068
+ **caption_args,
1069
  **topic_kwargs
1070
  )
1071
  break
 
1080
  target_chat,
1081
  audio=file_path,
1082
  thumb=thumb_to_use,
 
 
1083
  duration=getattr(msg.audio, "duration", 0) or 0,
1084
  progress=progress_bar,
1085
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1086
+ **caption_args,
1087
  **topic_kwargs
1088
  )
1089
  else:
 
1093
  target_chat,
1094
  document=file_path,
1095
  thumb=thumb_to_use,
 
 
1096
  progress=progress_bar,
1097
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1098
+ **caption_args,
1099
  **topic_kwargs
1100
  )
1101
  break
 
1116
  print(f"Upload error on msg {msgid}: {e}")
1117
  return False, 0
1118
  finally:
 
1119
  if os.path.exists(file_path):
1120
  try:
1121
  os.remove(file_path)