forked from uniborg/uniborg
fix image extension error and copy target caption
This commit is contained in:
parent
ed18b3ccba
commit
1a5a7a3210
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue