From 6dc069afd95d1cedbad20ed0d71040e5b107b07f Mon Sep 17 00:00:00 2001 From: udf Date: Sat, 3 Aug 2019 17:41:48 +0200 Subject: [PATCH] Send html file when message is too long --- stdplugins/info.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/stdplugins/info.py b/stdplugins/info.py index d6eddb1..441c0ad 100644 --- a/stdplugins/info.py +++ b/stdplugins/info.py @@ -4,8 +4,9 @@ from telethon import events from telethon.utils import add_surrogate -from telethon.tl.types import MessageEntityPre +from telethon.tl.types import MessageEntityPre, DocumentAttributeFilename from telethon.tl.tlobject import TLObject +from telethon.errors import MessageTooLongError import datetime STR_LEN_MAX = 256 @@ -91,4 +92,16 @@ async def _(event): return msg = await event.message.get_reply_message() yaml_text = yaml_format(msg) - await event.edit(yaml_text, parse_mode=parse_pre) + try: + await event.edit(yaml_text, parse_mode=parse_pre) + except MessageTooLongError: + await event.delete() + await borg.send_file( + await event.get_input_chat(), + f'
{yaml_text}
'.encode('utf-8'), + reply_to=msg, + attributes=[ + DocumentAttributeFilename('info.html') + ], + allow_cache=False + )