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]