mirror of
https://github.com/DerrtSML/qbittorent_bot.git
synced 2025-10-25 20:10:08 +03:00
Update bot.py
This commit is contained in:
parent
33f24f6d13
commit
9adeadfd8b
22
bot.py
22
bot.py
@ -99,7 +99,7 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||||||
await update.message.reply_text(help_text)
|
await update.message.reply_text(help_text)
|
||||||
|
|
||||||
|
|
||||||
# --- Команда /status (ОБНОВЛЕНО с общей статистикой и кнопками удаления) ---
|
# --- Команда /status ---
|
||||||
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
if update.message is None:
|
if update.message is None:
|
||||||
logger.warning("Received an update without a message object in status handler.")
|
logger.warning("Received an update without a message object in status handler.")
|
||||||
@ -377,15 +377,20 @@ 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/Films", # ЗАМЕНИТЕ НА СВОИ АКТУАЛЬНЫЕ ПУТИ
|
# --- ВАЖНО: ЗАМЕНИТЕ ЭТИ ПУТИ НА СВОИ АКТУАЛЬНЫЕ ПУТИ, ВИДИМЫЕ QBITTORRENT ---
|
||||||
"/share/Data/Serials",
|
"/share/Data/Films",
|
||||||
"/share/Data/torrents",
|
"/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])))
|
available_paths = sorted(list(set([p.replace(os.sep, '/') for p in available_paths if p])))
|
||||||
|
|
||||||
directory_keyboard = []
|
directory_keyboard = []
|
||||||
for path in available_paths:
|
for path in available_paths:
|
||||||
|
# Обрезаем путь для отображения, если он слишком длинный
|
||||||
display_path = os.path.basename(path) if len(path) > 30 else path
|
display_path = os.path.basename(path) if len(path) > 30 else path
|
||||||
directory_keyboard.append([InlineKeyboardButton(display_path, callback_data=f"select_dir_{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()
|
await query.answer()
|
||||||
|
|
||||||
data = query.data.split('_')
|
data = query.data.split('_')
|
||||||
|
# Собираем путь обратно из частей, так как он может содержать '_'
|
||||||
selected_directory = "_".join(data[2:])
|
selected_directory = "_".join(data[2:])
|
||||||
|
|
||||||
logger.info(f"Selected directory: {selected_directory}")
|
logger.info(f"Selected directory: {selected_directory}")
|
||||||
@ -424,6 +430,7 @@ async def select_directory_callback(update: Update, context: ContextTypes.DEFAUL
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Логирование параметров перед добавлением торрента
|
||||||
logger.info(f"Attempting to add torrent:")
|
logger.info(f"Attempting to add torrent:")
|
||||||
logger.info(f" URL: {torrent_url}")
|
logger.info(f" URL: {torrent_url}")
|
||||||
logger.info(f" Category: {category or 'None'}")
|
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"Категория: {category or 'Без категории'}\n"
|
||||||
f"Директория: {selected_directory}"
|
f"Директория: {selected_directory}"
|
||||||
)
|
)
|
||||||
|
# Очистка user_data после успешного добавления
|
||||||
if 'current_torrent_url' in context.user_data:
|
if 'current_torrent_url' in context.user_data:
|
||||||
del context.user_data['current_torrent_url']
|
del context.user_data['current_torrent_url']
|
||||||
if 'selected_category' in context.user_data:
|
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_.*"))
|
application.add_handler(CallbackQueryHandler(stop_torrent_callback, pattern=r"^stop_hash_.*"))
|
||||||
# CallbackQueryHandler для кнопок запуска торрентов
|
# CallbackQueryHandler для кнопок запуска торрентов
|
||||||
application.add_handler(CallbackQueryHandler(start_torrent_callback, pattern=r"^start_hash_.*"))
|
application.add_handler(CallbackQueryHandler(start_torrent_callback, pattern=r"^start_hash_.*"))
|
||||||
# НОВЫЙ CallbackQueryHandler для кнопок удаления торрентов
|
# CallbackQueryHandler для кнопок удаления торрентов
|
||||||
application.add_handler(CallbackQueryHandler(delete_torrent_callback, pattern=r"^delete_hash_.*"))
|
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(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...")
|
logger.info("Bot started polling...")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user