Agnivesh10M commited on
Commit
e4dda13
·
verified ·
1 Parent(s): 4044ad3

Update TechVJ/start.py

Browse files
Files changed (1) hide show
  1. TechVJ/start.py +176 -83
TechVJ/start.py CHANGED
@@ -167,7 +167,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"):
@@ -240,19 +241,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 +264,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` लिखें।")
@@ -647,8 +648,8 @@ async def start_clone_task(client: Client, user_id: int):
647
  target_topic_id = task.get("target_topic_id")
648
 
649
  user_session = db.get_session(user_id)
650
- user_api_id = db.get_api_id(user_id)
651
- user_api_hash = db.get_api_hash(user_id)
652
 
653
  total_count = (end_id - start_id) + 1
654
  status_msg = await client.send_message(
@@ -673,9 +674,10 @@ async def start_clone_task(client: Client, user_id: int):
673
  return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर (कृपया दोबारा /login करें): `{e}`")
674
 
675
  batch_temp.IS_BATCH[user_id] = False
 
676
  success = 0
677
  not_found = 0
678
- retrying = 0
679
  total_bytes = 0
680
  start_time = time.time()
681
 
@@ -683,20 +685,27 @@ async def start_clone_task(client: Client, user_id: int):
683
  for msgid in range(start_id, end_id + 1):
684
  current_idx += 1
685
  if batch_temp.IS_BATCH.get(user_id):
 
686
  await status_msg.edit_text("🛑 **टास्क पूरी तरह रोक दिया गया है।**")
687
  break
688
 
689
  if not db.is_user_vip(user_id, ADMINS):
690
  batch_temp.IS_BATCH[user_id] = True
 
691
  await status_msg.edit_text("🚫 **आपका VIP एक्सेस समाप्त या हटा दिया गया है।**")
692
  break
693
 
694
- attempts = 0
695
- while attempts < 3:
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,
@@ -711,26 +720,61 @@ async def start_clone_task(client: Client, user_id: int):
711
  batch_temp.LAST_SAVED_ID[user_id] = msgid
712
  else:
713
  not_found += 1
 
714
  break
 
715
  except asyncio.CancelledError:
 
716
  break
 
717
  except FloodWait as fw:
718
- await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
719
- await asyncio.sleep(fw.value + 1)
720
- attempts += 1
721
- except asyncio.TimeoutError:
722
- attempts += 1
723
- await asyncio.sleep(2)
 
 
 
 
 
724
  except Exception as e:
725
- print(f"Error on msg {msgid}: {e}")
726
- retrying += 1
727
- break
 
 
 
 
 
 
728
 
729
- if batch_temp.IS_BATCH.get(user_id):
730
- await status_msg.edit_text("🛑 **टास्क पूरी तरह रोक दिया गया है।**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
731
  break
732
 
733
- await asyncio.sleep(WAITING_TIME)
 
734
 
735
  try:
736
  await acc.stop()
@@ -745,23 +789,34 @@ async def start_clone_task(client: Client, user_id: int):
745
  elapsed_time = max(1, int(time.time() - start_time))
746
  avg_speed = f"{humanbytes(total_bytes / elapsed_time)}/s"
747
 
748
- if not batch_temp.IS_BATCH.get(user_id, False):
749
  summary_card = (
750
  "🏁 **Transfer Finished**\n"
751
  "━━━━━━━━━━━━━━━━━━━━\n"
752
  f"📊 Total Messages: {total_count}\n"
753
  f"✅ Success: {success}\n"
754
  f"🗑️ Empty/Skipped: {not_found}\n"
755
- f"🔁 Retrying: {retrying}\n"
756
  f"📦 Total Size: {humanbytes(total_bytes)}\n"
757
  f"⚡ Avg Speed: {avg_speed}\n"
758
  f"⏱️ Time: {time_formatter(elapsed_time)}\n"
759
- "━━━━━━━━━━━━━━━━━━━━"
 
 
760
  )
761
  try:
762
- await status_msg.edit_text(summary_card)
 
 
 
 
763
  except Exception:
764
- pass
 
 
 
 
 
765
 
766
  def get_file_name_from_msg(msg: Message) -> str:
767
  name = None
@@ -777,6 +832,17 @@ def get_file_name_from_msg(msg: Message) -> str:
777
  name = f"audio_{msg.id}.mp3"
778
  elif msg.photo:
779
  name = f"photo_{msg.id}.jpg"
 
 
 
 
 
 
 
 
 
 
 
780
  else:
781
  name = f"file_{msg.id}.bin"
782
 
@@ -825,8 +891,8 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
825
  except Exception:
826
  try:
827
  msg = await asyncio.wait_for(client.get_messages(source_chat, msgid), timeout=25.0)
828
- except Exception:
829
- return False, 0
830
 
831
  if not msg or msg.empty or msg.service:
832
  return False, 0
@@ -844,6 +910,13 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
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,9 +924,8 @@ 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
858
  else:
859
  down_start = time.time()
@@ -864,7 +936,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
864
  )
865
 
866
  try:
867
- if msg.photo:
868
  file_path = await acc.download_media(msg, file_name=down_path)
869
  else:
870
  try:
@@ -896,7 +968,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
896
  raise asyncio.CancelledError()
897
 
898
  if not file_path or not os.path.exists(file_path):
899
- return False, 0
900
 
901
  size = os.path.getsize(file_path)
902
  up_start = time.time()
@@ -914,35 +986,26 @@ 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
940
- except FloodWait as f:
941
- await asyncio.sleep(f.value + 1)
942
- except Exception as ex:
943
- if up_retry == 2:
944
- raise ex
945
- await asyncio.sleep(3)
946
  elif msg.audio:
947
  await sender_client.send_audio(
948
  target_chat,
@@ -955,26 +1018,58 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
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:
959
- for up_retry in range(3):
960
- try:
961
- await sender_client.send_document(
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
972
- except FloodWait as f:
973
- await asyncio.sleep(f.value + 1)
974
- except Exception as ex:
975
- if up_retry == 2:
976
- raise ex
977
- await asyncio.sleep(3)
978
  except asyncio.CancelledError:
979
  if os.path.exists(file_path):
980
  try:
@@ -983,11 +1078,9 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
983
  pass
984
  raise asyncio.CancelledError()
985
  except Exception as e:
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)
993
  except Exception:
 
167
  is_vip = db.is_user_vip(user_id, ADMINS)
168
  user_data = db.get_user(user_id)
169
 
170
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
171
+ if user_id in adm_list:
172
  return await message.reply_text("👑 **आप बॉट के एडमिन हैं!** आपके पास आजीवन असीमित VIP एक्सेस है।")
173
 
174
  if is_vip and user_data and user_data.get("plan_expiry"):
 
241
  @Client.on_message(filters.command("users") & filters.private)
242
  async def users_admin_handler(client: Client, message: Message):
243
  user_id = message.from_user.id
244
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
245
+ if user_id not in adm_list:
246
  return
247
  users = db.get_all_users()
248
+ vip_count = sum(1 for u in users if u.get("plan_expiry"))
 
 
 
249
  await message.reply_text(f"📊 **बॉट आँकड़े (Admin Panel):**\n\n👥 कुल रजिस्टर्ड यूजर्स: `{len(users)}`\n💎 एक्टिव VIP यूजर्स: `{vip_count}`")
250
 
251
  @Client.on_message(filters.command("setprice") & filters.private)
252
  async def setprice_handler(client: Client, message: Message):
253
  user_id = message.from_user.id
254
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
255
+ if user_id not in adm_list:
256
  return
257
  args = message.text.split()
258
  if len(args) != 3:
 
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
+ adm_list = ADMINS if isinstance(ADMINS, list) else [ADMINS]
268
+ if user_id not in adm_list:
269
  return
270
  if not message.reply_to_message:
271
  return await message.reply_text("⚠️ कृपया जिस मैसेज को ब्रॉडकास्ट करना है, उसे रिप्लाई करते हुए `/broadcast` लिखें।")
 
648
  target_topic_id = task.get("target_topic_id")
649
 
650
  user_session = db.get_session(user_id)
651
+ user_api_id = int(db.get_api_id(user_id) or API_ID)
652
+ user_api_hash = db.get_api_hash(user_id) or API_HASH
653
 
654
  total_count = (end_id - start_id) + 1
655
  status_msg = await client.send_message(
 
674
  return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर (कृपया दोबारा /login करें): `{e}`")
675
 
676
  batch_temp.IS_BATCH[user_id] = False
677
+ was_cancelled = False
678
  success = 0
679
  not_found = 0
680
+ auto_retries_count = 0
681
  total_bytes = 0
682
  start_time = time.time()
683
 
 
685
  for msgid in range(start_id, end_id + 1):
686
  current_idx += 1
687
  if batch_temp.IS_BATCH.get(user_id):
688
+ was_cancelled = True
689
  await status_msg.edit_text("🛑 **टास्क पूरी तरह रोक दिया गया है।**")
690
  break
691
 
692
  if not db.is_user_vip(user_id, ADMINS):
693
  batch_temp.IS_BATCH[user_id] = True
694
+ was_cancelled = True
695
  await status_msg.edit_text("🚫 **आपका VIP एक्सेस समाप्त या हटा दिया गया है।**")
696
  break
697
 
698
+ # अनलिमिटेड 30-सेकंड ऑटो-रिज्यूम व ऑटो-रिट्राय लूप
699
+ while True:
700
  if batch_temp.IS_BATCH.get(user_id):
701
+ was_cancelled = True
702
+ break
703
+ if not db.is_user_vip(user_id, ADMINS):
704
+ batch_temp.IS_BATCH[user_id] = True
705
+ was_cancelled = True
706
  break
707
+
708
  try:
 
709
  ok, sz = await asyncio.wait_for(
710
  process_media(
711
  client, acc, user_id, source_chat, msgid,
 
720
  batch_temp.LAST_SAVED_ID[user_id] = msgid
721
  else:
722
  not_found += 1
723
+ batch_temp.LAST_SAVED_ID[user_id] = msgid
724
  break
725
+
726
  except asyncio.CancelledError:
727
+ was_cancelled = True
728
  break
729
+
730
  except FloodWait as fw:
731
+ wait_sec = max(30, fw.value + 2)
732
+ auto_retries_count += 1
733
+ try:
734
+ await status_msg.edit_text(
735
+ f"⏳ **टेलीग्राम Rate-Limit (ID `{msgid}`):**\n"
736
+ f"🔄 `{wait_sec}` सेकंड बाद अपने आप ऑटो-रिज्यूम होगा..."
737
+ )
738
+ except Exception:
739
+ pass
740
+ await asyncio.sleep(wait_sec)
741
+
742
  except Exception as e:
743
+ auto_retries_count += 1
744
+ print(f"Auto-retry on msg {msgid}: {e}")
745
+ try:
746
+ await status_msg.edit_text(
747
+ f"⚠️ **ट्रांसफर रुका (ID `{msgid}`):** `{str(e)[:60]}`\n"
748
+ f"🔄 **30 सेकंड में ऑटो-रिज्यूम हो रहा है...** (प्रयास #{auto_retries_count})"
749
+ )
750
+ except Exception:
751
+ pass
752
 
753
+ for _ in range(30):
754
+ if batch_temp.IS_BATCH.get(user_id):
755
+ was_cancelled = True
756
+ break
757
+ await asyncio.sleep(1)
758
+
759
+ if was_cancelled:
760
+ break
761
+
762
+ try:
763
+ if not acc.is_connected:
764
+ await acc.start()
765
+ except Exception:
766
+ pass
767
+
768
+ if batch_temp.IS_BATCH.get(user_id) or was_cancelled:
769
+ was_cancelled = True
770
+ try:
771
+ await status_msg.edit_text("🛑 **टास्क पूरी तरह रोक दिया गया है।**")
772
+ except Exception:
773
+ pass
774
  break
775
 
776
+ if current_idx < total_count:
777
+ await asyncio.sleep(WAITING_TIME)
778
 
779
  try:
780
  await acc.stop()
 
789
  elapsed_time = max(1, int(time.time() - start_time))
790
  avg_speed = f"{humanbytes(total_bytes / elapsed_time)}/s"
791
 
792
+ if not was_cancelled:
793
  summary_card = (
794
  "🏁 **Transfer Finished**\n"
795
  "━━━━━━━━━━━━━━━━━━━━\n"
796
  f"📊 Total Messages: {total_count}\n"
797
  f"✅ Success: {success}\n"
798
  f"🗑️ Empty/Skipped: {not_found}\n"
799
+ f"🔄 Auto-Retries: {auto_retries_count}\n"
800
  f"📦 Total Size: {humanbytes(total_bytes)}\n"
801
  f"⚡ Avg Speed: {avg_speed}\n"
802
  f"⏱️ Time: {time_formatter(elapsed_time)}\n"
803
+ "━━━━━━━━━━━━━━━━━━━━\n"
804
+ "👤 **Developer:** [**𝚾 𝚫 𝚬 𝚸 · ༎🥀**](https://t.me/Avigat1210)\n"
805
+ "🔗 **Telegram:** [**@Avigat1210**](https://t.me/Avigat1210)"
806
  )
807
  try:
808
+ await status_msg.edit_text(
809
+ summary_card,
810
+ parse_mode=enums.ParseMode.MARKDOWN,
811
+ disable_web_page_preview=True
812
+ )
813
  except Exception:
814
+ await client.send_message(
815
+ user_id,
816
+ summary_card,
817
+ parse_mode=enums.ParseMode.MARKDOWN,
818
+ disable_web_page_preview=True
819
+ )
820
 
821
  def get_file_name_from_msg(msg: Message) -> str:
822
  name = None
 
832
  name = f"audio_{msg.id}.mp3"
833
  elif msg.photo:
834
  name = f"photo_{msg.id}.jpg"
835
+ elif msg.voice:
836
+ name = f"voice_{msg.id}.ogg"
837
+ elif msg.video_note:
838
+ name = f"videonote_{msg.id}.mp4"
839
+ elif msg.animation and msg.animation.file_name:
840
+ name = msg.animation.file_name
841
+ elif msg.animation:
842
+ name = f"animation_{msg.id}.mp4"
843
+ elif msg.sticker:
844
+ ext = "tgs" if msg.sticker.is_animated else ("webm" if msg.sticker.is_video else "webp")
845
+ name = f"sticker_{msg.id}.{ext}"
846
  else:
847
  name = f"file_{msg.id}.bin"
848
 
 
891
  except Exception:
892
  try:
893
  msg = await asyncio.wait_for(client.get_messages(source_chat, msgid), timeout=25.0)
894
+ except Exception as e:
895
+ raise e
896
 
897
  if not msg or msg.empty or msg.service:
898
  return False, 0
 
910
  await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
911
  return True, len(text_to_send.encode('utf-8'))
912
 
913
+ has_media = any([
914
+ msg.photo, msg.video, msg.document, msg.audio,
915
+ msg.voice, msg.video_note, msg.animation, msg.sticker
916
+ ])
917
+ if not has_media:
918
+ return False, 0
919
+
920
  file_name = get_file_name_from_msg(msg)
921
  user_down_dir = os.path.join("downloads", str(user_id))
922
  os.makedirs(user_down_dir, exist_ok=True)
 
924
 
925
  remaining = max(0, total_count - current_idx)
926
 
 
927
  file_path = None
928
+ if os.path.exists(down_path) and os.path.getsize(down_path) > 512:
929
  file_path = down_path
930
  else:
931
  down_start = time.time()
 
936
  )
937
 
938
  try:
939
+ if msg.photo or msg.sticker or msg.voice or msg.video_note:
940
  file_path = await acc.download_media(msg, file_name=down_path)
941
  else:
942
  try:
 
968
  raise asyncio.CancelledError()
969
 
970
  if not file_path or not os.path.exists(file_path):
971
+ raise RuntimeError(f"Download incomplete for message {msgid}")
972
 
973
  size = os.path.getsize(file_path)
974
  up_start = time.time()
 
986
  created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
987
  thumb_to_use = created_temp_thumb
988
 
989
+ upload_succeeded = False
990
  try:
991
  if msg.photo:
992
  await sender_client.send_photo(
993
  target_chat, file_path, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs
994
  )
995
  elif msg.video:
996
+ await sender_client.send_video(
997
+ target_chat,
998
+ video=file_path,
999
+ thumb=thumb_to_use,
1000
+ caption=final_caption,
1001
+ parse_mode=enums.ParseMode.MARKDOWN,
1002
+ duration=getattr(msg.video, "duration", 0) or 0,
1003
+ width=getattr(msg.video, "width", 0) or 0,
1004
+ height=getattr(msg.video, "height", 0) or 0,
1005
+ progress=progress_bar,
1006
+ progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1007
+ **topic_kwargs
1008
+ )
 
 
 
 
 
 
 
 
 
 
1009
  elif msg.audio:
1010
  await sender_client.send_audio(
1011
  target_chat,
 
1018
  progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1019
  **topic_kwargs
1020
  )
1021
+ elif msg.voice:
1022
+ await sender_client.send_voice(
1023
+ target_chat,
1024
+ voice=file_path,
1025
+ caption=final_caption,
1026
+ parse_mode=enums.ParseMode.MARKDOWN,
1027
+ duration=getattr(msg.voice, "duration", 0) or 0,
1028
+ **topic_kwargs
1029
+ )
1030
+ elif msg.video_note:
1031
+ await sender_client.send_video_note(
1032
+ target_chat,
1033
+ video_note=file_path,
1034
+ duration=getattr(msg.video_note, "duration", 0) or 0,
1035
+ length=getattr(msg.video_note, "length", 0) or 0,
1036
+ **topic_kwargs
1037
+ )
1038
+ elif msg.animation:
1039
+ await sender_client.send_animation(
1040
+ target_chat,
1041
+ animation=file_path,
1042
+ thumb=thumb_to_use,
1043
+ caption=final_caption,
1044
+ parse_mode=enums.ParseMode.MARKDOWN,
1045
+ duration=getattr(msg.animation, "duration", 0) or 0,
1046
+ width=getattr(msg.animation, "width", 0) or 0,
1047
+ height=getattr(msg.animation, "height", 0) or 0,
1048
+ progress=progress_bar,
1049
+ progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1050
+ **topic_kwargs
1051
+ )
1052
+ elif msg.sticker:
1053
+ await sender_client.send_sticker(
1054
+ target_chat,
1055
+ sticker=file_path,
1056
+ **topic_kwargs
1057
+ )
1058
  else:
1059
+ await sender_client.send_document(
1060
+ target_chat,
1061
+ document=file_path,
1062
+ file_name=file_name,
1063
+ thumb=thumb_to_use,
1064
+ caption=final_caption,
1065
+ parse_mode=enums.ParseMode.MARKDOWN,
1066
+ progress=progress_bar,
1067
+ progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count, user_id),
1068
+ **topic_kwargs
1069
+ )
1070
+
1071
+ upload_succeeded = True
1072
+
 
 
 
 
 
1073
  except asyncio.CancelledError:
1074
  if os.path.exists(file_path):
1075
  try:
 
1078
  pass
1079
  raise asyncio.CancelledError()
1080
  except Exception as e:
1081
+ raise e
 
1082
  finally:
1083
+ if upload_succeeded and os.path.exists(file_path):
 
1084
  try:
1085
  os.remove(file_path)
1086
  except Exception: