Skip to content

Commit

Permalink
Merge pull request #28 from ch3p4ll3/V2-quick-fix
Browse files Browse the repository at this point in the history
V2 quick Fix
  • Loading branch information
ch3p4ll3 authored Jan 2, 2024
2 parents c7a3ede + 53fafba commit 63b88ff
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/bot/plugins/callbacks/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
4 changes: 2 additions & 2 deletions src/bot/plugins/callbacks/category/category_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")])
Expand Down
1 change: 0 additions & 1 deletion src/bot/plugins/callbacks/list_callbacks.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/bot/plugins/callbacks/pause_resume/pause_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/bot/plugins/callbacks/pause_resume/resume_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
]
]
)
Expand All @@ -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("<class ", "").replace(">", ""))
data_type = convert_type_from_string(data.split("-")[2])

user_info = get_user_from_config(user_id)

Expand Down
1 change: 0 additions & 1 deletion src/bot/plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/bot/plugins/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")])
Expand Down
4 changes: 2 additions & 2 deletions src/client_manager/qbittorrent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
25 changes: 13 additions & 12 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 63b88ff

Please sign in to comment.