Files
DownloadSM/bot/telegram_send.py
smolkik-code 66a37ab5cb update v0.1
2025-12-27 01:20:49 +07:00

60 lines
2.4 KiB
Python

import asyncio
from pathlib import Path
from typing import Optional
from telegram import Message
from telegram.constants import ParseMode
from telegram.error import TelegramError
import logging
logger = logging.getLogger(__name__)
async def send_video(message: Message, filepath: Path, title: Optional[str] = None, *args, **kwargs):
"""Универсальная функция - принимает любые аргументы"""
try:
with open(filepath, 'rb') as video_file:
await message.reply_video(
video=video_file,
caption=title or "Видео",
supports_streaming=True,
parse_mode=ParseMode.HTML,
**kwargs # ✅ принимает любые доп. аргументы
)
except TelegramError as e:
logger.error(f"Ошибка отправки видео: {e}")
await message.reply_text("❌ Ошибка при отправке видео")
async def send_audio(message: Message, filepath: Path, title: Optional[str] = None, *args, **kwargs):
try:
with open(filepath, 'rb') as audio_file:
await message.reply_audio(
audio=audio_file,
title=title or "Аудио",
parse_mode=ParseMode.HTML,
**kwargs
)
except TelegramError as e:
logger.error(f"Ошибка отправки аудио: {e}")
await message.reply_text("❌ Ошибка при отправке аудио")
async def send_document(message: Message, filepath: Path, *args, **kwargs):
try:
with open(filepath, 'rb') as doc_file:
await message.reply_document(
document=doc_file,
**kwargs
)
except TelegramError as e:
logger.error(f"Ошибка отправки документа: {e}")
await message.reply_text("❌ Ошибка при отправке документа")
async def send_photo(message: Message, filepath: Path, *args, **kwargs):
try:
with open(filepath, 'rb') as photo_file:
await message.reply_photo(
photo=photo_file,
**kwargs
)
except TelegramError as e:
logger.error(f"Ошибка отправки фото: {e}")
await message.reply_text("❌ Ошибка при отправке фото")