Skip to content

Commit

Permalink
filee in dm, leech caption and minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 5, 2025
1 parent 8d1e783 commit 24e66db
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 81 deletions.
1 change: 1 addition & 0 deletions bot/core/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Config:
DELETE_LINKS = False
FSUB_IDS = ""
LOG_CHAT_ID = 0
LEECH_FILENAME_CAPTION = ""

@classmethod
def get(cls, key):
Expand Down
2 changes: 1 addition & 1 deletion bot/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async def update_variables():

if await aiopath.exists("list_drives.txt"):
async with aiopen("list_drives.txt", "r+") as f:
lines = f.readlines()
lines = await f.readlines()
for line in lines:
temp = line.strip().split()
drives_ids.append(temp[1])
Expand Down
38 changes: 37 additions & 1 deletion bot/helper/mirror_leech_utils/telegram_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
InputMediaPhoto,
InputMediaVideo,
)
from bot.helper.aeon_utils.caption_gen import generate_caption
from tenacity import (
RetryError,
retry,
Expand Down Expand Up @@ -56,6 +57,7 @@ def __init__(self, listener, path):
self._last_uploaded = 0
self._processed_bytes = 0
self._listener = listener
self._user_id = listener.user_id
self._path = path
self._start_time = time()
self._total_files = 0
Expand All @@ -67,6 +69,7 @@ def __init__(self, listener, path):
self._last_msg_in_group = False
self._up_path = ""
self._lprefix = ""
self._lcaption = ""
self._media_group = False
self._is_private = False
self._sent_msg = None
Expand Down Expand Up @@ -94,6 +97,11 @@ async def _user_settings(self):
if "lprefix" not in self._listener.user_dict
else ""
)
self._lcaption = self._listener.user_dict.get("lcaption") or (
Config.LEECH_FILENAME_CAPTION
if "lcaption" not in self._listener.user_dict
else ""
)
if self._thumb != "none" and not await aiopath.exists(self._thumb):
self._thumb = None

Expand Down Expand Up @@ -142,8 +150,11 @@ async def _msg_to_reply(self):
return True

async def _prepare_file(self, file_, dirpath, delete_file):
if self._lcaption:
cap_mono = await generate_caption(file_, dirpath, self._lcaption)
if self._lprefix:
cap_mono = f"{self._lprefix} <code>{file_}</code>"
if not self._lcaption:
cap_mono = f"{self._lprefix} <code>{file_}</code>"
self._lprefix = re_sub("<.*?>", "", self._lprefix)
if (
self._listener.seed
Expand Down Expand Up @@ -503,6 +514,8 @@ async def _upload_file(self, cap_mono, file, o_path, force_document=False):
progress=self._upload_progress,
)

await _copy_message()

if (
not self._listener.is_cancelled
and self._media_group
Expand Down Expand Up @@ -555,6 +568,29 @@ async def _upload_file(self, cap_mono, file, o_path, force_document=False):
return await self._upload_file(cap_mono, file, o_path, True)
raise err

async def _copy_message(self):
await sleep(1)

async def _copy(target, retries=3):
for attempt in range(retries):
try:
msg = await bot.get_messages(
self._sent_msg.chat.id, self._sent_msg.id
)
await msg.copy(target)
return
except Exception as e:
LOGGER.error(f"Attempt {attempt + 1} failed: {e} {msg.id}")
if attempt < retries - 1:
await sleep(0.5)
LOGGER.error(f"Failed to copy message after {retries} attempts")

# if self.dm_mode:
await _copy(self._user_id)

# if self._user_dump:
# await _copy(self._user_dump)

@property
def speed(self):
try:
Expand Down
5 changes: 3 additions & 2 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ async def new_event(self):
file_ = None

if (
self.link and (is_magnet(self.link) or self.link.endswith(".torrent"))
) or (file_ and getattr(file_, "file_name", "").endswith(".torrent")):
self.link
and (is_magnet(self.link) or self.link.endswith(".torrent"))
) or (file_ and file_.file_name and file_.file_name.endswith(".torrent")):
self.is_qbit = True

if (
Expand Down
Loading

0 comments on commit 24e66db

Please sign in to comment.