Support autocast to InputMessage

This commit is contained in:
Lonami Exo
2018-04-23 11:05:38 +02:00
parent 6ecef42ec7
commit f31ca142a3
6 changed files with 25 additions and 19 deletions

View File

@@ -25,7 +25,7 @@ from .tl.types import (
InputPhotoEmpty, FileLocation, ChatPhotoEmpty, UserProfilePhotoEmpty,
FileLocationUnavailable, InputMediaUploadedDocument, ChannelFull,
InputMediaUploadedPhoto, DocumentAttributeFilename, photos,
TopPeer, InputNotifyPeer
TopPeer, InputNotifyPeer, InputMessageID
)
from .tl.types.contacts import ResolvedPeer
@@ -333,6 +333,21 @@ def get_input_media(media, is_photo=False):
_raise_cast_fail(media, 'InputMedia')
def get_input_message(message):
"""Similar to :meth:`get_input_peer`, but for input messages."""
try:
if isinstance(message, int): # This case is really common too
return InputMessageID(message)
elif message.SUBCLASS_OF_ID == 0x54b6bcc5: # crc32(b'InputMessage'):
return message
elif message.SUBCLASS_OF_ID == 0x790009e3: # crc32(b'Message'):
return InputMessageID(message.id)
except AttributeError:
pass
_raise_cast_fail(message, 'InputMedia')
def is_image(file):
"""
Returns ``True`` if the file extension looks like an image file to Telegram.