diff --git a/main.py b/main.py index b377446..ac4f478 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ mkdir(Configs.log_folder) # Create a file handler -handler = logging.handlers.TimedRotatingFileHandler( +handler = handlers.TimedRotatingFileHandler( f'{Configs.log_folder}/QbittorrentBot.log', when='midnight', backupCount=10 diff --git a/src/bot/plugins/callbacks/__init__.py b/src/bot/plugins/callbacks/__init__.py index eb03b23..e69de29 100644 --- a/src/bot/plugins/callbacks/__init__.py +++ b/src/bot/plugins/callbacks/__init__.py @@ -1,8 +0,0 @@ -from .add_torrents_callbacks import * -from src.bot.plugins.callbacks.category.category_callbacks import * -from src.bot.plugins.callbacks.delete.delete_all_callbacks import * -from src.bot.plugins.callbacks.delete.delete_single_callbacks import * -from .list_callbacks import * -from .pause_resume.pause_callbacks import * -from .pause_resume.resume_callbacks import * -from .torrent_info import * diff --git a/src/bot/plugins/callbacks/category/category_callbacks.py b/src/bot/plugins/callbacks/category/category_callbacks.py index 0ecf5d0..0cbc71d 100644 --- a/src/bot/plugins/callbacks/category/category_callbacks.py +++ b/src/bot/plugins/callbacks/category/category_callbacks.py @@ -2,7 +2,7 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery from pyrogram.errors.exceptions import MessageIdInvalid -from ...callbacks import add_magnet_callback, add_torrent_callback +from ..add_torrents_callbacks import add_magnet_callback, add_torrent_callback from ..... import db_management from .... import custom_filters from .....client_manager import ClientRepo @@ -33,7 +33,7 @@ async def list_categories(client: Client, callback_query: CallbackQuery): "There are no categories", reply_markup=InlineKeyboardMarkup(buttons)) return - for key, i in enumerate(categories): + for _, i in enumerate(categories): buttons.append([InlineKeyboardButton(i, f"{callback_query.data.split('#')[1]}#{i}")]) buttons.append([InlineKeyboardButton("🔙 Menu", "menu")]) diff --git a/src/bot/plugins/callbacks/list_callbacks.py b/src/bot/plugins/callbacks/list_callbacks.py index ecdce05..758485d 100644 --- a/src/bot/plugins/callbacks/list_callbacks.py +++ b/src/bot/plugins/callbacks/list_callbacks.py @@ -1,7 +1,6 @@ from pyrogram import Client from pyrogram.types import CallbackQuery from ... import custom_filters -from .... import db_management from ..common import list_active_torrents, send_menu diff --git a/src/bot/plugins/callbacks/pause_resume/pause_callbacks.py b/src/bot/plugins/callbacks/pause_resume/pause_callbacks.py index 263a26d..332279d 100644 --- a/src/bot/plugins/callbacks/pause_resume/pause_callbacks.py +++ b/src/bot/plugins/callbacks/pause_resume/pause_callbacks.py @@ -3,7 +3,7 @@ from .... import custom_filters from .....client_manager import ClientRepo -from ...common import list_active_torrents, send_menu +from ...common import list_active_torrents from .....configs import Configs diff --git a/src/bot/plugins/callbacks/pause_resume/resume_callbacks.py b/src/bot/plugins/callbacks/pause_resume/resume_callbacks.py index 8dd1428..477adad 100644 --- a/src/bot/plugins/callbacks/pause_resume/resume_callbacks.py +++ b/src/bot/plugins/callbacks/pause_resume/resume_callbacks.py @@ -3,7 +3,7 @@ from .... import custom_filters from .....client_manager import ClientRepo -from ...common import list_active_torrents, send_menu +from ...common import list_active_torrents from .....configs import Configs diff --git a/src/bot/plugins/callbacks/settings/client_settings_callbacks.py b/src/bot/plugins/callbacks/settings/client_settings_callbacks.py index 0c119b9..3951af2 100644 --- a/src/bot/plugins/callbacks/settings/client_settings_callbacks.py +++ b/src/bot/plugins/callbacks/settings/client_settings_callbacks.py @@ -89,7 +89,7 @@ async def list_client_settings_callback(client: Client, callback_query: Callback ] await callback_query.edit_message_text( - f"Edit Qbittorrent Client", + "Edit Qbittorrent Client", reply_markup=InlineKeyboardMarkup( fields + [ diff --git a/src/bot/plugins/callbacks/settings/users_settings_callbacks.py b/src/bot/plugins/callbacks/settings/users_settings_callbacks.py index 168ab63..da448ef 100644 --- a/src/bot/plugins/callbacks/settings/users_settings_callbacks.py +++ b/src/bot/plugins/callbacks/settings/users_settings_callbacks.py @@ -6,7 +6,7 @@ from .... import custom_filters from .....configs import Configs from .....db_management import write_support -from .....utils import get_user_from_config +from .....utils import get_user_from_config, convert_type_from_string @Client.on_callback_query(custom_filters.get_users_filter & custom_filters.check_user_filter & custom_filters.user_is_administrator) @@ -52,7 +52,7 @@ async def get_user_info_callback(client: Client, callback_query: CallbackQuery) fields + [ [ - InlineKeyboardButton(f"🔙 Users", f"get_users") + InlineKeyboardButton("🔙 Users", "get_users") ] ] ) @@ -64,7 +64,7 @@ async def edit_user_callback(client: Client, callback_query: CallbackQuery) -> N data = callback_query.data.split("#")[1] user_id = int(data.split("-")[0]) field_to_edit = data.split("-")[1] - data_type = eval(data.split("-")[2].replace("", "")) + data_type = convert_type_from_string(data.split("-")[2]) user_info = get_user_from_config(user_id) diff --git a/src/bot/plugins/commands.py b/src/bot/plugins/commands.py index 13ace3c..ec66a2b 100644 --- a/src/bot/plugins/commands.py +++ b/src/bot/plugins/commands.py @@ -5,7 +5,6 @@ from .. import custom_filters from ...db_management import write_support from ...utils import convert_size -from ...configs import Configs from .common import send_menu diff --git a/src/bot/plugins/common.py b/src/bot/plugins/common.py index 80ea3b8..aaa6902 100644 --- a/src/bot/plugins/common.py +++ b/src/bot/plugins/common.py @@ -67,7 +67,7 @@ def render_categories_buttons(): buttons = [categories_buttons] if callback is not None: - for key, i in enumerate(torrents): + for _, i in enumerate(torrents): buttons.append([InlineKeyboardButton(i.name, f"{callback}#{i.info.hash}")]) buttons.append([InlineKeyboardButton("🔙 Menu", "menu")]) diff --git a/src/client_manager/qbittorrent_manager.py b/src/client_manager/qbittorrent_manager.py index fe26d45..907d2bf 100644 --- a/src/client_manager/qbittorrent_manager.py +++ b/src/client_manager/qbittorrent_manager.py @@ -79,14 +79,14 @@ def delete_one_data(cls, torrent_hash: str) -> None: @classmethod def delete_all_no_data(cls) -> None: - logger.debug(f"Deleting all torrents") + logger.debug("Deleting all torrents") with qbittorrentapi.Client(**Configs.config.client.connection_string) as qbt_client: for i in qbt_client.torrents_info(): qbt_client.torrents_delete(delete_files=False, hashes=i.hash) @classmethod def delete_all_data(cls) -> None: - logger.debug(f"Deleting all torrent + files") + logger.debug("Deleting all torrent + files") with qbittorrentapi.Client(**Configs.config.client.connection_string) as qbt_client: for i in qbt_client.torrents_info(): qbt_client.torrents_delete(delete_files=True, hashes=i.hash) diff --git a/src/configs/__init__.py b/src/configs/__init__.py index a24d648..be31b26 100644 --- a/src/configs/__init__.py +++ b/src/configs/__init__.py @@ -1,6 +1,6 @@ from .config import MainConfig from os import getenv -from json import load, dumps +from json import load from typing import Union diff --git a/src/utils.py b/src/utils.py index b01fcee..6214ad4 100644 --- a/src/utils.py +++ b/src/utils.py @@ -5,24 +5,25 @@ from pyrogram.errors.exceptions import UserIsBlocked from src import db_management -from src.client_manager.qbittorrent_manager import QbittorrentManager +from src.client_manager import ClientRepo from .configs import Configs from .configs.enums import ClientTypeEnum, UserRolesEnum from .configs.user import User async def torrent_finished(app): - with QbittorrentManager() as qb: - for i in qb.get_torrent_info(status_filter="completed"): - if db_management.read_completed_torrents(i.hash) is None: - - for user in Configs.config.users: - if user.notify: - try: - await app.send_message(user.user_id, f"torrent {i.name} has finished downloading!") - except UserIsBlocked: - pass - db_management.write_completed_torrents(i.hash) + repository = ClientRepo.get_client_manager(Configs.config.client.type) + + for i in repository.get_torrent_info(status_filter="completed"): + if db_management.read_completed_torrents(i.hash) is None: + + for user in Configs.config.users: + if user.notify: + try: + await app.send_message(user.user_id, f"torrent {i.name} has finished downloading!") + except UserIsBlocked: + pass + db_management.write_completed_torrents(i.hash) def get_user_from_config(user_id: int) -> User: