From 6015a14182644b57f76560e74006cdbac4af0574 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:36:38 +0200 Subject: [PATCH] Add ability to edit photos by uploading new files --- .../methods/messages/edit_message_media.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 56295749..dfee76a8 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -16,8 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api import functions +import os + +from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient +from pyrogram.client.types import ( + InputMediaPhoto +) class EditMessageMedia(BaseClient): @@ -26,11 +31,33 @@ class EditMessageMedia(BaseClient): message_id: int, media, reply_markup=None): + style = self.html if media.parse_mode.lower() == "html" else self.markdown + caption = media.caption + + if isinstance(media, InputMediaPhoto): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedPhoto( + file=self.save_file(media.media) + ) + ) + ) + + media = types.InputMediaPhoto( + id=types.InputPhoto( + id=media.photo.id, + access_hash=media.photo.access_hash + ) + ) + r = self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), id=message_id, reply_markup=reply_markup.write() if reply_markup else None, - media=media + media=media, + **style.parse(caption) ) )