Agnivesh10M commited on
Commit
097a907
·
verified ·
1 Parent(s): f32a467

Update TechVJ/start.py

Browse files
Files changed (1) hide show
  1. TechVJ/start.py +111 -46
TechVJ/start.py CHANGED
@@ -45,7 +45,6 @@ def time_formatter(seconds: int) -> str:
45
  return tmp if tmp else "0s"
46
 
47
  async def progress_bar(current, total, ud_type, message, start, fname="", current_idx=1, total_count=1, user_id=None):
48
- # यदि यूजर ने /cancel दबा दिया है तो तुरंत यहीं प्रोसेस को टर्मिनेट कर दो
49
  if user_id and batch_temp.IS_BATCH.get(user_id):
50
  raise asyncio.CancelledError("Task cancelled by user.")
51
 
@@ -91,6 +90,20 @@ def generate_auto_thumb(video_path: str, thumb_path: str):
91
  pass
92
  return None
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  @Client.on_message(filters.command("id"))
95
  async def get_id(client: Client, message: Message):
96
  chat_id = message.chat.id
@@ -149,18 +162,20 @@ def parse_telegram_link(link: str):
149
  async def resume_command(client: Client, message: Message):
150
  user_id = message.from_user.id
151
  if not db.is_user_vip(user_id, ADMINS):
152
- return await message.reply_text("🔒 आपका VIP एक्सेस समाप्त हो चुका है।")
153
 
154
  task = batch_temp.CLONE_DATA.get(user_id)
155
  last_id = batch_temp.LAST_SAVED_ID.get(user_id)
156
- if not task or not last_id:
157
  return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला। नया टास्क शुरू करने के लिए `/clone` करें।")
158
 
159
  if last_id >= task["end_id"]:
160
  return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
161
 
 
162
  task["start_id"] = last_id + 1
163
- await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक)")
 
164
  await start_clone_task(client, user_id)
165
 
166
  @Client.on_message(filters.command(["clone", "clon"]) & filters.private)
@@ -175,7 +190,7 @@ async def clone_command(client: Client, message: Message):
175
 
176
  user_session = db.get_session(user_id)
177
  if not user_session:
178
- return await message.reply_text("🔑 पहले **/login** करें।")
179
 
180
  guide_text = (
181
  "📖 **कंटेंट क्लोनिंग निर्देश:**\n"
@@ -239,8 +254,12 @@ async def clone_command(client: Client, message: Message):
239
  "extra_caption": None,
240
  "replace_find": None,
241
  "replace_with": None,
 
 
 
242
  "thumb_path": None
243
  }
 
244
  return await show_customization_menu(client, user_id)
245
 
246
  if ":" in dest_val:
@@ -267,10 +286,13 @@ async def clone_command(client: Client, message: Message):
267
  "extra_caption": None,
268
  "replace_find": None,
269
  "replace_with": None,
 
 
 
270
  "thumb_path": None
271
  }
 
272
 
273
- # टॉपिक ग्रुप प्रश्न बटन (Yes / No)
274
  topic_markup = InlineKeyboardMarkup([
275
  [
276
  InlineKeyboardButton("✅ हाँ (Yes)", callback_data="ask_topic_yes"),
@@ -285,10 +307,14 @@ async def clone_command(client: Client, message: Message):
285
 
286
  async def show_customization_menu(client: Client, user_id: int):
287
  data = batch_temp.CLONE_DATA.get(user_id, {})
288
- cap_status = "सेट है ✅" if data.get("custom_caption") else "डिफ़ॉल्ट"
289
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
290
  thm_status = "सेट है ✅" if data.get("thumb_path") else "डिफ़ॉल्ट"
 
 
291
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
 
 
292
  dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
293
  if data.get("target_topic_id"):
294
  dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
@@ -300,16 +326,20 @@ async def show_customization_menu(client: Client, user_id: int):
300
  "━━━━━━━━━━━━━━━━━━━━\n"
301
  f"📝 नया कैप्शन: `{cap_status}`\n"
302
  f"🔄 रिप्लेस: {rep_status}\n"
 
 
303
  f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
304
  f"🖼️ थंबनेल: `{thm_status}`\n"
305
  f"🎯 टारगेट: {dest_display}\n"
306
  f"📊 रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_msgs} मैसेज)\n"
307
  "━━━━━━━━━━━━━━━━━━━━\n"
308
- "एडिट करें या तुरंत ट्रांसफर के लिए **🚀 Confirm & Start** दबाएँ:"
309
  )
310
  buttons = InlineKeyboardMarkup([
311
  [InlineKeyboardButton("📝 Edit Full Caption", callback_data="set_caption"),
312
  InlineKeyboardButton("🔄 Replace in Caption", callback_data="set_replace")],
 
 
313
  [InlineKeyboardButton("➕ Add Extra Caption", callback_data="set_extra"),
314
  InlineKeyboardButton("🖼️ Set Thumbnail", callback_data="set_thumb")],
315
  [InlineKeyboardButton("🗑️ Clear Settings", callback_data="clear_settings"),
@@ -355,7 +385,7 @@ async def callback_handler(client: Client, query: CallbackQuery):
355
 
356
  elif data == "set_replace":
357
  await query.message.delete()
358
- find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? वह शब्द भेजें:", filters=filters.text, timeout=180)
359
  if find_msg.text == "/cancel":
360
  return await show_customization_menu(client, user_id)
361
  with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना चाहते हैं? (हटाने/खाली रखने के लिए `/empty`):", filters=filters.text, timeout=180)
@@ -365,9 +395,28 @@ async def callback_handler(client: Client, query: CallbackQuery):
365
  batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
366
  await show_customization_menu(client, user_id)
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  elif data == "set_extra":
369
  await query.message.delete()
370
- msg = await client.ask(user_id, "✍️ **अतिरिक्त कैप्शन भेजें** (हाइपरलिंक्स मान्य हैं):", filters=filters.text, timeout=180)
371
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = msg.text.markdown
372
  await show_customization_menu(client, user_id)
373
 
@@ -387,6 +436,9 @@ async def callback_handler(client: Client, query: CallbackQuery):
387
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
388
  batch_temp.CLONE_DATA[user_id]["replace_find"] = None
389
  batch_temp.CLONE_DATA[user_id]["replace_with"] = None
 
 
 
390
  tpath = batch_temp.CLONE_DATA[user_id].get("thumb_path")
391
  if tpath and os.path.exists(tpath):
392
  os.remove(tpath)
@@ -432,10 +484,10 @@ async def start_clone_task(client: Client, user_id: int):
432
  try:
433
  await acc.start()
434
  except Exception as e:
435
- return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर: `{e}`")
436
 
437
  try:
438
- async for dialog in acc.get_dialogs(limit=20):
439
  pass
440
  except Exception:
441
  pass
@@ -470,7 +522,7 @@ async def start_clone_task(client: Client, user_id: int):
470
  target_chat, target_topic_id, task, status_msg,
471
  current_idx, total_count
472
  ),
473
- timeout=300.0
474
  )
475
  if ok:
476
  success += 1
@@ -480,19 +532,15 @@ async def start_clone_task(client: Client, user_id: int):
480
  not_found += 1
481
  break
482
  except asyncio.CancelledError:
483
- # कैंसल होते ही तुरंत लूप से बाहर आ जाओ
484
- print(f"User {user_id} cancelled the task.")
485
  break
486
  except FloodWait as fw:
487
  await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
488
  await asyncio.sleep(fw.value + 1)
489
  attempts += 1
490
  except asyncio.TimeoutError:
491
- print(f"Timeout on msg {msgid}, retrying...")
492
  attempts += 1
493
  await asyncio.sleep(2)
494
- except Exception as e:
495
- print(f"General error on {msgid}: {e}")
496
  retrying += 1
497
  break
498
 
@@ -553,54 +601,70 @@ def get_file_name_from_msg(msg: Message) -> str:
553
  clean_name = re.sub(r"^\d+_", "", name)
554
  return clean_name if clean_name else name
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  async def process_media(client: Client, acc: Client, user_id: int, source_chat, msgid: int, target_chat, target_topic_id, task: dict, status_msg: Message, current_idx: int, total_count: int):
557
  if batch_temp.IS_BATCH.get(user_id):
558
  raise asyncio.CancelledError()
559
 
560
  msg = None
561
  try:
562
- msg = await asyncio.wait_for(acc.get_messages(source_chat, msgid), timeout=15.0)
563
  except Exception:
564
  try:
565
- msg = await asyncio.wait_for(client.get_messages(source_chat, msgid), timeout=15.0)
566
  except Exception:
567
  return False, 0
568
 
569
  if not msg or msg.empty or msg.service:
570
  return False, 0
571
 
572
- final_caption = (msg.caption.markdown if msg.caption else "")
573
-
574
- if task.get("custom_caption"):
575
- final_caption = task["custom_caption"]
576
- elif task.get("replace_find"):
577
- find_w = task["replace_find"]
578
- with_w = task.get("replace_with") or ""
579
- if final_caption:
580
- final_caption = final_caption.replace(find_w, with_w)
581
-
582
- if task.get("extra_caption"):
583
- if final_caption:
584
- final_caption = f"{final_caption}\n\n{task['extra_caption']}"
585
- else:
586
- final_caption = task["extra_caption"]
587
 
588
  is_direct_bot = task.get("is_direct_bot", False)
589
  sender_client = client if is_direct_bot else acc
590
-
591
  topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
592
 
593
  # सादा टेक्स्ट मैसेज
594
  if msg.text:
595
- text_to_send = msg.text.markdown
596
- if task.get("custom_caption"):
597
- text_to_send = task["custom_caption"]
598
- elif task.get("replace_find"):
599
- find_w = task["replace_find"]
600
- with_w = task.get("replace_with") or ""
601
- text_to_send = text_to_send.replace(find_w, with_w)
602
- if task.get("extra_caption"):
603
- text_to_send += f"\n\n{task['extra_caption']}"
604
  await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
605
  return True, len(text_to_send.encode('utf-8'))
606
 
@@ -701,6 +765,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
701
  **topic_kwargs
702
  )
703
  else:
 
704
  await sender_client.send_document(
705
  target_chat,
706
  document=file_path,
@@ -719,7 +784,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
719
  pass
720
  raise asyncio.CancelledError()
721
  except Exception as e:
722
- print(f"Direct Upload error on {msgid}: {e}")
723
  return False, 0
724
  finally:
725
  if os.path.exists(file_path):
 
45
  return tmp if tmp else "0s"
46
 
47
  async def progress_bar(current, total, ud_type, message, start, fname="", current_idx=1, total_count=1, user_id=None):
 
48
  if user_id and batch_temp.IS_BATCH.get(user_id):
49
  raise asyncio.CancelledError("Task cancelled by user.")
50
 
 
90
  pass
91
  return None
92
 
93
+ def strip_all_urls(text: str) -> str:
94
+ """कैप्शन से सभी प्रकार की लिंक्स और मार्कडाउन हाइपरलिंक को पूरी तरह साफ़ करना"""
95
+ if not text:
96
+ return ""
97
+ # 1. मार्कडाउन हाइपरलिंक [Text](http://link) से सिर्फ टेक्स्ट बचाना
98
+ text = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+|t\.me/[^\)]+)\)', r'\1', text)
99
+ # 2. सादी http, https और www लिंक्स हटाना
100
+ text = re.sub(r'https?://\S+|www\.\S+', '', text)
101
+ # 3. t.me/ लिंक्स हटाना
102
+ text = re.sub(r't\.me/\S+', '', text)
103
+ # 4. लगातार खाली स्पेस को साफ़ करना
104
+ text = re.sub(r'\n{3,}', '\n\n', text).strip()
105
+ return text
106
+
107
  @Client.on_message(filters.command("id"))
108
  async def get_id(client: Client, message: Message):
109
  chat_id = message.chat.id
 
162
  async def resume_command(client: Client, message: Message):
163
  user_id = message.from_user.id
164
  if not db.is_user_vip(user_id, ADMINS):
165
+ return await message.reply_text("🔒 आपका VIP एक्सेस सक्रिय नहीं है।")
166
 
167
  task = batch_temp.CLONE_DATA.get(user_id)
168
  last_id = batch_temp.LAST_SAVED_ID.get(user_id)
169
+ if not task or last_id is None:
170
  return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला। नया टास्क शुरू करने के लिए `/clone` करें।")
171
 
172
  if last_id >= task["end_id"]:
173
  return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
174
 
175
+ # सुरक्षित रेज़्यूम: केवल वही मैसेज चलेंगे जो बचे हैं
176
  task["start_id"] = last_id + 1
177
+ total_remaining = (task["end_id"] - task["start_id"]) + 1
178
+ await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक, शेष: {total_remaining})")
179
  await start_clone_task(client, user_id)
180
 
181
  @Client.on_message(filters.command(["clone", "clon"]) & filters.private)
 
190
 
191
  user_session = db.get_session(user_id)
192
  if not user_session:
193
+ return await message.reply_text("🔑 पहले **/login** करें ताकि आपके अकाउंट से लिंक्स प्रोसेस हो सकें।")
194
 
195
  guide_text = (
196
  "📖 **कंटेंट क्लोनिंग निर्देश:**\n"
 
254
  "extra_caption": None,
255
  "replace_find": None,
256
  "replace_with": None,
257
+ "strip_links": False,
258
+ "hyperlink_word": None,
259
+ "hyperlink_url": None,
260
  "thumb_path": None
261
  }
262
+ batch_temp.LAST_SAVED_ID[user_id] = min(s_id, e_id) - 1
263
  return await show_customization_menu(client, user_id)
264
 
265
  if ":" in dest_val:
 
286
  "extra_caption": None,
287
  "replace_find": None,
288
  "replace_with": None,
289
+ "strip_links": False,
290
+ "hyperlink_word": None,
291
+ "hyperlink_url": None,
292
  "thumb_path": None
293
  }
294
+ batch_temp.LAST_SAVED_ID[user_id] = min(s_id, e_id) - 1
295
 
 
296
  topic_markup = InlineKeyboardMarkup([
297
  [
298
  InlineKeyboardButton("✅ हाँ (Yes)", callback_data="ask_topic_yes"),
 
307
 
308
  async def show_customization_menu(client: Client, user_id: int):
309
  data = batch_temp.CLONE_DATA.get(user_id, {})
310
+ cap_status = "कस्टम सेट है ✅" if data.get("custom_caption") else "ओरिजिनल"
311
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
312
  thm_status = "सेट है ✅" if data.get("thumb_path") else "डिफ़ॉल्ट"
313
+ strip_status = "हटाएँगे 🗑️" if data.get("strip_links") else "सुरक्षित रखेंगे"
314
+
315
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
316
+ link_attach_status = f"[{data.get('hyperlink_word')}]({data.get('hyperlink_url')})" if data.get("hyperlink_word") else "कोई नहीं"
317
+
318
  dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
319
  if data.get("target_topic_id"):
320
  dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
 
326
  "━━━━━━━━━━━━━━━━━━━━\n"
327
  f"📝 नया कैप्शन: `{cap_status}`\n"
328
  f"🔄 रिप्लेस: {rep_status}\n"
329
+ f"🚫 लिंक्स हटाना: `{strip_status}`\n"
330
+ f"📎 हाइपरलिंक जोड़ना: {link_attach_status}\n"
331
  f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
332
  f"🖼️ थंबनेल: `{thm_status}`\n"
333
  f"🎯 टारगेट: {dest_display}\n"
334
  f"📊 रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_msgs} मैसेज)\n"
335
  "━━━━━━━━━━━━━━━━━━━━\n"
336
+ "कस्टमाइज़ करें या तुरंत प्रोसेस के लिए **🚀 Confirm & Start** दबाएँ:"
337
  )
338
  buttons = InlineKeyboardMarkup([
339
  [InlineKeyboardButton("📝 Edit Full Caption", callback_data="set_caption"),
340
  InlineKeyboardButton("🔄 Replace in Caption", callback_data="set_replace")],
341
+ [InlineKeyboardButton("🚫 Remove All Links", callback_data="toggle_strip_links"),
342
+ InlineKeyboardButton("📎 Attach Hyperlink", callback_data="set_hyperlink")],
343
  [InlineKeyboardButton("➕ Add Extra Caption", callback_data="set_extra"),
344
  InlineKeyboardButton("🖼️ Set Thumbnail", callback_data="set_thumb")],
345
  [InlineKeyboardButton("🗑️ Clear Settings", callback_data="clear_settings"),
 
385
 
386
  elif data == "set_replace":
387
  await query.message.delete()
388
+ find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? वह शब्द/टेक्स्ट भेजें:", filters=filters.text, timeout=180)
389
  if find_msg.text == "/cancel":
390
  return await show_customization_menu(client, user_id)
391
  with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना चाहते हैं? (हटाने/खाली रखने के लिए `/empty`):", filters=filters.text, timeout=180)
 
395
  batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
396
  await show_customization_menu(client, user_id)
397
 
398
+ elif data == "toggle_strip_links":
399
+ curr = batch_temp.CLONE_DATA[user_id].get("strip_links", False)
400
+ batch_temp.CLONE_DATA[user_id]["strip_links"] = not curr
401
+ await query.answer("लिंक हटाने का विकल्प अपडेट हुआ!")
402
+ await query.message.delete()
403
+ await show_customization_menu(client, user_id)
404
+
405
+ elif data == "set_hyperlink":
406
+ await query.message.delete()
407
+ w_msg = await client.ask(user_id, "✍️ कैप्शन के किस **शब्द (Word/Text)** पर लिंक लगानी है?", filters=filters.text, timeout=180)
408
+ if w_msg.text == "/cancel":
409
+ return await show_customization_menu(client, user_id)
410
+ u_msg = await client.ask(user_id, f"🔗 `{w_msg.text}` के लिए **URL (वेबसाइट/चैनल लिंक)** भेजें:", filters=filters.text, timeout=180)
411
+ if u_msg.text == "/cancel":
412
+ return await show_customization_menu(client, user_id)
413
+ batch_temp.CLONE_DATA[user_id]["hyperlink_word"] = w_msg.text.strip()
414
+ batch_temp.CLONE_DATA[user_id]["hyperlink_url"] = u_msg.text.strip()
415
+ await show_customization_menu(client, user_id)
416
+
417
  elif data == "set_extra":
418
  await query.message.delete()
419
+ msg = await client.ask(user_id, "✍️ **अतिरिक्त कैप्शन भेजें** (हाइपरलिंक मान्य हैं):", filters=filters.text, timeout=180)
420
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = msg.text.markdown
421
  await show_customization_menu(client, user_id)
422
 
 
436
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
437
  batch_temp.CLONE_DATA[user_id]["replace_find"] = None
438
  batch_temp.CLONE_DATA[user_id]["replace_with"] = None
439
+ batch_temp.CLONE_DATA[user_id]["strip_links"] = False
440
+ batch_temp.CLONE_DATA[user_id]["hyperlink_word"] = None
441
+ batch_temp.CLONE_DATA[user_id]["hyperlink_url"] = None
442
  tpath = batch_temp.CLONE_DATA[user_id].get("thumb_path")
443
  if tpath and os.path.exists(tpath):
444
  os.remove(tpath)
 
484
  try:
485
  await acc.start()
486
  except Exception as e:
487
+ return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर (कृपया दोबारा /login करें): `{e}`")
488
 
489
  try:
490
+ async for dialog in acc.get_dialogs(limit=10):
491
  pass
492
  except Exception:
493
  pass
 
522
  target_chat, target_topic_id, task, status_msg,
523
  current_idx, total_count
524
  ),
525
+ timeout=360.0
526
  )
527
  if ok:
528
  success += 1
 
532
  not_found += 1
533
  break
534
  except asyncio.CancelledError:
 
 
535
  break
536
  except FloodWait as fw:
537
  await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
538
  await asyncio.sleep(fw.value + 1)
539
  attempts += 1
540
  except asyncio.TimeoutError:
 
541
  attempts += 1
542
  await asyncio.sleep(2)
543
+ except Exception:
 
544
  retrying += 1
545
  break
546
 
 
601
  clean_name = re.sub(r"^\d+_", "", name)
602
  return clean_name if clean_name else name
603
 
604
+ def format_caption_text(raw_text: str, task: dict) -> str:
605
+ """कैप्शन पर रिप्लेसमेंट, लिंक रिमूवल, और हाइपरलिंक नियम लागू करना"""
606
+ if not raw_text:
607
+ raw_text = ""
608
+
609
+ final_text = raw_text
610
+
611
+ # 1. कस्टम कैप्शन ओवरराइड
612
+ if task.get("custom_caption"):
613
+ final_text = task["custom_caption"]
614
+ else:
615
+ # 2. सभी लिंक्स हटाना
616
+ if task.get("strip_links"):
617
+ final_text = strip_all_urls(final_text)
618
+
619
+ # 3. टेक्स्ट/शब्द रिप्लेस करना
620
+ if task.get("replace_find"):
621
+ find_w = task["replace_find"]
622
+ with_w = task.get("replace_with") or ""
623
+ if find_w in final_text:
624
+ final_text = final_text.replace(find_w, with_w)
625
+
626
+ # 4. हाइपरलिंक जोड़ना [Word](URL)
627
+ if task.get("hyperlink_word") and task.get("hyperlink_url"):
628
+ target_word = task["hyperlink_word"]
629
+ target_url = task["hyperlink_url"]
630
+ if target_word in final_text:
631
+ final_text = final_text.replace(target_word, f"[{target_word}]({target_url})", 1)
632
+
633
+ # 5. अतिरिक्त कैप्शन जोड़ना
634
+ if task.get("extra_caption"):
635
+ if final_text.strip():
636
+ final_text = f"{final_text}\n\n{task['extra_caption']}"
637
+ else:
638
+ final_text = task["extra_caption"]
639
+
640
+ return final_text
641
+
642
  async def process_media(client: Client, acc: Client, user_id: int, source_chat, msgid: int, target_chat, target_topic_id, task: dict, status_msg: Message, current_idx: int, total_count: int):
643
  if batch_temp.IS_BATCH.get(user_id):
644
  raise asyncio.CancelledError()
645
 
646
  msg = None
647
  try:
648
+ msg = await asyncio.wait_for(acc.get_messages(source_chat, msgid), timeout=20.0)
649
  except Exception:
650
  try:
651
+ msg = await asyncio.wait_for(client.get_messages(source_chat, msgid), timeout=20.0)
652
  except Exception:
653
  return False, 0
654
 
655
  if not msg or msg.empty or msg.service:
656
  return False, 0
657
 
658
+ raw_caption = msg.caption.markdown if msg.caption else ""
659
+ final_caption = format_caption_text(raw_caption, task)
 
 
 
 
 
 
 
 
 
 
 
 
 
660
 
661
  is_direct_bot = task.get("is_direct_bot", False)
662
  sender_client = client if is_direct_bot else acc
 
663
  topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
664
 
665
  # सादा टेक्स्ट मैसेज
666
  if msg.text:
667
+ text_to_send = format_caption_text(msg.text.markdown, task)
 
 
 
 
 
 
 
 
668
  await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
669
  return True, len(text_to_send.encode('utf-8'))
670
 
 
765
  **topic_kwargs
766
  )
767
  else:
768
+ # HTML, PDF, Zip, Docs और अन्य सभी प्रकार की फाइल्स
769
  await sender_client.send_document(
770
  target_chat,
771
  document=file_path,
 
784
  pass
785
  raise asyncio.CancelledError()
786
  except Exception as e:
787
+ print(f"Upload error on msg {msgid}: {e}")
788
  return False, 0
789
  finally:
790
  if os.path.exists(file_path):