Remove /removeuser and update status display
This commit is contained in:
@@ -339,10 +339,10 @@ class TaskExecutor:
|
||||
try:
|
||||
from pyrogram.errors import MessageNotModified
|
||||
status_text = (
|
||||
f"📥 **Downloading file**\n\n"
|
||||
f"📥 **Загрузка файла**\n\n"
|
||||
f"🔗 {task.url[:50]}...\n"
|
||||
f"📊 Progress: **{percent}%**\n"
|
||||
f"⏳ Please wait..."
|
||||
f"📊 Прогресс: **{percent}%**\n"
|
||||
f"⏳ Пожалуйста, подождите..."
|
||||
)
|
||||
try:
|
||||
await app_client.edit_message_text(
|
||||
@@ -358,16 +358,16 @@ class TaskExecutor:
|
||||
# Save reference to event loop for use in progress hook
|
||||
progress_loop = asyncio.get_event_loop()
|
||||
|
||||
# Send one message about download start (will be updated)
|
||||
# Check if message already exists (from url_handler), if not - create one
|
||||
app_client = get_app_client()
|
||||
status_message = None
|
||||
if app_client:
|
||||
message_id = get_task_message(task.id)
|
||||
if not message_id and app_client:
|
||||
try:
|
||||
status_text = (
|
||||
f"📥 **Downloading file**\n\n"
|
||||
f"📥 **Загрузка начата**\n\n"
|
||||
f"🔗 {task.url[:50]}...\n"
|
||||
f"📊 Progress: **0%**\n"
|
||||
f"⏳ Please wait..."
|
||||
f"📊 Прогресс: **0%**\n"
|
||||
f"⏳ Ожидание начала загрузки..."
|
||||
)
|
||||
status_message = await app_client.send_message(
|
||||
task.user_id,
|
||||
@@ -548,17 +548,120 @@ class TaskExecutor:
|
||||
caption = f"📥 **{result.get('title', 'File')}**"
|
||||
if result.get('duration'):
|
||||
from bot.utils.helpers import format_duration
|
||||
caption += f"\n⏱ Duration: {format_duration(result['duration'])}"
|
||||
caption += f"\n⏱ Длительность: {format_duration(result['duration'])}"
|
||||
|
||||
# Send file
|
||||
logger.info(f"Calling send_file_to_user for file: {result['file_path']}")
|
||||
success = await send_file_to_user(
|
||||
client=app_client,
|
||||
chat_id=task.user_id,
|
||||
file_path=result['file_path'],
|
||||
caption=caption,
|
||||
thumbnail=result.get('thumbnail')
|
||||
)
|
||||
# Replace status message with video/file using edit_message_media
|
||||
message_id = get_task_message(task.id)
|
||||
success = False
|
||||
|
||||
if message_id:
|
||||
try:
|
||||
from pyrogram.types import InputMediaVideo, InputMediaPhoto, InputMediaAudio, InputMediaDocument
|
||||
from pathlib import Path
|
||||
|
||||
file = Path(result['file_path'])
|
||||
file_ext = file.suffix.lower()
|
||||
|
||||
# Determine media type and create appropriate InputMedia
|
||||
if file_ext in ['.mp4', '.avi', '.mov', '.mkv', '.webm']:
|
||||
# Video - prepare thumbnail
|
||||
thumbnail_path = result.get('thumbnail')
|
||||
if thumbnail_path and Path(thumbnail_path).exists():
|
||||
media = InputMediaVideo(
|
||||
media=str(file),
|
||||
caption=caption,
|
||||
thumb=str(thumbnail_path)
|
||||
)
|
||||
else:
|
||||
# Try to generate thumbnail if not exists
|
||||
from bot.utils.file_processor import generate_thumbnail
|
||||
thumbnail_path_temp = f"downloads/thumb_{file.stem}.jpg"
|
||||
if await generate_thumbnail(str(file), thumbnail_path_temp):
|
||||
media = InputMediaVideo(
|
||||
media=str(file),
|
||||
caption=caption,
|
||||
thumb=thumbnail_path_temp
|
||||
)
|
||||
else:
|
||||
media = InputMediaVideo(
|
||||
media=str(file),
|
||||
caption=caption
|
||||
)
|
||||
elif file_ext in ['.jpg', '.jpeg', '.png', '.gif', '.webp']:
|
||||
# Image
|
||||
media = InputMediaPhoto(
|
||||
media=str(file),
|
||||
caption=caption
|
||||
)
|
||||
elif file_ext in ['.mp3', '.wav', '.ogg', '.m4a', '.flac']:
|
||||
# Audio
|
||||
thumbnail_path = result.get('thumbnail')
|
||||
if thumbnail_path and Path(thumbnail_path).exists():
|
||||
media = InputMediaAudio(
|
||||
media=str(file),
|
||||
caption=caption,
|
||||
thumb=str(thumbnail_path)
|
||||
)
|
||||
else:
|
||||
media = InputMediaAudio(
|
||||
media=str(file),
|
||||
caption=caption
|
||||
)
|
||||
else:
|
||||
# Document
|
||||
thumbnail_path = result.get('thumbnail')
|
||||
if thumbnail_path and Path(thumbnail_path).exists():
|
||||
media = InputMediaDocument(
|
||||
media=str(file),
|
||||
caption=caption,
|
||||
thumb=str(thumbnail_path)
|
||||
)
|
||||
else:
|
||||
media = InputMediaDocument(
|
||||
media=str(file),
|
||||
caption=caption
|
||||
)
|
||||
|
||||
# Replace message with media
|
||||
await app_client.edit_message_media(
|
||||
chat_id=task.user_id,
|
||||
message_id=message_id,
|
||||
media=media
|
||||
)
|
||||
logger.info(f"Replaced status message with media for task {task.id}")
|
||||
success = True
|
||||
except Exception as e:
|
||||
# If edit_message_media fails, fallback to sending file normally
|
||||
logger.warning(f"Failed to replace message with media for task {task.id}: {e}, sending file normally")
|
||||
try:
|
||||
success = await send_file_to_user(
|
||||
client=app_client,
|
||||
chat_id=task.user_id,
|
||||
file_path=result['file_path'],
|
||||
caption=caption,
|
||||
thumbnail=result.get('thumbnail')
|
||||
)
|
||||
# Delete old status message if file sent successfully
|
||||
if success and message_id:
|
||||
try:
|
||||
await app_client.delete_messages(
|
||||
chat_id=task.user_id,
|
||||
message_ids=message_id
|
||||
)
|
||||
except Exception as delete_error:
|
||||
logger.debug(f"Failed to delete old message: {delete_error}")
|
||||
except Exception as send_error:
|
||||
logger.error(f"Failed to send file as fallback: {send_error}")
|
||||
else:
|
||||
# No message_id, send file normally
|
||||
logger.info(f"No message_id for task {task.id}, sending file normally")
|
||||
success = await send_file_to_user(
|
||||
client=app_client,
|
||||
chat_id=task.user_id,
|
||||
file_path=result['file_path'],
|
||||
caption=caption,
|
||||
thumbnail=result.get('thumbnail')
|
||||
)
|
||||
|
||||
logger.info(f"File sending result: success={success}")
|
||||
|
||||
@@ -567,17 +670,6 @@ class TaskExecutor:
|
||||
await delete_file(result['file_path'])
|
||||
await task_queue.update_task_status(task.id, TaskStatus.COMPLETED, progress=100)
|
||||
task_queue.clear_cancel_event(task.id)
|
||||
|
||||
# Delete download message (file already sent)
|
||||
message_id = get_task_message(task.id)
|
||||
if message_id:
|
||||
try:
|
||||
await app_client.delete_messages(
|
||||
chat_id=task.user_id,
|
||||
message_ids=message_id
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"Failed to delete download message for task {task.id}: {e}")
|
||||
clear_task_message(task.id)
|
||||
else:
|
||||
error_msg = "Failed to send file"
|
||||
|
||||
Reference in New Issue
Block a user