mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2021-05-13 03:08:02 +03:00
new: InputMediaAnimation, InputMediaAudio, InputMediaDocument, editMessageMedia
Added support for editing the media content of messages: added the method editMessageMedia and new types InputMediaAnimation, InputMediaAudio, and InputMediaDocument.
This commit is contained in:
102
telebot/types.py
102
telebot/types.py
@@ -2073,48 +2073,56 @@ class MaskPosition(JsonDeserializable, JsonSerializable):
|
||||
|
||||
# InputMedia
|
||||
|
||||
class InputMediaPhoto(JsonSerializable):
|
||||
def __init__(self, media, caption=None, parse_mode=None):
|
||||
self.type = "photo"
|
||||
class InputMedia(JsonSerializable):
|
||||
def __init__(self, type, media, caption=None, parse_mode=None):
|
||||
self.type = type
|
||||
self.media = media
|
||||
self.caption = caption
|
||||
self.parse_mode = parse_mode
|
||||
|
||||
self._media_dic = 'attach://' + util.generate_random_token() if not util.is_string(self.media) else self.media
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_dic())
|
||||
|
||||
def to_dic(self):
|
||||
ret = {'type': self.type, 'media': 'attach://' + util.generate_random_token()
|
||||
if not util.is_string(self.media) else self.media}
|
||||
ret = {'type': self.type, 'media': self._media_dic}
|
||||
if self.caption:
|
||||
ret['caption'] = self.caption
|
||||
if self.parse_mode:
|
||||
ret['parse_mode'] = self.parse_mode
|
||||
return ret
|
||||
|
||||
def _convert_input_media(self):
|
||||
if util.is_string(self.media):
|
||||
return self.to_json(), None
|
||||
|
||||
class InputMediaVideo(JsonSerializable):
|
||||
def __init__(self, media, caption=None, parse_mode=None, width=None, height=None, duration=None,
|
||||
return self.to_json(), {self._media_dic: self.media}
|
||||
|
||||
|
||||
class InputMediaPhoto(InputMedia):
|
||||
def __init__(self, media, caption=None, parse_mode=None):
|
||||
super(InputMedia).__init__(type="photo", media=media, caption=caption, parse_mode=parse_mode)
|
||||
|
||||
def to_dic(self):
|
||||
ret = super(InputMedia).to_dic()
|
||||
return ret
|
||||
|
||||
|
||||
class InputMediaVideo(InputMedia):
|
||||
def __init__(self, media, thumb=None, caption=None, parse_mode=None, width=None, height=None, duration=None,
|
||||
supports_streaming=None):
|
||||
self.type = "video"
|
||||
self.media = media
|
||||
self.caption = caption
|
||||
self.parse_mode = parse_mode
|
||||
super(InputMedia).__init__(type="video", media=media, caption=caption, parse_mode=parse_mode)
|
||||
self.thumb = thumb
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.duration = duration
|
||||
self.supports_streaming = supports_streaming
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_dic())
|
||||
|
||||
def to_dic(self):
|
||||
ret = {'type': self.type, 'media': 'attach://' + util.generate_random_token()
|
||||
if not util.is_string(self.media) else self.media}
|
||||
if self.caption:
|
||||
ret['caption'] = self.caption
|
||||
if self.parse_mode:
|
||||
ret['parse_mode'] = self.parse_mode
|
||||
ret = super(InputMedia).to_dic()
|
||||
if self.thumb:
|
||||
ret['thumb'] = self.thumb
|
||||
if self.width:
|
||||
ret['width'] = self.width
|
||||
if self.height:
|
||||
@@ -2124,3 +2132,57 @@ class InputMediaVideo(JsonSerializable):
|
||||
if self.supports_streaming:
|
||||
ret['supports_streaming'] = self.supports_streaming
|
||||
return ret
|
||||
|
||||
|
||||
class InputMediaAnimation(InputMedia):
|
||||
def __init__(self, media, thumb=None, caption=None, parse_mode=None, width=None, height=None, duration=None):
|
||||
super(InputMedia).__init__(type="animation", media=media, caption=caption, parse_mode=parse_mode)
|
||||
self.thumb = thumb
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.duration = duration
|
||||
|
||||
def to_dic(self):
|
||||
ret = super(InputMedia).to_dic()
|
||||
if self.thumb:
|
||||
ret['thumb'] = self.thumb
|
||||
if self.width:
|
||||
ret['width'] = self.width
|
||||
if self.height:
|
||||
ret['height'] = self.height
|
||||
if self.duration:
|
||||
ret['duration'] = self.duration
|
||||
return ret
|
||||
|
||||
|
||||
class InputMediaAudio(InputMedia):
|
||||
def __init__(self, media, thumb=None, caption=None, parse_mode=None, duration=None, performer=None, title=None):
|
||||
super(InputMedia).__init__(type="audio", media=media, caption=caption, parse_mode=parse_mode)
|
||||
self.thumb = thumb
|
||||
self.duration = duration
|
||||
self.performer = performer
|
||||
self.title = title
|
||||
|
||||
def to_dic(self):
|
||||
ret = super(InputMedia).to_dic()
|
||||
if self.thumb:
|
||||
ret['thumb'] = self.thumb
|
||||
if self.duration:
|
||||
ret['duration'] = self.duration
|
||||
if self.performer:
|
||||
ret['performer'] = self.performer
|
||||
if self.title:
|
||||
ret['title'] = self.title
|
||||
return ret
|
||||
|
||||
|
||||
class InputMediaDocument(InputMedia):
|
||||
def __init__(self, media, thumb=None, caption=None, parse_mode=None):
|
||||
super(InputMedia).__init__(type="document", media=media, caption=caption, parse_mode=parse_mode)
|
||||
self.thumb = thumb
|
||||
|
||||
def to_dic(self):
|
||||
ret = super(InputMedia).to_dic()
|
||||
if self.thumb:
|
||||
ret['thumb'] = self.thumb
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user