Skip to content

Commit

Permalink
ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 5, 2025
1 parent 497be61 commit 8dd2aa4
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.13
3.12
1 change: 0 additions & 1 deletion bot/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 1 addition & 0 deletions bot/core/aeon_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async def start_user(cls):
Config.TELEGRAM_HASH,
session_string=Config.USER_SESSION_STRING,
parse_mode=enums.ParseMode.HTML,
no_updates=True
sleep_threshold=60,
max_concurrent_transmissions=10,
)
Expand Down
2 changes: 1 addition & 1 deletion bot/core/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Config:
DEFAULT_UPLOAD = "rc"
DOWNLOAD_DIR = "/usr/src/app/downloads/"
EXTENSION_FILTER = ""
FFMPEG_CMDS = {}
FFMPEG_CMDS: ClassVar[Dict[str, List[str]]] = {}
FILELION_API = ""
GDRIVE_ID = ""
INCOMPLETE_TASK_NOTIFIER = False
Expand Down
1 change: 0 additions & 1 deletion bot/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion bot/helper/ext_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion bot/helper/listeners/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

8 changes: 2 additions & 6 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ async def _on_seed_finish(tor):

@new_task
async def _stop_duplicate(tor):
if task := await get_task_by_gid(tor.hash[:12]):
if task.listener.stop_duplicate:
task.listener.name = tor.content_path.rsplit("/", 1)[-1].rsplit(
".!qB",
1,
)[0]
if (task := await get_task_by_gid(tor.hash[:12])) and task.listener.stop_duplicate:
task.listener.name = tor.content_path.rsplit("/", 1)[-1].rsplit(".!qB", 1)[0]
msg, button = await stop_duplicate_check(task.listener)
if msg:
_on_download_error(msg, tor, button)
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/listeners/task_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ async def on_upload_complete(
await send_message(self.message, msg)
else:
fmsg = ""
for index, (link, name) in enumerate(files.items(), start=1):
fmsg += f"{index}. <a href='{link}'>{name}</a>\n"
for index, (url, name) in enumerate(files.items(), start=1):
fmsg += f"{index}. <a href='{url}'>{name}</a>\n"
if len(fmsg.encode() + msg.encode()) > 4000:
await send_message(
self.user_id,
Expand Down
1 change: 0 additions & 1 deletion bot/helper/mirror_leech_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion bot/helper/mirror_leech_utils/download_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,6 @@ def _set_options(self, options):
self.opts[key].append(value)
elif key == "download_ranges":
if isinstance(value, list):
self.opts[key] = lambda info, ytdl: value
self.opts[key] = (lambda v: (lambda info, ytdl: v))(value)
else:
self.opts[key] = value
1 change: 0 additions & 1 deletion bot/helper/mirror_leech_utils/gdrive_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

5 changes: 2 additions & 3 deletions bot/helper/mirror_leech_utils/gdrive_utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def download(self):
self.listener.is_cancelled = True
finally:
self._updater.cancel()
if self.listener.is_cancelled:
return None
async_to_sync(self.listener.on_download_complete)
if not self.listener.is_cancelled:
async_to_sync(self.listener.on_download_complete)

def _download_folder(self, folder_id, path, folder_name):
folder_name = folder_name.replace("/", "")
Expand Down
40 changes: 22 additions & 18 deletions bot/helper/mirror_leech_utils/gdrive_utils/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def upload(self, unwanted_files, ft_delete):
self.service = self.authorize()
LOGGER.info(f"Uploading: {self._path}")
self._updater = SetInterval(self.update_interval, self.progress)
link = None
dir_id = None
mime_type = None
try:
if ospath.isfile(self._path):
if self._path.lower().endswith(
Expand Down Expand Up @@ -96,24 +99,25 @@ def upload(self, unwanted_files, ft_delete):
self._is_errored = True
finally:
self._updater.cancel()
if self.listener.is_cancelled and not self._is_errored:
if mime_type == "Folder":
LOGGER.info("Deleting uploaded data from Drive...")
self.service.files().delete(
fileId=dir_id,
supportsAllDrives=True,
).execute()
return
if self._is_errored:
return
async_to_sync(
self.listener.on_upload_complete,
link,
self.total_files,
self.total_folders,
mime_type,
dir_id=self.get_id_from_url(link),
)

if self.listener.is_cancelled and not self._is_errored:
if mime_type == "Folder" and dir_id:
LOGGER.info("Deleting uploaded data from Drive...")
self.service.files().delete(
fileId=dir_id,
supportsAllDrives=True,
).execute()
return
if self._is_errored:
return
async_to_sync(
self.listener.on_upload_complete,
link,
self.total_files,
self.total_folders,
mime_type,
dir_id=self.get_id_from_url(link) if link else None,
)

def _upload_dir(self, input_directory, dest_id, unwanted_files, ft_delete):
list_dirs = listdir(input_directory)
Expand Down
1 change: 0 additions & 1 deletion bot/helper/mirror_leech_utils/rclone_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion bot/helper/mirror_leech_utils/status_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion bot/helper/telegram_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

13 changes: 6 additions & 7 deletions bot/modules/mediainfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ async def gen_mediainfo(message, link=None, media=None, msg=None):
headers = {
"user-agent": "Mozilla/5.0 (Linux; Android 12; 2201116PI) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36",
}
async with aiohttp.ClientSession() as session:
async with session.get(link, headers=headers) as response:
file_size = int(response.headers.get("Content-Length", 0))
async with aiopen(des_path, "wb") as f:
async for chunk in response.content.iter_chunked(10000000):
await f.write(chunk)
break
async with aiohttp.ClientSession() as session, session.get(link, headers=headers) as response, aiopen(des_path, "wb") as f:
file_size = int(response.headers.get("Content-Length", 0))
async with aiopen(des_path, "wb") as f:
async for chunk in response.content.iter_chunked(10000000):
await f.write(chunk)
break
elif media:
des_path = ospath.join(path, media.file_name)
file_size = media.file_size
Expand Down
5 changes: 2 additions & 3 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ async def new_event(self):

path = f"{Config.DOWNLOAD_DIR}{self.mid}{self.folder_name}"

if not self.link and (reply_to := self.message.reply_to_message):
if reply_to.text:
self.link = reply_to.text.split("\n", 1)[0].strip()
if not self.link and (reply_to := self.message.reply_to_message) and reply_to.text:
self.link = reply_to.text.split("\n", 1)[0].strip()
if is_telegram_link(self.link):
try:
reply_to, session = await get_tg_link_message(self.link, user_id)
Expand Down
33 changes: 16 additions & 17 deletions bot/modules/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,25 @@ async def send_incomplete_task_message(cid, msg_id, msg):

async def restart_notification():
if await aiopath.isfile(".restartmsg"):
with open(".restartmsg") as f:
chat_id, msg_id = map(int, f)
with aiopen(".restartmsg", "r") as f:
chat_id, msg_id = map(int, await f.read().splitlines())
else:
chat_id, msg_id = 0, 0

if Config.INCOMPLETE_TASK_NOTIFIER and Config.DATABASE_URL:
if notifier_dict := await database.get_incomplete_tasks():
for cid, data in notifier_dict.items():
msg = (
"Restarted Successfully!" if cid == chat_id else "Bot Restarted!"
)
for tag, links in data.items():
msg += f"\n\n{tag}: "
for index, link in enumerate(links, start=1):
msg += f" <a href='{link}'>{index}</a> |"
if len(msg.encode()) > 4000:
await send_incomplete_task_message(cid, msg_id, msg)
msg = ""
if msg:
await send_incomplete_task_message(cid, msg_id, msg)
if Config.INCOMPLETE_TASK_NOTIFIER and Config.DATABASE_URL and (notifier_dict := await database.get_incomplete_tasks()):
for cid, data in notifier_dict.items():
msg = (
"Restarted Successfully!" if cid == chat_id else "Bot Restarted!"
)
for tag, links in data.items():
msg += f"\n\n{tag}: "
for index, link in enumerate(links, start=1):
msg += f" <a href='{link}'>{index}</a> |"
if len(msg.encode()) > 4000:
await send_incomplete_task_message(cid, msg_id, msg)
msg = ""
if msg:
await send_incomplete_task_message(cid, msg_id, msg)

if await aiopath.isfile(".restartmsg"):
with contextlib.suppress(Exception):
Expand Down
3 changes: 1 addition & 2 deletions bot/modules/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ async def get_packages_version():
get_version_async(command, regex) for command, regex in commands.values()
]
versions = await gather(*tasks)
for tool, version in zip(commands.keys(), versions, strict=False):
commands[tool] = version
commands.update({tool: version for tool, version in zip(commands.keys(), versions, strict=False)})
if await aiopath.exists(".git"):
last_commit = await cmd_exec(
"git log -1 --date=short --pretty=format:'%cd <b>From</b> %cr'",
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fix = true
unsafe-fixes = true
line-length = 85
target-version = "py313"
target-version = "py312"

[lint.mccabe]
max-complexity = 100
Expand Down

0 comments on commit 8dd2aa4

Please sign in to comment.