mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-29 15:49:02 +01:00
parent
5a37af6f89
commit
08d298eb60
70 changed files with 343 additions and 295 deletions
|
@ -37,8 +37,8 @@ class TelegramObject(object):
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.__dict__[item]
|
return self.__dict__[item]
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
|
|
@ -2581,11 +2581,11 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(Bot, Bot).de_json(data, bot)
|
data = super(Bot, cls).de_json(data, bot)
|
||||||
|
|
||||||
return Bot(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
data = {'id': self.id, 'username': self.username, 'first_name': self.username}
|
data = {'id': self.id, 'username': self.username, 'first_name': self.username}
|
||||||
|
|
|
@ -46,8 +46,8 @@ class CallbackQuery(TelegramObject):
|
||||||
|
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -60,12 +60,12 @@ class CallbackQuery(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(CallbackQuery, CallbackQuery).de_json(data, bot)
|
data = super(CallbackQuery, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['message'] = Message.de_json(data.get('message'), bot)
|
data['message'] = Message.de_json(data.get('message'), bot)
|
||||||
|
|
||||||
return CallbackQuery(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -78,8 +78,8 @@ class Chat(TelegramObject):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -93,7 +93,7 @@ class Chat(TelegramObject):
|
||||||
|
|
||||||
data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
|
data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
|
||||||
|
|
||||||
return Chat(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def send_action(self, *args, **kwargs):
|
def send_action(self, *args, **kwargs):
|
||||||
"""Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``"""
|
"""Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
|
|
@ -98,8 +98,8 @@ class ChatMember(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.user, self.status)
|
self._id_attrs = (self.user, self.status)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -111,12 +111,12 @@ class ChatMember(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(ChatMember, ChatMember).de_json(data, bot)
|
data = super(ChatMember, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['user'] = User.de_json(data.get('user'), bot)
|
data['user'] = User.de_json(data.get('user'), bot)
|
||||||
data['until_date'] = from_timestamp(data.get('until_date', None))
|
data['until_date'] = from_timestamp(data.get('until_date', None))
|
||||||
|
|
||||||
return ChatMember(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -64,8 +64,8 @@ class ChosenInlineResult(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.result_id,)
|
self._id_attrs = (self.result_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -77,13 +77,13 @@ class ChosenInlineResult(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(ChosenInlineResult, ChosenInlineResult).de_json(data, bot)
|
data = super(ChosenInlineResult, cls).de_json(data, bot)
|
||||||
# Required
|
# Required
|
||||||
data['from_user'] = User.de_json(data.pop('from'), bot)
|
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||||
# Optionals
|
# Optionals
|
||||||
data['location'] = Location.de_json(data.get('location'), bot)
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return ChosenInlineResult(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -62,8 +62,8 @@ class Audio(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -75,4 +75,4 @@ class Audio(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Audio(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -39,8 +39,8 @@ class ChatPhoto(TelegramObject):
|
||||||
self.small_file_id = small_file_id
|
self.small_file_id = small_file_id
|
||||||
self.big_file_id = big_file_id
|
self.big_file_id = big_file_id
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -52,4 +52,4 @@ class ChatPhoto(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ChatPhoto(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
|
@ -49,8 +49,8 @@ class Contact(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.phone_number,)
|
self._id_attrs = (self.phone_number,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -62,4 +62,4 @@ class Contact(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Contact(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -60,8 +60,8 @@ class Document(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -73,8 +73,8 @@ class Document(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Document, Document).de_json(data, bot)
|
data = super(Document, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Document(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -53,8 +53,8 @@ class File(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -66,7 +66,7 @@ class File(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return File(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def download(self, custom_path=None, out=None, timeout=None):
|
def download(self, custom_path=None, out=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -40,8 +40,8 @@ class Location(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.longitude, self.latitude)
|
self._id_attrs = (self.longitude, self.latitude)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -53,4 +53,4 @@ class Location(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Location(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -50,8 +50,8 @@ class PhotoSize(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -63,10 +63,10 @@ class PhotoSize(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return PhotoSize(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
@ -80,6 +80,6 @@ class PhotoSize(TelegramObject):
|
||||||
|
|
||||||
photos = list()
|
photos = list()
|
||||||
for photo in data:
|
for photo in data:
|
||||||
photos.append(PhotoSize.de_json(photo, bot))
|
photos.append(cls.de_json(photo, bot))
|
||||||
|
|
||||||
return photos
|
return photos
|
||||||
|
|
|
@ -74,8 +74,8 @@ class Sticker(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (:obj:`dict`):
|
data (:obj:`dict`):
|
||||||
|
@ -87,19 +87,19 @@ class Sticker(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Sticker, Sticker).de_json(data, bot)
|
data = super(Sticker, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
data['mask_position'] = MaskPosition.de_json(data.get('mask_position'), bot)
|
data['mask_position'] = MaskPosition.de_json(data.get('mask_position'), bot)
|
||||||
|
|
||||||
return Sticker(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
return [Sticker.de_json(d, bot) for d in data]
|
return [cls.de_json(d, bot) for d in data]
|
||||||
|
|
||||||
|
|
||||||
class StickerSet(TelegramObject):
|
class StickerSet(TelegramObject):
|
||||||
|
@ -190,9 +190,9 @@ class MaskPosition(TelegramObject):
|
||||||
self.y_shift = y_shift
|
self.y_shift = y_shift
|
||||||
self.zoom = zoom
|
self.zoom = zoom
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
if data is None:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return MaskPosition(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -42,13 +42,13 @@ class Venue(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.location, self.title)
|
self._id_attrs = (self.location, self.title)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(Venue, Venue).de_json(data, bot)
|
data = super(Venue, cls).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['location'] = Location.de_json(data.get('location'), bot)
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return Venue(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -67,8 +67,8 @@ class Video(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -80,8 +80,8 @@ class Video(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Video, Video).de_json(data, bot)
|
data = super(Video, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Video(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -43,8 +43,8 @@ class VideoNote(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -56,8 +56,8 @@ class VideoNote(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(VideoNote, VideoNote).de_json(data, bot)
|
data = super(VideoNote, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return VideoNote(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -50,8 +50,8 @@ class Voice(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -63,6 +63,6 @@ class Voice(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Voice, Voice).de_json(data, bot)
|
data = super(Voice, cls).de_json(data, bot)
|
||||||
|
|
||||||
return Voice(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -41,8 +41,8 @@ class ForceReply(ReplyMarkup):
|
||||||
# Optionals
|
# Optionals
|
||||||
self.selective = bool(selective)
|
self.selective = bool(selective)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -54,4 +54,4 @@ class ForceReply(ReplyMarkup):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ForceReply(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -50,21 +50,21 @@ class Animation(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.file_id,)
|
self._id_attrs = (self.file_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
bot (telegram.Bot):
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Game:
|
telegram.Animation:
|
||||||
"""
|
"""
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Animation, Animation).de_json(data, bot)
|
data = super(Animation, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Animation(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -59,8 +59,8 @@ class Game(TelegramObject):
|
||||||
self.text_entities = text_entities
|
self.text_entities = text_entities
|
||||||
self.animation = animation
|
self.animation = animation
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -73,13 +73,13 @@ class Game(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Game, Game).de_json(data, bot)
|
data = super(Game, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
|
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
|
||||||
data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
|
data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
|
||||||
data['animation'] = Animation.de_json(data.get('animation'), bot)
|
data['animation'] = Animation.de_json(data.get('animation'), bot)
|
||||||
|
|
||||||
return Game(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -36,21 +36,21 @@ class GameHighScore(TelegramObject):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.score = score
|
self.score = score
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
bot (telegram.Bot):
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Game:
|
telegram.GameHighScore:
|
||||||
"""
|
"""
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(GameHighScore, GameHighScore).de_json(data, bot)
|
data = super(GameHighScore, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['user'] = User.de_json(data.get('user'), bot)
|
data['user'] = User.de_json(data.get('user'), bot)
|
||||||
|
|
||||||
return GameHighScore(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -74,8 +74,8 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
self.callback_game = callback_game
|
self.callback_game = callback_game
|
||||||
self.pay = pay
|
self.pay = pay
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -84,20 +84,20 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
Returns:
|
Returns:
|
||||||
telegram.InlineKeyboardButton:
|
telegram.InlineKeyboardButton:
|
||||||
"""
|
"""
|
||||||
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data, bot)
|
data = super(InlineKeyboardButton, cls).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return InlineKeyboardButton(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
inline_keyboards = list()
|
inline_keyboards = list()
|
||||||
for inline_keyboard in data:
|
for inline_keyboard in data:
|
||||||
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard, bot))
|
inline_keyboards.append(cls.de_json(inline_keyboard, bot))
|
||||||
|
|
||||||
return inline_keyboards
|
return inline_keyboards
|
||||||
|
|
|
@ -38,8 +38,8 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
||||||
# Required
|
# Required
|
||||||
self.inline_keyboard = inline_keyboard
|
self.inline_keyboard = inline_keyboard
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -49,7 +49,7 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
||||||
telegram.InlineKeyboardMarkup:
|
telegram.InlineKeyboardMarkup:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data, bot)
|
data = super(InlineKeyboardMarkup, cls).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
@ -59,7 +59,7 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
||||||
for inline_keyboard in data['inline_keyboard']
|
for inline_keyboard in data['inline_keyboard']
|
||||||
]
|
]
|
||||||
|
|
||||||
return InlineKeyboardMarkup(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
data = super(InlineKeyboardMarkup, self).to_dict()
|
data = super(InlineKeyboardMarkup, self).to_dict()
|
||||||
|
|
|
@ -58,8 +58,8 @@ class InlineQuery(TelegramObject):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -68,7 +68,7 @@ class InlineQuery(TelegramObject):
|
||||||
Returns:
|
Returns:
|
||||||
telegram.InlineQuery:
|
telegram.InlineQuery:
|
||||||
"""
|
"""
|
||||||
data = super(InlineQuery, InlineQuery).de_json(data, bot)
|
data = super(InlineQuery, cls).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
@ -76,7 +76,7 @@ class InlineQuery(TelegramObject):
|
||||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['location'] = Location.de_json(data.get('location'), bot)
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return InlineQuery(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -42,7 +42,3 @@ class InlineQueryResult(TelegramObject):
|
||||||
self.id = str(id)
|
self.id = str(id)
|
||||||
|
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def de_json(data, bot):
|
|
||||||
return super(InlineQueryResult, InlineQueryResult).de_json(data, bot)
|
|
||||||
|
|
|
@ -92,12 +92,15 @@ class InlineQueryResultArticle(InlineQueryResult):
|
||||||
if thumb_height:
|
if thumb_height:
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data, bot)
|
data = super(InlineQueryResultArticle, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultArticle(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -84,12 +84,15 @@ class InlineQueryResultAudio(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data, bot)
|
data = super(InlineQueryResultAudio, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultAudio(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -69,12 +69,15 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data, bot)
|
data = super(InlineQueryResultCachedAudio, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedAudio(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -73,13 +73,15 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedDocument,
|
data = super(InlineQueryResultCachedDocument, cls).de_json(data, bot)
|
||||||
InlineQueryResultCachedDocument).de_json(data, bot)
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedDocument(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -69,12 +69,15 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data, bot)
|
data = super(InlineQueryResultCachedGif, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedGif(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -70,13 +70,15 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedMpeg4Gif,
|
data = super(InlineQueryResultCachedMpeg4Gif, cls).de_json(data, bot)
|
||||||
InlineQueryResultCachedMpeg4Gif).de_json(data, bot)
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedMpeg4Gif(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -73,12 +73,15 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data, bot)
|
data = super(InlineQueryResultCachedPhoto, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedPhoto(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -58,13 +58,15 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedSticker,
|
data = super(InlineQueryResultCachedSticker, cls).de_json(data, bot)
|
||||||
InlineQueryResultCachedSticker).de_json(data, bot)
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedSticker(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -72,12 +72,15 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data, bot)
|
data = super(InlineQueryResultCachedVideo, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedVideo(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -67,12 +67,15 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data, bot)
|
data = super(InlineQueryResultCachedVoice, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedVoice(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -82,12 +82,15 @@ class InlineQueryResultContact(InlineQueryResult):
|
||||||
if thumb_height:
|
if thumb_height:
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data, bot)
|
data = super(InlineQueryResultContact, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultContact(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -92,12 +92,15 @@ class InlineQueryResultDocument(InlineQueryResult):
|
||||||
if thumb_height:
|
if thumb_height:
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data, bot)
|
data = super(InlineQueryResultDocument, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultDocument(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -33,10 +33,13 @@ class InlineQueryResultGame(InlineQueryResult):
|
||||||
if reply_markup:
|
if reply_markup:
|
||||||
self.reply_markup = reply_markup
|
self.reply_markup = reply_markup
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultGame, InlineQueryResultGame).de_json(data, bot)
|
data = super(InlineQueryResultGame, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
|
|
||||||
return InlineQueryResultGame(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -89,12 +89,15 @@ class InlineQueryResultGif(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data, bot)
|
data = super(InlineQueryResultGif, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultGif(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -82,12 +82,15 @@ class InlineQueryResultLocation(InlineQueryResult):
|
||||||
if thumb_height:
|
if thumb_height:
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data, bot)
|
data = super(InlineQueryResultLocation, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultLocation(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -90,12 +90,15 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data, bot)
|
data = super(InlineQueryResultMpeg4Gif, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultMpeg4Gif(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -75,12 +75,15 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data, bot)
|
data = super(InlineQueryResultPhoto, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultPhoto(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -59,12 +59,15 @@ class InlineQueryResultVenue(InlineQueryResult):
|
||||||
if thumb_height:
|
if thumb_height:
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data, bot)
|
data = super(InlineQueryResultVenue, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVenue(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -62,12 +62,15 @@ class InlineQueryResultVideo(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data, bot)
|
data = super(InlineQueryResultVideo, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVideo(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -49,12 +49,15 @@ class InlineQueryResultVoice(InlineQueryResult):
|
||||||
if input_message_content:
|
if input_message_content:
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data, bot)
|
data = super(InlineQueryResultVoice, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'), bot)
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVoice(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -32,6 +32,6 @@ class InputContactMessageContent(InputMessageContent):
|
||||||
# Optionals
|
# Optionals
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
return InputContactMessageContent(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -30,6 +30,6 @@ class InputLocationMessageContent(InputMessageContent):
|
||||||
self.latitude = latitude
|
self.latitude = latitude
|
||||||
self.longitude = longitude
|
self.longitude = longitude
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
return InputLocationMessageContent(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -25,9 +25,9 @@ from telegram import TelegramObject
|
||||||
class InputMessageContent(TelegramObject):
|
class InputMessageContent(TelegramObject):
|
||||||
"""Base class for Telegram InputMessageContent Objects"""
|
"""Base class for Telegram InputMessageContent Objects"""
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(InputMessageContent, InputMessageContent).de_json(data, bot)
|
data = super(InputMessageContent, cls).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -32,6 +32,6 @@ class InputTextMessageContent(InputMessageContent):
|
||||||
self.parse_mode = parse_mode
|
self.parse_mode = parse_mode
|
||||||
self.disable_web_page_preview = disable_web_page_preview
|
self.disable_web_page_preview = disable_web_page_preview
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
return InputTextMessageContent(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -34,6 +34,6 @@ class InputVenueMessageContent(InputMessageContent):
|
||||||
# Optionals
|
# Optionals
|
||||||
self.foursquare_id = foursquare_id
|
self.foursquare_id = foursquare_id
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
return InputVenueMessageContent(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -40,20 +40,20 @@ class KeyboardButton(TelegramObject):
|
||||||
self.request_contact = request_contact
|
self.request_contact = request_contact
|
||||||
self.request_location = request_location
|
self.request_location = request_location
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return KeyboardButton(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
keyboards = list()
|
keyboards = list()
|
||||||
for keyboard in data:
|
for keyboard in data:
|
||||||
keyboards.append(KeyboardButton.de_json(keyboard, bot))
|
keyboards.append(cls.de_json(keyboard, bot))
|
||||||
|
|
||||||
return keyboards
|
return keyboards
|
||||||
|
|
|
@ -197,8 +197,8 @@ class Message(TelegramObject):
|
||||||
"""int: Short for :attr:`Message.chat.id`"""
|
"""int: Short for :attr:`Message.chat.id`"""
|
||||||
return self.chat.id
|
return self.chat.id
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -210,7 +210,7 @@ class Message(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Message, Message).de_json(data, bot)
|
data = super(Message, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['date'] = from_timestamp(data['date'])
|
data['date'] = from_timestamp(data['date'])
|
||||||
|
@ -240,7 +240,7 @@ class Message(TelegramObject):
|
||||||
data['invoice'] = Invoice.de_json(data.get('invoice'), bot)
|
data['invoice'] = Invoice.de_json(data.get('invoice'), bot)
|
||||||
data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot)
|
data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot)
|
||||||
|
|
||||||
return Message(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
if item in self.__dict__.keys():
|
if item in self.__dict__.keys():
|
||||||
|
|
|
@ -43,16 +43,19 @@ class MessageEntity(TelegramObject):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
data = super(MessageEntity, MessageEntity).de_json(data, bot)
|
data = super(MessageEntity, cls).de_json(data, bot)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
data['user'] = User.de_json(data.get('user'), bot)
|
data['user'] = User.de_json(data.get('user'), bot)
|
||||||
|
|
||||||
return MessageEntity(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
@ -65,7 +68,7 @@ class MessageEntity(TelegramObject):
|
||||||
|
|
||||||
entities = list()
|
entities = list()
|
||||||
for entity in data:
|
for entity in data:
|
||||||
entities.append(MessageEntity.de_json(entity, bot))
|
entities.append(cls.de_json(entity, bot))
|
||||||
|
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ class Invoice(TelegramObject):
|
||||||
self.currency = currency
|
self.currency = currency
|
||||||
self.total_amount = total_amount
|
self.total_amount = total_amount
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -55,4 +55,4 @@ class Invoice(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Invoice(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -34,8 +34,8 @@ class LabeledPrice(TelegramObject):
|
||||||
self.label = label
|
self.label = label
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -48,10 +48,10 @@ class LabeledPrice(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return LabeledPrice(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
@ -65,6 +65,6 @@ class LabeledPrice(TelegramObject):
|
||||||
|
|
||||||
labeled_prices = list()
|
labeled_prices = list()
|
||||||
for labeled_price in data:
|
for labeled_price in data:
|
||||||
labeled_prices.append(LabeledPrice.de_json(labeled_price, bot))
|
labeled_prices.append(cls.de_json(labeled_price, bot))
|
||||||
|
|
||||||
return labeled_prices
|
return labeled_prices
|
||||||
|
|
|
@ -39,8 +39,8 @@ class OrderInfo(TelegramObject):
|
||||||
self.email = email
|
self.email = email
|
||||||
self.shipping_address = shipping_address
|
self.shipping_address = shipping_address
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -50,10 +50,10 @@ class OrderInfo(TelegramObject):
|
||||||
telegram.OrderInfo:
|
telegram.OrderInfo:
|
||||||
"""
|
"""
|
||||||
if not data:
|
if not data:
|
||||||
return OrderInfo()
|
return cls()
|
||||||
|
|
||||||
data = super(OrderInfo, OrderInfo).de_json(data, bot)
|
data = super(OrderInfo, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
|
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
|
||||||
|
|
||||||
return OrderInfo(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -62,8 +62,8 @@ class PreCheckoutQuery(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -75,12 +75,12 @@ class PreCheckoutQuery(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(PreCheckoutQuery, PreCheckoutQuery).de_json(data, bot)
|
data = super(PreCheckoutQuery, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.pop('from'), bot)
|
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||||
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
|
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
|
||||||
|
|
||||||
return PreCheckoutQuery(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -46,8 +46,8 @@ class ShippingAddress(TelegramObject):
|
||||||
self._id_attrs = (self.country_code, self.state, self.city, self.street_line1,
|
self._id_attrs = (self.country_code, self.state, self.city, self.street_line1,
|
||||||
self.street_line2, self.post_code)
|
self.street_line2, self.post_code)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -59,4 +59,4 @@ class ShippingAddress(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ShippingAddress(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -42,8 +42,8 @@ class ShippingOption(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -55,11 +55,11 @@ class ShippingOption(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(ShippingOption, ShippingOption).de_json(data, bot)
|
data = super(ShippingOption, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['prices'] = LabeledPrice.de_list(data.get('prices'), bot)
|
data['prices'] = LabeledPrice.de_list(data.get('prices'), bot)
|
||||||
|
|
||||||
return ShippingOption(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -47,8 +47,8 @@ class ShippingQuery(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.id,)
|
self._id_attrs = (self.id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -60,12 +60,12 @@ class ShippingQuery(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(ShippingQuery, ShippingQuery).de_json(data, bot)
|
data = super(ShippingQuery, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.pop('from'), bot)
|
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||||
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
|
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
|
||||||
|
|
||||||
return ShippingQuery(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -58,8 +58,8 @@ class SuccessfulPayment(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)
|
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -71,7 +71,7 @@ class SuccessfulPayment(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(SuccessfulPayment, SuccessfulPayment).de_json(data, bot)
|
data = super(SuccessfulPayment, cls).de_json(data, bot)
|
||||||
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
|
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
|
||||||
|
|
||||||
return SuccessfulPayment(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -54,8 +54,8 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
||||||
self.one_time_keyboard = bool(one_time_keyboard)
|
self.one_time_keyboard = bool(one_time_keyboard)
|
||||||
self.selective = bool(selective)
|
self.selective = bool(selective)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -67,11 +67,11 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(ReplyKeyboardMarkup, ReplyKeyboardMarkup).de_json(data, bot)
|
data = super(ReplyKeyboardMarkup, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
|
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
|
||||||
|
|
||||||
return ReplyKeyboardMarkup(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
data = super(ReplyKeyboardMarkup, self).to_dict()
|
data = super(ReplyKeyboardMarkup, self).to_dict()
|
||||||
|
|
|
@ -46,8 +46,8 @@ class ReplyKeyboardRemove(ReplyMarkup):
|
||||||
# Optionals
|
# Optionals
|
||||||
self.selective = bool(selective)
|
self.selective = bool(selective)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -60,7 +60,7 @@ class ReplyKeyboardRemove(ReplyMarkup):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ReplyKeyboardRemove(**data)
|
return cls(**data)
|
||||||
|
|
||||||
|
|
||||||
class ReplyKeyboardHide(object):
|
class ReplyKeyboardHide(object):
|
||||||
|
|
|
@ -23,12 +23,4 @@ from telegram import TelegramObject
|
||||||
|
|
||||||
class ReplyMarkup(TelegramObject):
|
class ReplyMarkup(TelegramObject):
|
||||||
"""Base class for Telegram ReplyMarkup Objects"""
|
"""Base class for Telegram ReplyMarkup Objects"""
|
||||||
|
pass
|
||||||
@staticmethod
|
|
||||||
def de_json(data, bot):
|
|
||||||
data = super(ReplyMarkup, ReplyMarkup).de_json(data, bot)
|
|
||||||
|
|
||||||
if not data:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
|
@ -89,8 +89,8 @@ class Update(TelegramObject):
|
||||||
|
|
||||||
self._id_attrs = (self.update_id,)
|
self._id_attrs = (self.update_id,)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -102,7 +102,7 @@ class Update(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(Update, Update).de_json(data, bot)
|
data = super(Update, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['message'] = Message.de_json(data.get('message'), bot)
|
data['message'] = Message.de_json(data.get('message'), bot)
|
||||||
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
|
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
|
||||||
|
@ -115,7 +115,7 @@ class Update(TelegramObject):
|
||||||
data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
|
data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
|
||||||
data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)
|
data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)
|
||||||
|
|
||||||
return Update(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effective_user(self):
|
def effective_user(self):
|
||||||
|
|
|
@ -77,8 +77,8 @@ class User(TelegramObject):
|
||||||
return '%s %s' % (self.first_name, self.last_name)
|
return '%s %s' % (self.first_name, self.last_name)
|
||||||
return self.first_name
|
return self.first_name
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -90,9 +90,9 @@ class User(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(User, User).de_json(data, bot)
|
data = super(User, cls).de_json(data, bot)
|
||||||
|
|
||||||
return User(bot=bot, **data)
|
return cls(bot=bot, **data)
|
||||||
|
|
||||||
def get_profile_photos(self, *args, **kwargs):
|
def get_profile_photos(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -100,8 +100,8 @@ class User(TelegramObject):
|
||||||
"""
|
"""
|
||||||
return self.bot.get_user_profile_photos(self.id, *args, **kwargs)
|
return self.bot.get_user_profile_photos(self.id, *args, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_list(data, bot):
|
def de_list(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
@ -115,6 +115,6 @@ class User(TelegramObject):
|
||||||
|
|
||||||
users = list()
|
users = list()
|
||||||
for user in data:
|
for user in data:
|
||||||
users.append(User.de_json(user, bot))
|
users.append(cls.de_json(user, bot))
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
|
@ -39,8 +39,8 @@ class UserProfilePhotos(TelegramObject):
|
||||||
self.total_count = int(total_count)
|
self.total_count = int(total_count)
|
||||||
self.photos = photos
|
self.photos = photos
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -52,11 +52,11 @@ class UserProfilePhotos(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = super(UserProfilePhotos, UserProfilePhotos).de_json(data, bot)
|
data = super(UserProfilePhotos, cls).de_json(data, bot)
|
||||||
|
|
||||||
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
|
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
|
||||||
|
|
||||||
return UserProfilePhotos(**data)
|
return cls(**data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -58,8 +58,8 @@ class WebhookInfo(TelegramObject):
|
||||||
self.max_connections = max_connections
|
self.max_connections = max_connections
|
||||||
self.allowed_updates = allowed_updates
|
self.allowed_updates = allowed_updates
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def de_json(data, bot):
|
def de_json(cls, data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
@ -72,4 +72,4 @@ class WebhookInfo(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return WebhookInfo(**data)
|
return cls(**data)
|
||||||
|
|
|
@ -68,11 +68,11 @@ class AnimationTest(BaseTest, unittest.TestCase):
|
||||||
animation = telegram.Animation.de_json(self.json_dict, self._bot)
|
animation = telegram.Animation.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(animation.to_dict()))
|
self.assertTrue(self.is_dict(animation.to_dict()))
|
||||||
self.assertEqual(animation['file_id'], self.animation_file_id)
|
self.assertEqual(animation.file_id, self.animation_file_id)
|
||||||
self.assertEqual(animation['thumb'], self.thumb)
|
self.assertEqual(animation.thumb, self.thumb)
|
||||||
self.assertEqual(animation['file_name'], self.file_name)
|
self.assertEqual(animation.file_name, self.file_name)
|
||||||
self.assertEqual(animation['mime_type'], self.mime_type)
|
self.assertEqual(animation.mime_type, self.mime_type)
|
||||||
self.assertEqual(animation['file_size'], self.file_size)
|
self.assertEqual(animation.file_size, self.file_size)
|
||||||
|
|
||||||
def test_equality(self):
|
def test_equality(self):
|
||||||
a = telegram.Animation(self.animation_file_id)
|
a = telegram.Animation(self.animation_file_id)
|
||||||
|
|
Loading…
Reference in a new issue