Skip to content

Commit

Permalink
Auto-format code [skip actions]
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 29, 2024
1 parent 8b1e1a9 commit 3c09948
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 58 deletions.
114 changes: 91 additions & 23 deletions bot/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,113 @@
def add_handlers():
command_filters = {
"authorize": (authorize, BotCommands.AuthorizeCommand, CustomFilters.sudo),
"unauthorize": (unauthorize, BotCommands.UnAuthorizeCommand, CustomFilters.sudo),
"unauthorize": (
unauthorize,
BotCommands.UnAuthorizeCommand,
CustomFilters.sudo,
),
"add_sudo": (add_sudo, BotCommands.AddSudoCommand, CustomFilters.sudo),
"remove_sudo": (remove_sudo, BotCommands.RmSudoCommand, CustomFilters.sudo),
"send_bot_settings": (send_bot_settings, BotCommands.BotSetCommand, CustomFilters.sudo),
"send_bot_settings": (
send_bot_settings,
BotCommands.BotSetCommand,
CustomFilters.sudo,
),
"cancel": (cancel, BotCommands.CancelTaskCommand, CustomFilters.authorized),
"cancel_all_buttons": (cancel_all_buttons, BotCommands.CancelAllCommand, CustomFilters.authorized),
"clone_node": (clone_node, BotCommands.CloneCommand, CustomFilters.authorized),
"cancel_all_buttons": (
cancel_all_buttons,
BotCommands.CancelAllCommand,
CustomFilters.authorized,
),
"clone_node": (
clone_node,
BotCommands.CloneCommand,
CustomFilters.authorized,
),
"aioexecute": (aioexecute, BotCommands.AExecCommand, CustomFilters.owner),
"execute": (execute, BotCommands.ExecCommand, CustomFilters.owner),
"clear": (clear, BotCommands.ClearLocalsCommand, CustomFilters.owner),
"select": (select, BotCommands.SelectCommand, CustomFilters.authorized),
"remove_from_queue": (remove_from_queue, BotCommands.ForceStartCommand, CustomFilters.authorized),
"count_node": (count_node, BotCommands.CountCommand, CustomFilters.authorized),
"delete_file": (delete_file, BotCommands.DeleteCommand, CustomFilters.authorized),
"gdrive_search": (gdrive_search, BotCommands.ListCommand, CustomFilters.authorized),
"remove_from_queue": (
remove_from_queue,
BotCommands.ForceStartCommand,
CustomFilters.authorized,
),
"count_node": (
count_node,
BotCommands.CountCommand,
CustomFilters.authorized,
),
"delete_file": (
delete_file,
BotCommands.DeleteCommand,
CustomFilters.authorized,
),
"gdrive_search": (
gdrive_search,
BotCommands.ListCommand,
CustomFilters.authorized,
),
"mirror": (mirror, BotCommands.MirrorCommand, CustomFilters.authorized),
"qb_mirror": (qb_mirror, BotCommands.QbMirrorCommand, CustomFilters.authorized),
"qb_mirror": (
qb_mirror,
BotCommands.QbMirrorCommand,
CustomFilters.authorized,
),
"leech": (leech, BotCommands.LeechCommand, CustomFilters.authorized),
"qb_leech": (qb_leech, BotCommands.QbLeechCommand, CustomFilters.authorized),
"get_rss_menu": (get_rss_menu, BotCommands.RssCommand, CustomFilters.authorized),
"get_rss_menu": (
get_rss_menu,
BotCommands.RssCommand,
CustomFilters.authorized,
),
"run_shell": (run_shell, BotCommands.ShellCommand, CustomFilters.owner),
"start": (start, BotCommands.StartCommand, None),
"log": (log, BotCommands.LogCommand, CustomFilters.sudo),
"restart_bot": (restart_bot, BotCommands.RestartCommand, CustomFilters.sudo),
"ping": (ping, BotCommands.PingCommand, CustomFilters.authorized),
"bot_help": (bot_help, BotCommands.HelpCommand, CustomFilters.authorized),
"bot_stats": (bot_stats, BotCommands.StatsCommand, CustomFilters.authorized),
"task_status": (task_status, BotCommands.StatusCommand, CustomFilters.authorized),
"torrent_search": (torrent_search, BotCommands.SearchCommand, CustomFilters.authorized),
"get_users_settings": (get_users_settings, BotCommands.UsersCommand, CustomFilters.sudo),
"send_user_settings": (send_user_settings, BotCommands.UserSetCommand, CustomFilters.authorized),
"task_status": (
task_status,
BotCommands.StatusCommand,
CustomFilters.authorized,
),
"torrent_search": (
torrent_search,
BotCommands.SearchCommand,
CustomFilters.authorized,
),
"get_users_settings": (
get_users_settings,
BotCommands.UsersCommand,
CustomFilters.sudo,
),
"send_user_settings": (
send_user_settings,
BotCommands.UserSetCommand,
CustomFilters.authorized,
),
"ytdl": (ytdl, BotCommands.YtdlCommand, CustomFilters.authorized),
"ytdl_leech": (ytdl_leech, BotCommands.YtdlLeechCommand, CustomFilters.authorized),
"restart_sessions": (restart_sessions, BotCommands.RestartSessionsCommand, CustomFilters.sudo),
"ytdl_leech": (
ytdl_leech,
BotCommands.YtdlLeechCommand,
CustomFilters.authorized,
),
"restart_sessions": (
restart_sessions,
BotCommands.RestartSessionsCommand,
CustomFilters.sudo,
),
}

for handler_name, (handler_func, command_name, custom_filter) in command_filters.items():
for handler_func, command_name, custom_filter in command_filters.values():
TgClient.bot.add_handler(
MessageHandler(
handler_func,
filters=command(command_name, case_sensitive=True) & (custom_filter or CustomFilters.authorized),
)
filters=command(command_name, case_sensitive=True)
& (custom_filter or CustomFilters.authorized),
),
)

regex_filters = {
Expand All @@ -75,11 +140,14 @@ def add_handlers():
}

for regex_filter, handler_func in regex_filters.items():
TgClient.bot.add_handler(CallbackQueryHandler(handler_func, filters=regex(regex_filter)))
TgClient.bot.add_handler(
CallbackQueryHandler(handler_func, filters=regex(regex_filter))
)

TgClient.bot.add_handler(
EditedMessageHandler(
run_shell,
filters=command(BotCommands.ShellCommand, case_sensitive=True) & CustomFilters.owner,
)
)
filters=command(BotCommands.ShellCommand, case_sensitive=True)
& CustomFilters.owner,
),
)
2 changes: 1 addition & 1 deletion bot/helper/aeon_utils/access_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
bot_name,
user_data,
)
from bot.core.aeon_client import TgClient
from bot.core.config_manager import Config
from bot.helper.aeon_utils.shorteners import short
from bot.helper.ext_utils.db_handler import database
from bot.helper.ext_utils.help_messages import nsfw_keywords
from bot.helper.ext_utils.status_utils import get_readable_time
from bot.helper.telegram_helper.button_build import ButtonMaker
from bot.core.aeon_client import TgClient


async def error_check(message):
Expand Down
9 changes: 5 additions & 4 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiofiles.os import remove

from bot import LOGGER, 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 All @@ -23,7 +24,6 @@
from bot.helper.mirror_leech_utils.download_utils.direct_link_generator import (
direct_link_generator,
)
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.mirror_leech_utils.gdrive_utils.clone import GoogleDriveClone
from bot.helper.mirror_leech_utils.gdrive_utils.count import GoogleDriveCount
from bot.helper.mirror_leech_utils.rclone_utils.transfer import RcloneTransferHelper
Expand Down Expand Up @@ -107,7 +107,7 @@ async def new_event(self):

if is_bulk:
await self.init_bulk(input_list, bulk_start, bulk_end, Clone)
return
return None

await self.get_tag(text)

Expand All @@ -122,14 +122,15 @@ async def new_event(self):
COMMAND_USAGE["clone"][0],
COMMAND_USAGE["clone"][1],
)
return
return None
LOGGER.info(self.link)
try:
await self.before_start()
except Exception as e:
await send_message(self.message, e)
return
return None
await self._proceed_to_clone(sync)
return None

async def _proceed_to_clone(self, sync):
if is_share_link(self.link):
Expand Down
55 changes: 33 additions & 22 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from asyncio import create_task
from base64 import b64encode
from re import match as re_match

from aiofiles.os import path as aiopath
from asyncio import create_task

from bot import LOGGER, bot_loop, task_dict_lock
from bot.core.config_manager import Config
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.ext_utils.bot_utils import (
COMMAND_USAGE,
arg_parser,
get_content_type,
sync_to_async,
)
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
from bot.helper.ext_utils.links_utils import (
is_gdrive_id,
Expand Down Expand Up @@ -44,10 +45,10 @@
TelegramDownloadHelper,
)
from bot.helper.telegram_helper.message_utils import (
get_tg_link_message,
send_message,
delete_links,
five_minute_del,
get_tg_link_message,
send_message,
)


Expand Down Expand Up @@ -214,7 +215,7 @@ async def new_event(self):
self.same_dir[fd_name]["total"] -= 1
else:
await self.init_bulk(input_list, bulk_start, bulk_end, Mirror)
return
return None

if len(self.bulk) != 0:
del self.bulk[0]
Expand Down Expand Up @@ -352,28 +353,38 @@ async def new_event(self):
return await five_minute_del(x)

if file_ is not None:
create_task(TelegramDownloadHelper(self).add_download(
reply_to,
f"{path}/",
session,
))
elif isinstance(self.link, dict):
create_task(
TelegramDownloadHelper(self).add_download(
reply_to,
f"{path}/",
session,
)
)
return None
if isinstance(self.link, dict):
create_task(add_direct_download(self, path))
elif self.is_qbit:
return None
if self.is_qbit:
create_task(add_qb_torrent(self, path, ratio, seed_time))
elif is_rclone_path(self.link):
return None
if is_rclone_path(self.link):
create_task(add_rclone_download(self, f"{path}/"))
elif is_mega_link(self.link):
return None
if is_mega_link(self.link):
create_task(add_mega_download(self, f"{path}/"))
elif is_gdrive_link(self.link) or is_gdrive_id(self.link):
return None
if is_gdrive_link(self.link) or is_gdrive_id(self.link):
create_task(add_gd_download(self, path))
else:
ussr = args["-au"]
pssw = args["-ap"]
if ussr or pssw:
auth = f"{ussr}:{pssw}"
headers += f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}"
create_task(add_aria2c_download(self, path, headers, ratio, seed_time))
return None
ussr = args["-au"]
pssw = args["-ap"]
if ussr or pssw:
auth = f"{ussr}:{pssw}"
headers += (
f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}"
)
create_task(add_aria2c_download(self, path, headers, ratio, seed_time))
return None


async def mirror(client, message):
Expand Down
17 changes: 9 additions & 8 deletions bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from bot import LOGGER, bot_loop, task_dict_lock
from bot.core.config_manager import Config
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.ext_utils.bot_utils import (
COMMAND_USAGE,
arg_parser,
Expand All @@ -20,18 +21,17 @@
get_readable_file_size,
get_readable_time,
)
from bot.helper.aeon_utils.access_check import error_check
from bot.helper.listeners.task_listener import TaskListener
from bot.helper.mirror_leech_utils.download_utils.yt_dlp_download import (
YoutubeDLHelper,
)
from bot.helper.telegram_helper.button_build import ButtonMaker
from bot.helper.telegram_helper.message_utils import (
delete_links,
delete_message,
edit_message,
send_message,
delete_links,
five_minute_del,
send_message,
)


Expand Down Expand Up @@ -414,7 +414,7 @@ async def new_event(self):
self.same_dir[fd_name]["total"] -= 1
else:
await self.init_bulk(input_list, bulk_start, bulk_end, YtDlp)
return
return None

if len(self.bulk) != 0:
del self.bulk[0]
Expand All @@ -435,7 +435,7 @@ async def new_event(self):
COMMAND_USAGE["yt"][1],
)
await self.remove_from_same_dir()
return
return None

if "mdisk.me" in self.link:
self.name, self.link = await _mdisk(self.link, self.name)
Expand All @@ -445,7 +445,7 @@ async def new_event(self):
except Exception as e:
await send_message(self.message, e)
await self.remove_from_same_dir()
return
return None

options = {"usenetrc": True, "cookiefile": "cookies.txt"}
if opt:
Expand Down Expand Up @@ -481,20 +481,21 @@ async def new_event(self):
msg = str(e).replace("<", " ").replace(">", " ")
await send_message(self.message, f"{self.tag} {msg}")
await self.remove_from_same_dir()
return
return None
finally:
await self.run_multi(input_list, YtDlp)

if not qual:
qual = await YtSelection(self).get_quality(result)
if qual is None:
await self.remove_from_same_dir()
return
return None

LOGGER.info(f"Downloading with YT-DLP: {self.link}")
playlist = "entries" in result
ydl = YoutubeDLHelper(self)
await ydl.add_download(path, qual, playlist, opt)
return None


async def ytdl(client, message):
Expand Down

0 comments on commit 3c09948

Please sign in to comment.