diff --git a/telegram/bot.py b/telegram/bot.py index 933369465..99f908d2d 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -611,6 +611,107 @@ class Bot(TelegramObject): return url, data + @log + @message + def sendVenue(self, + chat_id, + latitude, + longitude, + title, + address, + foursquare_id=None, + **kwargs): + """ + Use this method to send information about a venue. + + Args: + chat_id: + Unique identifier for the target chat or username of the target + channel (in the format @channelusername). + latitude: + Latitude of the venue. + longitude: + Longitude of the venue. + title: + Name of the venue. + address: + Address of the venue. + foursquare_id: + Foursquare identifier of the venue. + disable_notification: + Sends the message silently. iOS users will not receive a + notification, Android users will receive a notification with no + sound. + reply_to_message_id: + If the message is a reply, ID of the original message. + reply_markup: + Additional interface options. A JSON-serialized object for an + inline keyboard, custom reply keyboard, instructions to hide + reply keyboard or to force a reply from the user. + + Returns: + A telegram.Message instance representing the message posted. + """ + + url = '%s/sendVenue' % self.base_url + + data = {'chat_id': chat_id, + 'latitude': latitude, + 'longitude': longitude, + 'address': address, + 'title': title} + + if foursquare_id: + data['foursquare_id'] = foursquare_id + + return url, data + + @log + @message + def sendContact(self, + chat_id, + phone_number, + first_name, + last_name=None, + **kwargs): + """ + Use this method to send phone contacts. + + Args: + chat_id: + Unique identifier for the target chat or username of the target + channel (in the format @channelusername). + phone_number: + Contact's phone number. + first_name: + Contact's first name. + last_name: + Contact's last name. + disable_notification: + Sends the message silently. iOS users will not receive a + notification, Android users will receive a notification with no + sound. + reply_to_message_id: + If the message is a reply, ID of the original message. + reply_markup: + Additional interface options. A JSON-serialized object for an + inline keyboard, custom reply keyboard, instructions to hide + reply keyboard or to force a reply from the user. + + Returns: + A telegram.Message instance representing the message posted. + """ + url = '%s/sendContact' % self.base_url + + data = {'chat_id': chat_id, + 'phone_number': phone_number, + 'first_name': first_name} + + if last_name: + data['last_name'] = last_name + + return url, data + @log @message def sendChatAction(self, diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index 6b08dbc59..b24255f26 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -77,7 +77,7 @@ def run_async(func): return async_func -class Dispatcher: +class Dispatcher(object): """ This class dispatches all kinds of updates to its registered handlers. @@ -131,7 +131,7 @@ class Dispatcher: if self.__stop_event.is_set(): self.logger.debug('orderly stopping') break - elif self.__stop_event.is_set(): + elif self.__exception_event.is_set(): self.logger.critical( 'stopping due to exception in another thread') break diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index d97cc2fd4..27171a948 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -43,7 +43,7 @@ from telegram.utils.webhookhandler import (WebhookServer, WebhookHandler) logging.getLogger(__name__).addHandler(NullHandler()) -class Updater: +class Updater(object): """ This class, which employs the Dispatcher class, provides a frontend to telegram.Bot to the programmer, so they can focus on coding the bot. Its diff --git a/telegram/inlinequeryresult.py b/telegram/inlinequeryresult.py index 58d1264b4..46daf7739 100644 --- a/telegram/inlinequeryresult.py +++ b/telegram/inlinequeryresult.py @@ -45,14 +45,4 @@ class InlineQueryResult(TelegramObject): @staticmethod def de_json(data): - """ - Args: - data (dict): - - Returns: - telegram.InlineQueryResult: - """ - if not data: - return None - - return InlineQueryResult(**data) + return super(InlineQueryResult, InlineQueryResult).de_json(data) diff --git a/telegram/inlinequeryresultarticle.py b/telegram/inlinequeryresultarticle.py index 88d803ab6..fbba73da3 100644 --- a/telegram/inlinequeryresultarticle.py +++ b/telegram/inlinequeryresultarticle.py @@ -20,8 +20,8 @@ """This module contains the classes that represent Telegram InlineQueryResultArticle""" -from telegram import InlineQueryResult -from telegram.utils.validate import validate_string +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultArticle(InlineQueryResult): @@ -30,9 +30,8 @@ class InlineQueryResultArticle(InlineQueryResult): Attributes: id (str): title (str): - message_text (str): - parse_mode (str): - disable_web_page_preview (bool): + input_message_content (telegram.InputMessageContent): + reply_markup (telegram.ReplyMarkup): url (str): hide_url (bool): description (str): @@ -43,11 +42,9 @@ class InlineQueryResultArticle(InlineQueryResult): Args: id (str): Unique identifier for this result, 1-64 Bytes title (str): - message_text (str): + reply_markup (telegram.ReplyMarkup): Keyword Args: - parse_mode (Optional[str]): - disable_web_page_preview (Optional[bool]): url (Optional[str]): hide_url (Optional[bool]): description (Optional[str]): @@ -59,51 +56,44 @@ class InlineQueryResultArticle(InlineQueryResult): def __init__(self, id, title, - message_text, - parse_mode=None, - disable_web_page_preview=None, + input_message_content, + reply_markup=None, url=None, hide_url=None, description=None, thumb_url=None, thumb_width=None, - thumb_height=None, - **kwargs): - - validate_string(title, 'title') - validate_string(message_text, 'message_text') - validate_string(url, 'url') - validate_string(description, 'description') - validate_string(thumb_url, 'thumb_url') - validate_string(parse_mode, 'parse_mode') + thumb_height=None): # Required super(InlineQueryResultArticle, self).__init__('article', id) self.title = title - self.message_text = message_text + self.input_message_content = input_message_content # Optional - self.parse_mode = parse_mode - self.disable_web_page_preview = bool(disable_web_page_preview) - self.url = url - self.hide_url = bool(hide_url) - self.description = description - self.thumb_url = thumb_url - if thumb_width is not None: - self.thumb_width = int(thumb_width) - if thumb_height is not None: - self.thumb_height = int(thumb_height) + if reply_markup: + self.reply_markup = reply_markup + if url: + self.url = url + if hide_url: + self.hide_url = hide_url + if description: + self.description = description + if thumb_url: + self.thumb_url = thumb_url + if thumb_width: + self.thumb_width = thumb_width + if thumb_height: + self.thumb_height = thumb_height @staticmethod def de_json(data): - """ - Args: - data (dict): + data = super(InlineQueryResultArticle, + InlineQueryResultArticle).de_json(data) - Returns: - telegram.InlineQueryResultArticle: - """ - if not data: - return None + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) return InlineQueryResultArticle(**data) diff --git a/telegram/inlinequeryresultaudio.py b/telegram/inlinequeryresultaudio.py index f3e34679b..1e868f394 100644 --- a/telegram/inlinequeryresultaudio.py +++ b/telegram/inlinequeryresultaudio.py @@ -20,7 +20,8 @@ """This module contains the classes that represent Telegram InlineQueryResultAudio""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultAudio(InlineQueryResult): @@ -38,10 +39,24 @@ class InlineQueryResultAudio(InlineQueryResult): self.audio_url = audio_url self.title = title - # Optional - self.performer = performer - self.audio_duration = audio_duration - if reply_markup is not None: - self.reply_markup = 'ReplyMarkup' # TODO - if input_message_content is not None: - self.input_message_content = 'InputMessageContent' + # Optionals + if performer: + self.performer = performer + if audio_duration: + self.audio_duration = audio_duration + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultAudio, + InlineQueryResultAudio).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultAudio(**data) diff --git a/telegram/inlinequeryresultcachedaudio.py b/telegram/inlinequeryresultcachedaudio.py index 67f0085d1..833f7f618 100644 --- a/telegram/inlinequeryresultcachedaudio.py +++ b/telegram/inlinequeryresultcachedaudio.py @@ -20,8 +20,34 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedAudio""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedAudio(InlineQueryResult): - pass + def __init__(self, + id, + audio_file_id, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedAudio, self).__init__('audio', id) + self.audio_file_id = audio_file_id + + # Optionals + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedAudio, + InlineQueryResultCachedAudio).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedAudio(**data) diff --git a/telegram/inlinequeryresultcacheddocument.py b/telegram/inlinequeryresultcacheddocument.py index c9670aa7f..441c7ea6b 100644 --- a/telegram/inlinequeryresultcacheddocument.py +++ b/telegram/inlinequeryresultcacheddocument.py @@ -20,8 +20,42 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedDocument""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedDocument(InlineQueryResult): - pass + def __init__(self, + id, + title, + document_file_id, + description=None, + caption=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedDocument, self).__init__('document', id) + self.title = title + self.document_file_id = document_file_id + + # Optionals + if description: + self.description = description + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedDocument, + InlineQueryResultCachedDocument).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedDocument(**data) diff --git a/telegram/inlinequeryresultcachedgif.py b/telegram/inlinequeryresultcachedgif.py index a431173c0..c5edac3fc 100644 --- a/telegram/inlinequeryresultcachedgif.py +++ b/telegram/inlinequeryresultcachedgif.py @@ -20,8 +20,40 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedGif""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedGif(InlineQueryResult): - pass + def __init__(self, + id, + gif_file_id, + title=None, + caption=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedGif, self).__init__('gif', id) + self.gif_file_id = gif_file_id + + # Optionals + if title: + self.title = title + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedGif, + InlineQueryResultCachedGif).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedGif(**data) diff --git a/telegram/inlinequeryresultcachedmpeg4gif.py b/telegram/inlinequeryresultcachedmpeg4gif.py index 2bf0aa03c..a9b4ab70f 100644 --- a/telegram/inlinequeryresultcachedmpeg4gif.py +++ b/telegram/inlinequeryresultcachedmpeg4gif.py @@ -20,8 +20,40 @@ """This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): - pass + def __init__(self, + id, + mpeg4_file_id, + title=None, + caption=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedMpeg4Gif, self).__init__('mpeg4_gif', id) + self.mpeg4_file_id = mpeg4_file_id + + # Optionals + if title: + self.title = title + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedMpeg4Gif, + InlineQueryResultCachedMpeg4Gif).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedMpeg4Gif(**data) diff --git a/telegram/inlinequeryresultcachedphoto.py b/telegram/inlinequeryresultcachedphoto.py index b931e65a1..a648a0b58 100644 --- a/telegram/inlinequeryresultcachedphoto.py +++ b/telegram/inlinequeryresultcachedphoto.py @@ -20,8 +20,43 @@ """This module contains the classes that represent Telegram InlineQueryResultPhoto""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedPhoto(InlineQueryResult): - pass + def __init__(self, + id, + photo_file_id, + title=None, + description=None, + caption=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedPhoto, self).__init__('photo', id) + self.photo_file_id = photo_file_id + + # Optionals + if title: + self.title = title + if description: + self.description = description + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedPhoto, + InlineQueryResultCachedPhoto).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedPhoto(**data) diff --git a/telegram/inlinequeryresultcachedsticker.py b/telegram/inlinequeryresultcachedsticker.py index 57cb2c9c6..c9eeae0d1 100644 --- a/telegram/inlinequeryresultcachedsticker.py +++ b/telegram/inlinequeryresultcachedsticker.py @@ -20,8 +20,34 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedSticker""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedSticker(InlineQueryResult): - pass + def __init__(self, + id, + sticker_file_id, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedSticker, self).__init__('sticker', id) + self.sticker_file_id = sticker_file_id + + # Optionals + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedSticker, + InlineQueryResultCachedSticker).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedSticker(**data) diff --git a/telegram/inlinequeryresultcachedvideo.py b/telegram/inlinequeryresultcachedvideo.py index f6d5e98e5..b013b36ab 100644 --- a/telegram/inlinequeryresultcachedvideo.py +++ b/telegram/inlinequeryresultcachedvideo.py @@ -20,8 +20,42 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedVideo""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedVideo(InlineQueryResult): - pass + def __init__(self, + id, + video_file_id, + title, + description=None, + caption=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedVideo, self).__init__('video', id) + self.video_file_id = video_file_id + self.title = title + + # Optionals + if description: + self.description = description + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedVideo, + InlineQueryResultCachedVideo).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedVideo(**data) diff --git a/telegram/inlinequeryresultcachedvoice.py b/telegram/inlinequeryresultcachedvoice.py index 8058efca5..7afeda867 100644 --- a/telegram/inlinequeryresultcachedvoice.py +++ b/telegram/inlinequeryresultcachedvoice.py @@ -20,8 +20,39 @@ """This module contains the classes that represent Telegram InlineQueryResultCachedVoice""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultCachedVoice(InlineQueryResult): - pass + def __init__(self, + id, + voice_file_id, + title, + description=None, + reply_markup=None, + input_message_content=None): + # Required + super(InlineQueryResultCachedVoice, self).__init__('voice', id) + self.voice_file_id = voice_file_id + self.title = title + + # Optionals + if description: + self.description = description + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultCachedVoice, + InlineQueryResultCachedVoice).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultCachedVoice(**data) diff --git a/telegram/inlinequeryresultcontact.py b/telegram/inlinequeryresultcontact.py index e892a3b0a..acccbaff8 100644 --- a/telegram/inlinequeryresultcontact.py +++ b/telegram/inlinequeryresultcontact.py @@ -20,8 +20,48 @@ """This module contains the classes that represent Telegram InlineQueryResultContact""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultContact(InlineQueryResult): - pass + def __init__(self, + id, + phone_number, + first_name, + last_name=None, + reply_markup=None, + input_message_content=None, + thumb_url=None, + thumb_width=None, + thumb_height=None): + # Required + super(InlineQueryResultContact, self).__init__('contact', id) + self.phone_number = phone_number + self.first_name = first_name + + # Optionals + if last_name: + self.last_name = last_name + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + if thumb_url: + self.thumb_url = thumb_url + if thumb_width: + self.thumb_width = thumb_width + if thumb_height: + self.thumb_height = thumb_height + + @staticmethod + def de_json(data): + data = super(InlineQueryResultContact, + InlineQueryResultContact).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultContact(**data) diff --git a/telegram/inlinequeryresultdocument.py b/telegram/inlinequeryresultdocument.py index 8d42a034f..e2e3f1999 100644 --- a/telegram/inlinequeryresultdocument.py +++ b/telegram/inlinequeryresultdocument.py @@ -20,8 +20,53 @@ """This module contains the classes that represent Telegram InlineQueryResultDocument""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultDocument(InlineQueryResult): - pass + def __init__(self, + id, + document_url, + title, + mime_type, + caption=None, + description=None, + reply_markup=None, + input_message_content=None, + thumb_url=None, + thumb_width=None, + thumb_height=None): + # Required + super(InlineQueryResultDocument, self).__init__('document', id) + self.document_url = document_url + self.title = title + self.mime_type = mime_type + + # Optionals + if caption: + self.caption = caption + if description: + self.description = description + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + if thumb_url: + self.thumb_url = thumb_url + if thumb_width: + self.thumb_width = thumb_width + if thumb_height: + self.thumb_height = thumb_height + + @staticmethod + def de_json(data): + data = super(InlineQueryResultDocument, + InlineQueryResultDocument).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultDocument(**data) diff --git a/telegram/inlinequeryresultgif.py b/telegram/inlinequeryresultgif.py index 62f563625..8ea2ee2f0 100644 --- a/telegram/inlinequeryresultgif.py +++ b/telegram/inlinequeryresultgif.py @@ -20,40 +20,11 @@ """This module contains the classes that represent Telegram InlineQueryResultGif""" -from telegram import InlineQueryResult -from telegram.utils.validate import validate_string +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultGif(InlineQueryResult): - """This object represents a Telegram InlineQueryResultGif. - - Attributes: - id (str): - gif_url (str): - gif_width (int): - gif_height (int): - thumb_url (str): - title (str): - caption (str): - message_text (str): - parse_mode (str): - disable_web_page_preview (bool): - - Args: - id (str): Unique identifier for this result, 1-64 Bytes - gif_url (str): - thumb_url (str): - - Keyword Args: - gif_width (Optional[int]): - gif_height (Optional[int]): - title (Optional[str]): - caption (Optional[str]): - message_text (Optional[str]): - parse_mode (Optional[str]): - disable_web_page_preview (Optional[bool]): - """ - def __init__(self, id, gif_url, @@ -62,44 +33,36 @@ class InlineQueryResultGif(InlineQueryResult): gif_height=None, title=None, caption=None, - message_text=None, - parse_mode=None, - disable_web_page_preview=None, - **kwargs): - - validate_string(gif_url, 'gif_url') - validate_string(thumb_url, 'thumb_url') - validate_string(title, 'title') - validate_string(caption, 'caption') - validate_string(message_text, 'message_text') - validate_string(parse_mode, 'parse_mode') + reply_markup=None, + input_message_content=None): # Required super(InlineQueryResultGif, self).__init__('gif', id) self.gif_url = gif_url self.thumb_url = thumb_url - # Optional - if gif_width is not None: - self.gif_width = int(gif_width) - if gif_height is not None: - self.gif_height = int(gif_height) - self.title = title - self.caption = caption - self.message_text = message_text - self.parse_mode = parse_mode - self.disable_web_page_preview = bool(disable_web_page_preview) + # Optionals + if gif_width: + self.gif_width = gif_width + if gif_height: + self.gif_height = gif_height + if title: + self.title = title + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content @staticmethod def de_json(data): - """ - Args: - data (dict): + data = super(InlineQueryResultGif, + InlineQueryResultGif).de_json(data) - Returns: - telegram.InlineQueryResultGif: - """ - if not data: - return None + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) return InlineQueryResultGif(**data) diff --git a/telegram/inlinequeryresultlocation.py b/telegram/inlinequeryresultlocation.py index 229ae3169..bb40f7a94 100644 --- a/telegram/inlinequeryresultlocation.py +++ b/telegram/inlinequeryresultlocation.py @@ -20,8 +20,47 @@ """This module contains the classes that represent Telegram InlineQueryResultLocation""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultLocation(InlineQueryResult): - pass + def __init__(self, + id, + latitude, + longitude, + title, + reply_markup=None, + input_message_content=None, + thumb_url=None, + thumb_width=None, + thumb_height=None): + # Required + super(InlineQueryResultLocation, self).__init__('location', id) + self.latitude = latitude + self.longitude = longitude + self.title = title + + # Optionals + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + if thumb_url: + self.thumb_url = thumb_url + if thumb_width: + self.thumb_width = thumb_width + if thumb_height: + self.thumb_height = thumb_height + + @staticmethod + def de_json(data): + data = super(InlineQueryResultLocation, + InlineQueryResultLocation).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultLocation(**data) diff --git a/telegram/inlinequeryresultmpeg4gif.py b/telegram/inlinequeryresultmpeg4gif.py index 73e5a08cd..c9cb5045f 100644 --- a/telegram/inlinequeryresultmpeg4gif.py +++ b/telegram/inlinequeryresultmpeg4gif.py @@ -20,40 +20,11 @@ """This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif""" -from telegram import InlineQueryResult -from telegram.utils.validate import validate_string +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultMpeg4Gif(InlineQueryResult): - """This object represents a Telegram InlineQueryResultMpeg4Gif. - - Attributes: - id (str): - mpeg4_url (str): - mpeg4_width (int): - mpeg4_height (int): - thumb_url (str): - title (str): - caption (str): - message_text (str): - parse_mode (str): - disable_web_page_preview (bool): - - Args: - id (str): Unique identifier for this result, 1-64 Bytes - mpeg4_url (str): - thumb_url (str): - - Keyword Args: - mpeg4_width (Optional[int]): - mpeg4_height (Optional[int]): - title (Optional[str]): - caption (Optional[str]): - message_text (Optional[str]): - parse_mode (Optional[str]): - disable_web_page_preview (Optional[bool]): - """ - def __init__(self, id, mpeg4_url, @@ -62,17 +33,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): mpeg4_height=None, title=None, caption=None, - message_text=None, - parse_mode=None, - disable_web_page_preview=None, - **kwargs): - - validate_string(mpeg4_url, 'mpeg4_url') - validate_string(thumb_url, 'thumb_url') - validate_string(title, 'title') - validate_string(caption, 'caption') - validate_string(message_text, 'message_text') - validate_string(parse_mode, 'parse_mode') + reply_markup=None, + input_message_content=None): # Required super(InlineQueryResultMpeg4Gif, self).__init__('mpeg4_gif', id) @@ -80,26 +42,27 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): self.thumb_url = thumb_url # Optional - if mpeg4_width is not None: - self.mpeg4_width = int(mpeg4_width) - if mpeg4_height is not None: - self.mpeg4_height = int(mpeg4_height) - self.title = title - self.caption = caption - self.message_text = message_text - self.parse_mode = parse_mode - self.disable_web_page_preview = bool(disable_web_page_preview) + if mpeg4_width: + self.mpeg4_width = mpeg4_width + if mpeg4_height: + self.mpeg4_height = mpeg4_height + if title: + self.title = title + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content @staticmethod def de_json(data): - """ - Args: - data (dict): + data = super(InlineQueryResultMpeg4Gif, + InlineQueryResultMpeg4Gif).de_json(data) - Returns: - telegram.InlineQueryResultMpeg4Gif: - """ - if not data: - return None + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) return InlineQueryResultMpeg4Gif(**data) diff --git a/telegram/inlinequeryresultphoto.py b/telegram/inlinequeryresultphoto.py index f9b6f94bc..bb8d147c1 100644 --- a/telegram/inlinequeryresultphoto.py +++ b/telegram/inlinequeryresultphoto.py @@ -20,96 +20,51 @@ """This module contains the classes that represent Telegram InlineQueryResultPhoto""" -from telegram import InlineQueryResult -from telegram.utils.validate import validate_string +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultPhoto(InlineQueryResult): - """This object represents a Telegram InlineQueryResultPhoto. - - Attributes: - id (str): - photo_url (str): - mime_type (str): - photo_width (int): - photo_height (int): - thumb_url (str): - title (str): - description (str): - caption (str): - message_text (str): - parse_mode (str): - disable_web_page_preview (bool): - - Args: - id (str): Unique identifier for this result, 1-64 Bytes - photo_url (str): - thumb_url (str): - - Keyword Args: - mime_type (Optional[str]): - photo_width (Optional[int]): - photo_height (Optional[int]): - title (Optional[str]): - description (Optional[str]): - caption (Optional[str]): - message_text (Optional[str]): - parse_mode (Optional[str]): - disable_web_page_preview (Optional[bool]): - """ - def __init__(self, id, photo_url, thumb_url, - mime_type=None, photo_width=None, photo_height=None, title=None, description=None, caption=None, - message_text=None, - parse_mode=None, - disable_web_page_preview=None, - **kwargs): - - validate_string(photo_url, 'photo_url') - validate_string(thumb_url, 'thumb_url') - validate_string(mime_type, 'mime_type') - validate_string(title, 'title') - validate_string(description, 'description') - validate_string(caption, 'caption') - validate_string(message_text, 'message_text') - validate_string(parse_mode, 'parse_mode') - + reply_markup=None, + input_message_content=None): # Required super(InlineQueryResultPhoto, self).__init__('photo', id) self.photo_url = photo_url self.thumb_url = thumb_url - # Optional - self.mime_type = mime_type - if photo_width is not None: + # Optionals + if photo_width: self.photo_width = int(photo_width) - if photo_height is not None: + if photo_height: self.photo_height = int(photo_height) - self.title = title - self.description = description - self.caption = caption - self.message_text = message_text - self.parse_mode = parse_mode - self.disable_web_page_preview = bool(disable_web_page_preview) + if title: + self.title = title + if description: + self.description = description + if caption: + self.caption = caption + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content @staticmethod def de_json(data): - """ - Args: - data (dict): + data = super(InlineQueryResultPhoto, + InlineQueryResultPhoto).de_json(data) - Returns: - telegram.InlineQueryResultPhoto: - """ - if not data: - return None + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) return InlineQueryResultPhoto(**data) diff --git a/telegram/inlinequeryresultvenue.py b/telegram/inlinequeryresultvenue.py index 6182d528d..c47102006 100644 --- a/telegram/inlinequeryresultvenue.py +++ b/telegram/inlinequeryresultvenue.py @@ -20,8 +20,53 @@ """This module contains the classes that represent Telegram InlineQueryResultVenue""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultVenue(InlineQueryResult): - pass + def __init__(self, + id, + latitude, + longitude, + title, + address, + foursquare_id=None, + reply_markup=None, + input_message_content=None, + thumb_url=None, + thumb_width=None, + thumb_height=None): + + # Required + super(InlineQueryResultVenue, self).__init__('venue', id) + self.latitude = latitude + self.longitude = longitude + self.title = title + self.address = address + + # Optional + if foursquare_id: + self.foursquare_id = foursquare_id + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + if thumb_url: + self.thumb_url = thumb_url + if thumb_width: + self.thumb_width = thumb_width + if thumb_height: + self.thumb_height = thumb_height + + @staticmethod + def de_json(data): + data = super(InlineQueryResultVenue, + InlineQueryResultVenue).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultVenue(**data) diff --git a/telegram/inlinequeryresultvideo.py b/telegram/inlinequeryresultvideo.py index 93e3c4706..6a0846701 100644 --- a/telegram/inlinequeryresultvideo.py +++ b/telegram/inlinequeryresultvideo.py @@ -20,70 +20,24 @@ """This module contains the classes that represent Telegram InlineQueryResultVideo""" -from telegram import InlineQueryResult -from telegram.utils.validate import validate_string +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultVideo(InlineQueryResult): - """This object represents a Telegram InlineQueryResultVideo. - - Attributes: - id (str): - video_url (str): - mime_type (str): - video_width (int): - video_height (int): - video_duration (int): - thumb_url (str): - title (str): - description (str): - caption (str): - message_text (str): - parse_mode (str): - disable_web_page_preview (bool): - - Args: - id (str): Unique identifier for this result, 1-64 Bytes - video_url (str): - mime_type (str): - thumb_url (str): - title (str): - message_text (str): - - Keyword Args: - video_width (Optional[int]): - video_height (Optional[int]): - video_duration (Optional[int]): - description (Optional[str]): - caption (Optional[str]): - parse_mode (Optional[str]): - disable_web_page_preview (Optional[bool]): - """ - def __init__(self, id, video_url, mime_type, thumb_url, title, - message_text, + caption=None, video_width=None, video_height=None, video_duration=None, description=None, - caption=None, - parse_mode=None, - disable_web_page_preview=None, - **kwargs): - - validate_string(video_url, 'video_url') - validate_string(mime_type, 'mime_type') - validate_string(thumb_url, 'thumb_url') - validate_string(title, 'title') - validate_string(message_text, 'message_text') - validate_string(description, 'description') - validate_string(caption, 'caption') - validate_string(parse_mode, 'parse_mode') + reply_markup=None, + input_message_content=None): # Required super(InlineQueryResultVideo, self).__init__('video', id) @@ -91,30 +45,31 @@ class InlineQueryResultVideo(InlineQueryResult): self.mime_type = mime_type self.thumb_url = thumb_url self.title = title - self.message_text = message_text # Optional - if video_width is not None: - self.video_width = int(video_width) - if video_height is not None: - self.video_height = int(video_height) - if video_duration is not None: - self.video_duration = int(video_duration) - self.description = description - self.caption = caption - self.parse_mode = parse_mode - self.disable_web_page_preview = bool(disable_web_page_preview) + if caption: + self.caption = caption + if video_width: + self.video_width = video_width + if video_height: + self.video_height = video_height + if video_duration: + self.video_duration = video_duration + if description: + self.description = description + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content @staticmethod def de_json(data): - """ - Args: - data (dict): + data = super(InlineQueryResultVideo, + InlineQueryResultVideo).de_json(data) - Returns: - telegram.InlineQueryResultVideo: - """ - if not data: - return None + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) return InlineQueryResultVideo(**data) diff --git a/telegram/inlinequeryresultvoice.py b/telegram/inlinequeryresultvoice.py index cf2059258..4bcae4bcd 100644 --- a/telegram/inlinequeryresultvoice.py +++ b/telegram/inlinequeryresultvoice.py @@ -20,8 +20,40 @@ """This module contains the classes that represent Telegram InlineQueryResultVoice""" -from telegram import InlineQueryResult +from telegram import InlineQueryResult, InlineKeyboardMarkup, \ + InputMessageContent class InlineQueryResultVoice(InlineQueryResult): - pass + def __init__(self, + id, + voice_url, + title, + voice_duration=None, + reply_markup=None, + input_message_content=None): + + # Required + super(InlineQueryResultVoice, self).__init__('voice', id) + self.voice_url = voice_url + self.title = title + + # Optional + if voice_duration: + self.voice_duration = voice_duration + if reply_markup: + self.reply_markup = reply_markup + if input_message_content: + self.input_message_content = input_message_content + + @staticmethod + def de_json(data): + data = super(InlineQueryResultVoice, + InlineQueryResultVoice).de_json(data) + + data['reply_markup'] = InlineKeyboardMarkup.de_json( + data.get('reply_markup')) + data['input_message_content'] = InputMessageContent.de_json( + data.get('input_message_content')) + + return InlineQueryResultVoice(**data) diff --git a/telegram/messageentity.py b/telegram/messageentity.py index f9b9b022b..a712cefa7 100644 --- a/telegram/messageentity.py +++ b/telegram/messageentity.py @@ -47,7 +47,7 @@ class MessageEntity(TelegramObject): self.url = url @staticmethod - def de_json(self): + def de_json(data): data = super(MessageEntity, MessageEntity).de_json(data) - return MessageEntity(**data) \ No newline at end of file + return MessageEntity(**data) diff --git a/telegram/venue.py b/telegram/venue.py index 14f73e1b7..b15503679 100644 --- a/telegram/venue.py +++ b/telegram/venue.py @@ -46,9 +46,9 @@ class Venue(TelegramObject): self.foursquare_id = foursquare_id @staticmethod - def de_json(self): + def de_json(data): data = super(Venue, Venue).de_json(data) data['location'] = Location.de_json(data.get('location')) - return Venue(**data) \ No newline at end of file + return Venue(**data) diff --git a/tests/test_updater.py b/tests/test_updater.py index 43ac956c2..078b9b322 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -632,7 +632,7 @@ class UpdaterTest(BaseTest, unittest.TestCase): self.assertRaises(ValueError, Updater) -class MockBot: +class MockBot(object): def __init__(self, text, messages=1, raise_error=False, bootstrap_retries=None, bootstrap_err=TelegramError('test')):