Skip to content

Commit

Permalink
ruff fix and checking in ytdl and clone
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 8, 2024
1 parent 0d9db99 commit c6ce01a
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 76 deletions.
6 changes: 4 additions & 2 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ async def restart_notification():

commit_link = result[0]

with open(".restartmsg") as f:
chat_id, msg_id = map(int, f)
async with aiopen(".restartmsg", mode="r") as f:
content = await f.read()
chat_id, msg_id = map(int, content.splitlines())

try:
await bot.edit_message_text(
chat_id=chat_id,
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ async def before_start(self):
ChatAction.TYPING,
)
except Exception:
raise ValueError("Start the bot and try again!")
raise ValueError("Start the bot and try again!") from None
elif (
self.user_transmission or self.mixed_leech
) and not self.is_super_chat:
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def clean_unwanted(path, custom_list=None):
await remove(f_path)
if dirpath.endswith((".unwanted", "splited_files", "copied_files")):
await aiormtree(dirpath, ignore_errors=True)
for dirpath, _, files in await sync_to_async(walk, path, topdown=False):
for dirpath, _, __ in await sync_to_async(walk, path, topdown=False):
if not await listdir(dirpath):
await rmdir(dirpath)

Expand Down
30 changes: 15 additions & 15 deletions bot/helper/listeners/mega_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def do(
async def mega_login(
executor,
api,
MAIL,
PASS,
email,
password,
):
if MAIL and PASS:
if email and password:
await sync_to_async(
executor.do,
api.login,
(
MAIL,
PASS,
email,
password,
),
)

Expand Down Expand Up @@ -81,7 +81,7 @@ def speed(self):
def downloaded_bytes(self):
return self._bytes_transferred

def onRequestFinish(
def onRequestFinish( # noqa: N802
self,
api,
request,
Expand Down Expand Up @@ -112,10 +112,10 @@ def onRequestFinish(
):
self.continue_event.set()

def onRequestTemporaryError(
def onRequestTemporaryError( # noqa: N802
self,
api,
request,
_,
__,
error: MegaError,
):
LOGGER.error(f"Mega Request error in {error}")
Expand All @@ -128,7 +128,7 @@ def onRequestTemporaryError(
self.error = error.toString()
self.continue_event.set()

def onTransferUpdate(
def onTransferUpdate( # noqa: N802
self,
api: MegaApi,
transfer: MegaTransfer,
Expand All @@ -143,11 +143,11 @@ def onTransferUpdate(
self._speed = transfer.getSpeed()
self._bytes_transferred = transfer.getTransferredBytes()

def onTransferFinish(
def onTransferFinish( # noqa: N802
self,
api: MegaApi,
_: MegaApi,
transfer: MegaTransfer,
error,
__,
):
try:
if self.is_cancelled:
Expand All @@ -160,9 +160,9 @@ def onTransferFinish(
except Exception as e:
LOGGER.error(e)

def onTransferTemporaryError(
def onTransferTemporaryError( # noqa: N802
self,
api,
_,
transfer,
error,
):
Expand Down
11 changes: 5 additions & 6 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ 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(
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)
msg, button = await stop_duplicate_check(task.listener)
if msg:
_on_download_error(msg, tor, button)


@new_task
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/status_utils/ffmpeg_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def progress(self):
except Exception:
try:
progress_raw = self._obj.processed_bytes / self._obj.size * 100
except:
except Exception:
progress_raw = 0
return f"{round(progress_raw, 2)}%"

Expand Down Expand Up @@ -63,7 +63,7 @@ def eta(self):
return get_readable_time(
(self._obj.size - self._obj.processed_bytes) / self._obj.speed,
)
except:
except Exception:
return "-"

def status(self):
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/status_utils/mega_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def name(self):
def progress_raw(self):
try:
return round(self._obj.downloaded_bytes / self._size * 100, 2)
except:
except Exception:
return 0.0

def progress(self):
Expand Down
1 change: 1 addition & 0 deletions bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: N811
from bot import CMD_SUFFIX as i


Expand Down
12 changes: 6 additions & 6 deletions bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async def send_message(
buttons=None,
block=True,
photo=None,
MARKDOWN=False,
markdown=False,
):
parse_mode = enums.ParseMode.MARKDOWN if MARKDOWN else enums.ParseMode.HTML
parse_mode = enums.ParseMode.MARKDOWN if markdown else enums.ParseMode.HTML
try:
if isinstance(message, int):
return await bot.send_message(
Expand Down Expand Up @@ -65,7 +65,7 @@ async def send_message(
LOGGER.warning(str(f))
if block:
await sleep(f.value * 1.2)
return await send_message(message, text, buttons, block, photo, MARKDOWN)
return await send_message(message, text, buttons, block, photo, markdown)
return str(f)
except Exception as e:
LOGGER.error(str(e))
Expand All @@ -78,9 +78,9 @@ async def edit_message(
buttons=None,
block=True,
photo=None,
MARKDOWN=False,
markdown=False,
):
parse_mode = enums.ParseMode.MARKDOWN if MARKDOWN else enums.ParseMode.HTML
parse_mode = enums.ParseMode.MARKDOWN if markdown else enums.ParseMode.HTML
try:
if message.media:
if photo:
Expand All @@ -104,7 +104,7 @@ async def edit_message(
LOGGER.warning(str(f))
if block:
await sleep(f.value * 1.2)
return await edit_message(message, text, buttons, block, photo, MARKDOWN)
return await edit_message(message, text, buttons, block, photo, markdown)
except (MessageNotModified, MessageEmpty):
pass
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ async def load_config():
FFMPEG_CMDS = environ.get("FFMPEG_CMDS", "")
try:
FFMPEG_CMDS = [] if len(FFMPEG_CMDS) == 0 else eval(FFMPEG_CMDS)
except:
except Exception:
LOGGER.error(f"Wrong FFMPEG_CMDS format: {FFMPEG_CMDS}")
FFMPEG_CMDS = []

Expand Down
8 changes: 8 additions & 0 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyrogram.handlers import MessageHandler

from bot import LOGGER, bot, bot_loop, task_dict, task_dict_lock
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.ext_utils.bot_utils import (
COMMAND_USAGE,
arg_parser,
Expand Down Expand Up @@ -38,6 +39,8 @@
delete_message,
send_message,
send_status_message,
five_minute_del,
delete_links,
)


Expand Down Expand Up @@ -67,6 +70,11 @@ def __init__(
self.is_clone = True

async def new_event(self):
error_msg, error_button = await error_check(self.message)
if error_msg:
await delete_links(self.message)
error = await send_message(self.message, error_msg, error_button)
return await five_minute_del(error)
text = self.message.text.split("\n")
input_list = text[0].split(" ")

Expand Down
6 changes: 3 additions & 3 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: RUF006
from asyncio import create_task
from base64 import b64encode
from re import match as re_match
Expand Down Expand Up @@ -230,9 +231,8 @@ async def new_event(self):

path = f"{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)
Expand Down
8 changes: 8 additions & 0 deletions bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from yt_dlp import YoutubeDL

from bot import DOWNLOAD_DIR, LOGGER, bot, bot_loop, config_dict, task_dict_lock
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.ext_utils.bot_utils import (
COMMAND_USAGE,
arg_parser,
Expand All @@ -30,6 +31,8 @@
delete_message,
edit_message,
send_message,
five_minute_del,
delete_links,
)


Expand Down Expand Up @@ -297,6 +300,11 @@ def __init__(
self.is_leech = is_leech

async def new_event(self):
error_msg, error_button = await error_check(self.message)
if error_msg:
await delete_links(self.message)
error = await send_message(self.message, error_msg, error_button)
return await five_minute_del(error)
text = self.message.text.split("\n")
input_list = text[0].split(" ")
qual = ""
Expand Down
Loading

0 comments on commit c6ce01a

Please sign in to comment.