mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-29 03:32:49 +01:00
Refactoring InlineQueryResultPhoto #232
This commit is contained in:
parent
7231eaa349
commit
ec27edef58
1 changed files with 23 additions and 68 deletions
|
@ -20,96 +20,51 @@
|
||||||
"""This module contains the classes that represent Telegram
|
"""This module contains the classes that represent Telegram
|
||||||
InlineQueryResultPhoto"""
|
InlineQueryResultPhoto"""
|
||||||
|
|
||||||
from telegram import InlineQueryResult
|
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||||
from telegram.utils.validate import validate_string
|
InputMessageContent
|
||||||
|
|
||||||
|
|
||||||
class InlineQueryResultPhoto(InlineQueryResult):
|
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,
|
def __init__(self,
|
||||||
id,
|
id,
|
||||||
photo_url,
|
photo_url,
|
||||||
thumb_url,
|
thumb_url,
|
||||||
mime_type=None,
|
|
||||||
photo_width=None,
|
photo_width=None,
|
||||||
photo_height=None,
|
photo_height=None,
|
||||||
title=None,
|
title=None,
|
||||||
description=None,
|
description=None,
|
||||||
caption=None,
|
caption=None,
|
||||||
message_text=None,
|
reply_markup=None,
|
||||||
parse_mode=None,
|
input_message_content=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')
|
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super(InlineQueryResultPhoto, self).__init__('photo', id)
|
super(InlineQueryResultPhoto, self).__init__('photo', id)
|
||||||
self.photo_url = photo_url
|
self.photo_url = photo_url
|
||||||
self.thumb_url = thumb_url
|
self.thumb_url = thumb_url
|
||||||
|
|
||||||
# Optional
|
# Optionals
|
||||||
self.mime_type = mime_type
|
if photo_width:
|
||||||
if photo_width is not None:
|
|
||||||
self.photo_width = int(photo_width)
|
self.photo_width = int(photo_width)
|
||||||
if photo_height is not None:
|
if photo_height:
|
||||||
self.photo_height = int(photo_height)
|
self.photo_height = int(photo_height)
|
||||||
self.title = title
|
if title:
|
||||||
self.description = description
|
self.title = title
|
||||||
self.caption = caption
|
if description:
|
||||||
self.message_text = message_text
|
self.description = description
|
||||||
self.parse_mode = parse_mode
|
if caption:
|
||||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
self.caption = caption
|
||||||
|
if reply_markup:
|
||||||
|
self.reply_markup = reply_markup
|
||||||
|
if input_message_content:
|
||||||
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data):
|
||||||
"""
|
data = super(InlineQueryResultPhoto,
|
||||||
Args:
|
InlineQueryResultPhoto).de_json(data)
|
||||||
data (dict):
|
|
||||||
|
|
||||||
Returns:
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||||
telegram.InlineQueryResultPhoto:
|
data.get('reply_markup'))
|
||||||
"""
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
if not data:
|
data.get('input_message_content'))
|
||||||
return None
|
|
||||||
|
|
||||||
return InlineQueryResultPhoto(**data)
|
return InlineQueryResultPhoto(**data)
|
||||||
|
|
Loading…
Reference in a new issue