From adc19dee8c543ad69554dc3da0cedf8ed7bcc50e Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 7 Mar 2026 22:55:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=B2=D1=8B=D1=81=D0=BE=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BA=D0=B0=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B5=20?= =?UTF-8?q?=D0=B2=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=BE=D0=B2=D0=BE=D0=B9?= =?UTF-8?q?=20=D1=87=D0=B0=D1=82.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BB=D0=B8=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B8=20=D0=BA=20=D1=84?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=20=D0=B2=20Telegram.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tg/handlers/default.py | 5 +++-- tg/handlers/private.py | 3 ++- tg/utils.py | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tg/handlers/default.py b/tg/handlers/default.py index ed26d14..6fe1165 100644 --- a/tg/handlers/default.py +++ b/tg/handlers/default.py @@ -85,8 +85,9 @@ async def any_message_handler(message: Message, bot: Bot): interval=4) if answer.image is not None: - answer_id = (await message.reply_photo(photo=wrap_photo(answer.image), caption=answer.text)).message_id - await message.answer_document(document=wrap_document(answer.image_hires, 'image', 'png')) + answer_id = (await message.reply_photo(photo=wrap_photo(answer.image), + caption=trim_caption(answer.text))).message_id + await message.reply_document(document=wrap_document(answer.image_hires, 'image', 'png')) else: answer_id = (await message.reply(answer.text)).message_id if success: diff --git a/tg/handlers/private.py b/tg/handlers/private.py index 0ac9d46..c69240c 100644 --- a/tg/handlers/private.py +++ b/tg/handlers/private.py @@ -60,7 +60,8 @@ async def any_message_handler(message: Message, bot: Bot): interval=4) if answer.image is not None: - answer_id = (await message.answer_photo(photo=wrap_photo(answer.image), caption=answer.text)).message_id + answer_id = (await message.answer_photo(photo=wrap_photo(answer.image), + caption=trim_caption(answer.text))).message_id await message.answer_document(document=wrap_document(answer.image_hires, 'image', 'png')) else: answer_id = (await message.answer(answer.text)).message_id diff --git a/tg/utils.py b/tg/utils.py index 1085885..4f0c854 100644 --- a/tg/utils.py +++ b/tg/utils.py @@ -60,3 +60,7 @@ def wrap_photo(image: bytes) -> BufferedInputFile: def wrap_document(document: bytes, name_prefix: str, extension: str) -> BufferedInputFile: name = "{}_{}.{}".format(name_prefix, datetime.now().strftime("%Y%m%d_%H%M%S"), extension) return BufferedInputFile(document, name) + + +def trim_caption(caption: str) -> str: + return caption[:1024]