mirror of
https://github.com/DerrtSML/qbittorent_bot.git
synced 2025-10-26 04:20:08 +03:00
Update bot.py
This commit is contained in:
parent
ee23ab8ad7
commit
2b488c3d4e
57
bot.py
57
bot.py
@ -310,9 +310,9 @@ async def send_directory_options(query, context):
|
|||||||
try:
|
try:
|
||||||
available_paths = [
|
available_paths = [
|
||||||
qb.app.default_save_path,
|
qb.app.default_save_path,
|
||||||
"/share/Data/torrents", # ЗАМЕНИТЕ НА СВОИ АКТУАЛЬНЫЕ ПУТИ
|
"/share/Data/Films", # ЗАМЕНИТЕ НА СВОИ АКТУАЛЬНЫЕ ПУТИ
|
||||||
"/share/Data/Films",
|
"/share/Data/Serials",
|
||||||
"/share/Data/Serials",
|
"/share/Data/torrents",
|
||||||
]
|
]
|
||||||
|
|
||||||
available_paths = sorted(list(set([p.replace(os.sep, '/') for p in available_paths if p])))
|
available_paths = sorted(list(set([p.replace(os.sep, '/') for p in available_paths if p])))
|
||||||
@ -401,58 +401,7 @@ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
logger.info(f"Received non-command text: {update.message.text} from {update.effective_user.id}")
|
logger.info(f"Received non-command text: {update.message.text} from {update.effective_user.id}")
|
||||||
await update.message.reply_text(f"Вы сказали: {update.message.text}")
|
await update.message.reply_text(f"Вы сказали: {update.message.text}")
|
||||||
|
|
||||||
# --- Обработка выбора директории и добавление торрента (ОБНОВЛЕНО с логированием) ---
|
|
||||||
async def select_directory_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
||||||
query = update.callback_query
|
|
||||||
await query.answer()
|
|
||||||
|
|
||||||
data = query.data.split('_')
|
|
||||||
# Собираем путь обратно из частей, если в нем были подчеркивания
|
|
||||||
selected_directory = "_".join(data[2:])
|
|
||||||
|
|
||||||
logger.info(f"Selected directory: {selected_directory}")
|
|
||||||
|
|
||||||
torrent_url = context.user_data.get('current_torrent_url')
|
|
||||||
category = context.user_data.get('selected_category')
|
|
||||||
|
|
||||||
if not torrent_url:
|
|
||||||
await query.edit_message_text("Ошибка: URL торрента не найден. Пожалуйста, попробуйте снова.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not init_qbittorrent_client():
|
|
||||||
await query.edit_message_text(
|
|
||||||
"Не удалось подключиться к qBittorrent. Проверьте переменные окружения и доступность сервера."
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
# --- НОВОЕ ЛОГИРОВАНИЕ ПЕРЕД ДОБАВЛЕНИЕМ ТОРРЕНТА ---
|
|
||||||
logger.info(f"Attempting to add torrent:")
|
|
||||||
logger.info(f" URL: {torrent_url}")
|
|
||||||
logger.info(f" Category: {category or 'None'}")
|
|
||||||
logger.info(f" Save Path: {selected_directory}")
|
|
||||||
# --- КОНЕЦ НОВОГО ЛОГИРОВАНИЯ ---
|
|
||||||
|
|
||||||
qb.torrents_add(
|
|
||||||
urls=torrent_url,
|
|
||||||
category=category,
|
|
||||||
save_path=selected_directory
|
|
||||||
)
|
|
||||||
await query.edit_message_text(
|
|
||||||
f"Торрент успешно добавлен в qBittorrent.\n"
|
|
||||||
f"Категория: {category or 'Без категории'}\n"
|
|
||||||
f"Директория: {selected_directory}"
|
|
||||||
)
|
|
||||||
if 'current_torrent_url' in context.user_data:
|
|
||||||
del context.user_data['current_torrent_url']
|
|
||||||
if 'selected_category' in context.user_data:
|
|
||||||
del context.user_data['selected_category']
|
|
||||||
except APIError as e:
|
|
||||||
logger.error(f"API Error adding torrent: {e}") # Более специфичное сообщение
|
|
||||||
await query.edit_message_text(f"Ошибка API при добавлении торрента: {e}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"An unexpected error occurred during torrent addition: {e}") # Более специфичное сообщение
|
|
||||||
await query.edit_message_text(f"Произошла непредвиденная ошибка при добавлении торрента: {e}")
|
|
||||||
# --- Основная функция, запускающая бота ---
|
# --- Основная функция, запускающая бота ---
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
if not TELEGRAM_BOT_TOKEN:
|
if not TELEGRAM_BOT_TOKEN:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user