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 28, 2024
1 parent 0369615 commit 1e49059
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 36 deletions.
15 changes: 9 additions & 6 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from asyncio import gather
from signal import SIGINT, signal

from pyrogram.filters import regex
from pyrogram.handlers import CallbackQueryHandler

from . import LOGGER, bot_loop
from .core.aeon_client import TgClient
from .core.config_manager import Config
Expand All @@ -13,22 +16,21 @@
update_qb_options,
update_variables,
)
from .helper.ext_utils.bot_utils import create_help_buttons, sync_to_async, new_task
from .helper.ext_utils.bot_utils import create_help_buttons, new_task, sync_to_async
from .helper.ext_utils.files_utils import clean_all, exit_clean_up
from .helper.ext_utils.telegraph_helper import telegraph
from .helper.listeners.aria2_listener import start_aria2_listener
from .helper.mirror_leech_utils.rclone_utils.serve import rclone_serve_booter
from .helper.telegram_helper.filters import CustomFilters
from .modules import (
get_packages_version,
initiate_search_tools,
restart_notification,
)
from .helper.telegram_helper.filters import CustomFilters
from pyrogram.filters import regex
from pyrogram.handlers import CallbackQueryHandler

Config.load()


@new_task
async def restart_sessions_confirm(_, query):
data = query.data.split()
Expand All @@ -43,12 +45,13 @@ async def restart_sessions_confirm(_, query):
CallbackQueryHandler(
restart_sessions_confirm,
filters=regex("^sessionrestart") & CustomFilters.sudo,
)
),
)
await edit_message(restart_message, "Session(s) Restarted Successfully!")
else:
await delete_message(message)


async def main():
await load_settings()
await gather(TgClient.start_bot(), TgClient.start_user())
Expand All @@ -73,7 +76,7 @@ async def main():
CallbackQueryHandler(
restart_sessions_confirm,
filters=regex("^sessionrestart") & CustomFilters.sudo,
)
),
)
LOGGER.info("Bot Started!")
signal(SIGINT, exit_clean_up)
Expand Down
8 changes: 4 additions & 4 deletions bot/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ def add_handlers():
)
TgClient.bot.add_handler(
CallbackQueryHandler(
confirm_restart, filters=regex("^botrestart") & CustomFilters.sudo
)
confirm_restart,
filters=regex("^botrestart") & CustomFilters.sudo,
),
)
TgClient.bot.add_handler(
MessageHandler(
restart_sessions,
filters=command(BotCommands.RestartSessionsCommand, case_sensitive=True)
& CustomFilters.sudo,
)
),
)

2 changes: 1 addition & 1 deletion bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ async def get_telegraph_list(telegraph_content):


def arg_parser(items, arg_base):

if not items:
return

Expand All @@ -116,6 +115,7 @@ def arg_parser(items, arg_base):
"-doc",
"-med",
}

def process_argument_with_values(start_index):
values = []
for j in range(start_index + 1, total):
Expand Down
6 changes: 5 additions & 1 deletion bot/helper/mirror_leech_utils/telegram_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ async def upload(self, o_files, ft_delete):
retry=retry_if_exception_type(Exception),
)
async def _upload_file(self, cap_mono, file, o_path, force_document=False):
if self._thumb is not None and not await aiopath.exists(self._thumb) and self._thumb != "none":
if (
self._thumb is not None
and not await aiopath.exists(self._thumb)
and self._thumb != "none"
):
self._thumb = None
thumb = self._thumb
self._is_corrupted = False
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
qb_mirror,
)
from .restart import (
confirm_restart,
restart_bot,
restart_notification,
confirm_restart,
restart_sessions,
)
from .rss import get_rss_menu, rss_listener
Expand Down Expand Up @@ -47,6 +47,7 @@
"cancel_multi",
"clear",
"clone_node",
"confirm_restart",
"confirm_selection",
"count_node",
"delete_file",
Expand All @@ -68,7 +69,6 @@
"remove_sudo",
"restart_bot",
"restart_notification",
"confirm_restart",
"restart_sessions",
"rss_listener",
"run_shell",
Expand Down
48 changes: 27 additions & 21 deletions bot/modules/restart.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import contextlib
from asyncio import create_subprocess_exec, gather
from os import execl as osexecl
from sys import executable

from aiofiles import open as aiopen
from aiofiles.os import path as aiopath, remove
from asyncio import gather, create_subprocess_exec
from os import execl as osexecl
from aiofiles.os import path as aiopath
from aiofiles.os import remove

from .. import intervals, scheduler, sabnzbd_client, LOGGER
from ..helper.ext_utils.bot_utils import new_task, sync_to_async
from ..helper.telegram_helper.message_utils import (
send_message,
delete_message,
)
from ..helper.ext_utils.db_handler import database
from ..helper.ext_utils.files_utils import clean_all
from ..helper.telegram_helper import button_build
from ..core.mltb_client import TgClient
from ..core.config_manager import Config
from bot import LOGGER, intervals, sabnzbd_client, scheduler
from bot.core.config_manager import Config
from bot.core.mltb_client import TgClient
from bot.helper.ext_utils.bot_utils import new_task, sync_to_async
from bot.helper.ext_utils.db_handler import database
from bot.helper.ext_utils.files_utils import clean_all
from bot.helper.telegram_helper import button_build
from bot.helper.telegram_helper.message_utils import delete_message, send_message


@new_task
Expand All @@ -23,7 +23,9 @@ async def restart_bot(_, message):
buttons.data_button("Yes!", "botrestart confirm")
buttons.data_button("Cancel", "botrestart cancel")
button = buttons.build_menu(2)
await send_message(message, "Are you sure you want to restart the bot ?!", button)
await send_message(
message, "Are you sure you want to restart the bot ?!", button
)


@new_task
Expand All @@ -33,7 +35,9 @@ async def restart_sessions(_, message):
buttons.data_button("Cancel", "sessionrestart cancel")
button = buttons.build_menu(2)
await send_message(
message, "Are you sure you want to restart the session(s) ?!", button
message,
"Are you sure you want to restart the session(s) ?!",
button,
)


Expand Down Expand Up @@ -68,7 +72,9 @@ async def restart_notification():
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!"
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):
Expand All @@ -80,12 +86,12 @@ async def restart_notification():
await send_incomplete_task_message(cid, msg_id, msg)

if await aiopath.isfile(".restartmsg"):
try:
with contextlib.suppress(Exception):
await TgClient.bot.edit_message_text(
chat_id=chat_id, message_id=msg_id, text="Restarted Successfully!"
chat_id=chat_id,
message_id=msg_id,
text="Restarted Successfully!",
)
except:
pass
await remove(".restartmsg")


Expand Down
2 changes: 1 addition & 1 deletion config_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
"https://raw.githubusercontent.com/nindogo/qbtSearchScripts/master/magnetdl.py",
"https://raw.githubusercontent.com/msagca/qbittorrent_plugins/main/uniondht.py",
"https://raw.githubusercontent.com/khensolomon/leyts/master/yts.py",
]
]

0 comments on commit 1e49059

Please sign in to comment.