mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-30 05:48:14 +00:00
Add ability to edit photos by uploading new files
This commit is contained in:
parent
e7b27c2c21
commit
6015a14182
@ -16,8 +16,13 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from pyrogram.api import functions
|
import os
|
||||||
|
|
||||||
|
from pyrogram.api import functions, types
|
||||||
from pyrogram.client.ext import BaseClient
|
from pyrogram.client.ext import BaseClient
|
||||||
|
from pyrogram.client.types import (
|
||||||
|
InputMediaPhoto
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditMessageMedia(BaseClient):
|
class EditMessageMedia(BaseClient):
|
||||||
@ -26,11 +31,33 @@ class EditMessageMedia(BaseClient):
|
|||||||
message_id: int,
|
message_id: int,
|
||||||
media,
|
media,
|
||||||
reply_markup=None):
|
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(
|
r = self.send(
|
||||||
functions.messages.EditMessage(
|
functions.messages.EditMessage(
|
||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
id=message_id,
|
id=message_id,
|
||||||
reply_markup=reply_markup.write() if reply_markup else None,
|
reply_markup=reply_markup.write() if reply_markup else None,
|
||||||
media=media
|
media=media,
|
||||||
|
**style.parse(caption)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user