add finders

This commit is contained in:
smolkik-code
2025-12-26 23:26:13 +07:00
parent f49db9adf6
commit d77e00f029
32 changed files with 681 additions and 330 deletions

41
bot/telegram_send.py Normal file
View File

@@ -0,0 +1,41 @@
from pathlib import Path
from telegram import Message
async def send_video(message: Message, filepath: Path, connect_timeout: int, read_timeout: int):
with filepath.open('rb') as f:
await message.chat.send_video(
video=f,
supports_streaming=True,
connect_timeout=connect_timeout,
read_timeout=read_timeout
)
async def send_audio(message: Message, filepath: Path, title: str | None, connect_timeout: int, read_timeout: int):
with filepath.open('rb') as f:
await message.chat.send_audio(
audio=f,
title=title,
connect_timeout=connect_timeout,
read_timeout=read_timeout
)
async def send_document(message: Message, filepath: Path, connect_timeout: int, read_timeout: int):
with filepath.open('rb') as f:
await message.chat.send_document(
document=f,
filename=filepath.name,
connect_timeout=connect_timeout,
read_timeout=read_timeout
)
async def send_photo(message: Message, filepath: Path, connect_timeout: int, read_timeout: int):
# Фото до ~20MB лучше отправлять как фото, большие — как документ
if filepath.stat().st_size <= 20 * 1024 * 1024:
with filepath.open('rb') as f:
await message.chat.send_photo(
photo=f,
connect_timeout=connect_timeout,
read_timeout=read_timeout
)
else:
await send_document(message, filepath, connect_timeout, read_timeout)