From 1a5a7a3210ea508cca374e3b58a01dd905172d16 Mon Sep 17 00:00:00 2001 From: udf Date: Mon, 26 Nov 2018 19:58:35 +0200 Subject: [PATCH] fix image extension error and copy target caption --- stdplugins/kbass_file_to_photo.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/stdplugins/kbass_file_to_photo.py b/stdplugins/kbass_file_to_photo.py index f267cab..9cf65e4 100644 --- a/stdplugins/kbass_file_to_photo.py +++ b/stdplugins/kbass_file_to_photo.py @@ -3,13 +3,17 @@ Reply to a file with .f to send it as a photo """ from io import BytesIO -from stdplugins.kbass_core import self_reply_cmd +from uniborg import util + from telethon import types from telethon.errors import PhotoInvalidDimensionsError +from telethon.tl.functions.messages import SendMediaRequest -@self_reply_cmd(borg, r"^\.f$") -async def on_file_to_photo(event, target): +@borg.on(util.admin_cmd(r"^\.f$")) +async def on_file_to_photo(event): + await event.delete() + target = await event.get_reply_message() try: image = target.media.document except AttributeError: @@ -24,11 +28,15 @@ async def on_file_to_photo(event, target): file = await borg.download_media(target, file=BytesIO()) file.seek(0) img = await borg.upload_file(file) + img.name = 'image.png' try: - await event.respond( - reply_to=target, - file=types.InputMediaUploadedPhoto(img) - ) + await borg(SendMediaRequest( + peer=await event.get_input_chat(), + media=types.InputMediaUploadedPhoto(img), + message=target.message, + entities=target.entities, + reply_to_msg_id=target.id + )) except PhotoInvalidDimensionsError: return