fix image extension error and copy target caption

This commit is contained in:
udf 2018-11-26 19:58:35 +02:00
parent ed18b3ccba
commit 1a5a7a3210
Signed by: kate
GPG Key ID: E40724BAD73AF77B
1 changed files with 15 additions and 7 deletions

View File

@ -3,13 +3,17 @@ Reply to a file with .f to send it as a photo
""" """
from io import BytesIO from io import BytesIO
from stdplugins.kbass_core import self_reply_cmd from uniborg import util
from telethon import types from telethon import types
from telethon.errors import PhotoInvalidDimensionsError from telethon.errors import PhotoInvalidDimensionsError
from telethon.tl.functions.messages import SendMediaRequest
@self_reply_cmd(borg, r"^\.f$") @borg.on(util.admin_cmd(r"^\.f$"))
async def on_file_to_photo(event, target): async def on_file_to_photo(event):
await event.delete()
target = await event.get_reply_message()
try: try:
image = target.media.document image = target.media.document
except AttributeError: except AttributeError:
@ -24,11 +28,15 @@ async def on_file_to_photo(event, target):
file = await borg.download_media(target, file=BytesIO()) file = await borg.download_media(target, file=BytesIO())
file.seek(0) file.seek(0)
img = await borg.upload_file(file) img = await borg.upload_file(file)
img.name = 'image.png'
try: try:
await event.respond( await borg(SendMediaRequest(
reply_to=target, peer=await event.get_input_chat(),
file=types.InputMediaUploadedPhoto(img) media=types.InputMediaUploadedPhoto(img),
) message=target.message,
entities=target.entities,
reply_to_msg_id=target.id
))
except PhotoInvalidDimensionsError: except PhotoInvalidDimensionsError:
return return