diff --git a/bot.py b/bot.py index 6007357..df28862 100644 --- a/bot.py +++ b/bot.py @@ -99,7 +99,7 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No await update.message.reply_text(help_text) -# --- Команда /status (ОБНОВЛЕНО с общей статистикой и кнопками удаления) --- +# --- Команда /status --- async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if update.message is None: logger.warning("Received an update without a message object in status handler.") @@ -377,15 +377,20 @@ async def send_directory_options(query, context): try: available_paths = [ qb.app.default_save_path, - "/share/Data/Films", # ЗАМЕНИТЕ НА СВОИ АКТУАЛЬНЫЕ ПУТИ - "/share/Data/Serials", - "/share/Data/torrents", + # --- ВАЖНО: ЗАМЕНИТЕ ЭТИ ПУТИ НА СВОИ АКТУАЛЬНЫЕ ПУТИ, ВИДИМЫЕ QBITTORRENT --- + "/share/Data/Films", + "/share/Data/Serials", # Пример пути + "/share/Data/torrents", # Пример пути + #"/var/lib/qbittorrent/data/completed", # Пример пути + # ------------------------------------------------------------------------- ] + # Удаляем дубликаты и сортируем пути для удобства available_paths = sorted(list(set([p.replace(os.sep, '/') for p in available_paths if p]))) directory_keyboard = [] for path in available_paths: + # Обрезаем путь для отображения, если он слишком длинный display_path = os.path.basename(path) if len(path) > 30 else path directory_keyboard.append([InlineKeyboardButton(display_path, callback_data=f"select_dir_{path}")]) @@ -406,6 +411,7 @@ async def select_directory_callback(update: Update, context: ContextTypes.DEFAUL await query.answer() data = query.data.split('_') + # Собираем путь обратно из частей, так как он может содержать '_' selected_directory = "_".join(data[2:]) logger.info(f"Selected directory: {selected_directory}") @@ -424,6 +430,7 @@ async def select_directory_callback(update: Update, context: ContextTypes.DEFAUL return try: + # Логирование параметров перед добавлением торрента logger.info(f"Attempting to add torrent:") logger.info(f" URL: {torrent_url}") logger.info(f" Category: {category or 'None'}") @@ -439,6 +446,7 @@ async def select_directory_callback(update: Update, context: ContextTypes.DEFAUL f"Категория: {category or 'Без категории'}\n" f"Директория: {selected_directory}" ) + # Очистка user_data после успешного добавления if 'current_torrent_url' in context.user_data: del context.user_data['current_torrent_url'] if 'selected_category' in context.user_data: @@ -502,7 +510,7 @@ def main() -> None: application.add_handler(CallbackQueryHandler(stop_torrent_callback, pattern=r"^stop_hash_.*")) # CallbackQueryHandler для кнопок запуска торрентов application.add_handler(CallbackQueryHandler(start_torrent_callback, pattern=r"^start_hash_.*")) - # НОВЫЙ CallbackQueryHandler для кнопок удаления торрентов + # CallbackQueryHandler для кнопок удаления торрентов application.add_handler(CallbackQueryHandler(delete_torrent_callback, pattern=r"^delete_hash_.*")) @@ -512,8 +520,8 @@ def main() -> None: # --- Обработчик для неизвестных команд --- application.add_handler(MessageHandler(filters.COMMAND, unknown_command)) - # --- Добавление обработчика ошибок --- - application.add_handler(application.add_error_handler(error_handler)) # Исправлено: handler_manager.add_error_handler expects a handler, not its return value + # --- Добавление обработчика ошибок (ИСПРАВЛЕНО!) --- + application.add_error_handler(error_handler) # --- Запуск бота --- logger.info("Bot started polling...")