diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 548f1c5b..b27f0397 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -143,6 +143,7 @@ Bots send_game set_game_score get_game_high_scores + answer_inline_query .. autoclass:: pyrogram.Client diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst index 396f14c7..4fe01873 100644 --- a/docs/source/pyrogram/Types.rst +++ b/docs/source/pyrogram/Types.rst @@ -79,8 +79,16 @@ Inline Mode .. autosummary:: :nosignatures: + InlineQuery InlineQueryResult InlineQueryResultArticle + +InputMessageContent +------------------- + +.. autosummary:: + :nosignatures: + InputMessageContent InputTextMessageContent @@ -229,12 +237,18 @@ Inline Mode .. Inline Mode ----------- +.. autoclass:: InlineQuery + :members: + .. autoclass:: InlineQueryResult :members: .. autoclass:: InlineQueryResultArticle :members: +.. InputMessageContent + ------------------- + .. autoclass:: InputMessageContent :members: diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c723dae7..d8f96c66 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -38,10 +38,10 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery, InlineQueryResult, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, - InlineQueryResultCachedAudio, InputMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, - ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll, PollOption, ChatPreview, StopPropagation, ContinuePropagation, - Game, CallbackGame, GameHighScore, GameHighScores, ChatPermissions + InlineQuery, InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputTextMessageContent, + InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll, + PollOption, ChatPreview, StopPropagation, ContinuePropagation, Game, CallbackGame, GameHighScore, GameHighScores, + ChatPermissions ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/methods/bots/answer_inline_query.py b/pyrogram/client/methods/bots/answer_inline_query.py index 49328d40..7b3524b2 100644 --- a/pyrogram/client/methods/bots/answer_inline_query.py +++ b/pyrogram/client/methods/bots/answer_inline_query.py @@ -16,22 +16,65 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import List + from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient +from ...types.inline_mode import InlineQueryResult class AnswerInlineQuery(BaseClient): def answer_inline_query( self, inline_query_id: str, - results: list, + results: List[InlineQueryResult], cache_time: int = 300, is_personal: bool = None, next_offset: str = "", switch_pm_text: str = "", switch_pm_parameter: str = "" ): - # TODO: Docs + """Use this method to send answers to an inline query. + No more than 50 results per query are allowed. + + Args: + inline_query_id (``str``): + Unique identifier for the answered query. + + results (List of :obj:`InlineQueryResult `): + A list of results for the inline query. + + cache_time (``int``, *optional*): + The maximum amount of time in seconds that the result of the inline query may be cached on the server. + Defaults to 300. + + is_personal (``bool``, *optional*): + Pass True, if results may be cached on the server side only for the user that sent the query. + By default, results may be returned to any user who sends the same query. + + next_offset (``str``, *optional*): + Pass the offset that a client should send in the next query with the same text to receive more results. + Pass an empty string if there are no more results or if you don‘t support pagination. + Offset length can’t exceed 64 bytes. + + switch_pm_text (``str``, *optional*): + If passed, clients will display a button with specified text that switches the user to a private chat + with the bot and sends the bot a start message with the parameter switch_pm_parameter + + switch_pm_parameter (``str``, *optional*): + `Deep-linking `_ parameter for the /start message sent to + the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. + + Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube + account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account" + button above the results, or even before showing any. The user presses the button, switches to a private + chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth + link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat + where they wanted to use the bot's inline capabilities. + + Returns: + On success, True is returned. + """ return self.send( functions.messages.SetInlineBotResults( query_id=int(inline_query_id), diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 197acf2c..e51a8413 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,19 +16,20 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .bots import ( - CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, InlineQueryResult, - InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio -) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame, - GameHighScore, GameHighScores + GameHighScore, GameHighScores, CallbackQuery +) +from .inline_mode import ( + InlineQuery, InlineQueryResult, InlineQueryResultArticle ) from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, - InputMediaDocument, InputMediaAnimation, InputMessageContent, InputTextMessageContent + InputMediaDocument, InputMediaAnimation +) +from .input_message_content import ( + InputMessageContent, InputTextMessageContent ) from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, diff --git a/pyrogram/client/types/bots/__init__.py b/pyrogram/client/types/bots/__init__.py index c87cb712..81767945 100644 --- a/pyrogram/client/types/bots/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -23,28 +23,6 @@ from .game_high_score import GameHighScore from .game_high_scores import GameHighScores from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup -from .inline_query import InlineQuery -from .inline_query_result import InlineQueryResult -from .inline_query_result_article import InlineQueryResultArticle -from .inline_query_result_audio import InlineQueryResultAudio -from .inline_query_result_cached_audio import InlineQueryResultCachedAudio -from .inline_query_result_cached_document import InlineQueryResultCachedDocument -from .inline_query_result_cached_gif import InlineQueryResultCachedGif -from .inline_query_result_cached_mpeg4_gif import InlineQueryResultCachedMpeg4Gif -from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto -from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker -from .inline_query_result_cached_video import InlineQueryResultCachedVideo -from .inline_query_result_cached_voice import InlineQueryResultCachedVoice -from .inline_query_result_contact import InlineQueryResultContact -from .inline_query_result_document import InlineQueryResultDocument -from .inline_query_result_game import InlineQueryResultGame -from .inline_query_result_gif import InlineQueryResultGif -from .inline_query_result_location import InlineQueryResultLocation -from .inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif -from .inline_query_result_photo import InlineQueryResultPhoto -from .inline_query_result_venue import InlineQueryResultVenue -from .inline_query_result_video import InlineQueryResultVideo -from .inline_query_result_voice import InlineQueryResultVoice from .keyboard_button import KeyboardButton from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove diff --git a/pyrogram/client/types/inline_mode/__init__.py b/pyrogram/client/types/inline_mode/__init__.py new file mode 100644 index 00000000..a7cb93d3 --- /dev/null +++ b/pyrogram/client/types/inline_mode/__init__.py @@ -0,0 +1,21 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .inline_query import InlineQuery +from .inline_query_result import InlineQueryResult +from .inline_query_result_article import InlineQueryResultArticle diff --git a/pyrogram/client/types/bots/inline_query.py b/pyrogram/client/types/inline_mode/inline_query.py similarity index 53% rename from pyrogram/client/types/bots/inline_query.py rename to pyrogram/client/types/inline_mode/inline_query.py index 3c311468..9c1c02ac 100644 --- a/pyrogram/client/types/bots/inline_query.py +++ b/pyrogram/client/types/inline_mode/inline_query.py @@ -20,15 +20,16 @@ from typing import List import pyrogram from pyrogram.api import types -from ..bots.inline_query_result import InlineQueryResult +from .inline_query_result import InlineQueryResult from ..messages_and_media import Location from ..pyrogram_type import PyrogramType +from ..update import Update from ..user_and_chats import User -class InlineQuery(PyrogramType): +class InlineQuery(PyrogramType, Update): """This object represents an incoming inline query. - When the user sends an empty query, your bot could return some default or trending results + When the user sends an empty query, your bot could return some default or trending results. Args: id (``str``): @@ -50,6 +51,7 @@ class InlineQuery(PyrogramType): def __init__( self, + *, client: "pyrogram.client.ext.BaseClient", id: str, from_user: User, @@ -69,7 +71,6 @@ class InlineQuery(PyrogramType): @staticmethod def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery": return InlineQuery( - client=client, id=str(inline_query.query_id), from_user=User._parse(client, users[inline_query.user_id]), query=inline_query.query, @@ -78,7 +79,8 @@ class InlineQuery(PyrogramType): longitude=inline_query.geo.long, latitude=inline_query.geo.lat, client=client - ) if inline_query.geo else None + ) if inline_query.geo else None, + client=client ) def answer( @@ -90,6 +92,55 @@ class InlineQuery(PyrogramType): switch_pm_text: str = "", switch_pm_parameter: str = "" ): + """Bound method *answer* of :obj:`InlineQuery `. + + Use this method as a shortcut for: + + .. code-block:: python + + client.answer_inline_query( + inline_query.id, + results=[...] + ) + + Example: + .. code-block:: python + + inline_query.answer([...]) + + Args: + results (List of :obj:`InlineQueryResult `): + A list of results for the inline query. + + cache_time (``int``, *optional*): + The maximum amount of time in seconds that the result of the inline query may be cached on the server. + Defaults to 300. + + is_personal (``bool``, *optional*): + Pass True, if results may be cached on the server side only for the user that sent the query. + By default, results may be returned to any user who sends the same query. + + next_offset (``str``, *optional*): + Pass the offset that a client should send in the next query with the same text to receive more results. + Pass an empty string if there are no more results or if you don‘t support pagination. + Offset length can’t exceed 64 bytes. + + switch_pm_text (``str``, *optional*): + If passed, clients will display a button with specified text that switches the user to a private chat + with the bot and sends the bot a start message with the parameter switch_pm_parameter + + switch_pm_parameter (``str``, *optional*): + `Deep-linking `_ parameter for the /start message sent to + the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. + + Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube + account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account" + button above the results, or even before showing any. The user presses the button, switches to a private + chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth + link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat + where they wanted to use the bot's inline capabilities. + """ + return self._client.answer_inline_query( inline_query_id=self.id, results=results, diff --git a/pyrogram/client/types/bots/inline_query_result.py b/pyrogram/client/types/inline_mode/inline_query_result.py similarity index 86% rename from pyrogram/client/types/bots/inline_query_result.py rename to pyrogram/client/types/inline_mode/inline_query_result.py index 7c4c0c30..3e7fcb02 100644 --- a/pyrogram/client/types/bots/inline_query_result.py +++ b/pyrogram/client/types/inline_mode/inline_query_result.py @@ -16,12 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from ..pyrogram_type import PyrogramType -class InlineQueryResult: - """This object represents one result of an inline query. - Pyrogram currently supports results of the following 20 types: - - - :obj:`InlineQueryResultCachedAudio` +"""- :obj:`InlineQueryResultCachedAudio` - :obj:`InlineQueryResultCachedDocument` - :obj:`InlineQueryResultCachedGif` - :obj:`InlineQueryResultCachedMpeg4Gif` @@ -29,7 +26,6 @@ class InlineQueryResult: - :obj:`InlineQueryResultCachedSticker` - :obj:`InlineQueryResultCachedVideo` - :obj:`InlineQueryResultCachedVoice` - - :obj:`InlineQueryResultArticle` - :obj:`InlineQueryResultAudio` - :obj:`InlineQueryResultContact` - :obj:`InlineQueryResultGame` @@ -40,9 +36,24 @@ class InlineQueryResult: - :obj:`InlineQueryResultPhoto` - :obj:`InlineQueryResultVenue` - :obj:`InlineQueryResultVideo` - - :obj:`InlineQueryResultVoice` + - :obj:`InlineQueryResultVoice`""" + + +class InlineQueryResult(PyrogramType): + """This object represents one result of an inline query. + + Pyrogram currently supports results of the following 20 types: + + - :obj:`InlineQueryResultArticle` """ + __slots__ = ["type", "id"] + def __init__(self, type: str, id: str): + super().__init__(None) + self.type = type self.id = id + + def write(self): + pass diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/inline_mode/inline_query_result_article.py similarity index 77% rename from pyrogram/client/types/bots/inline_query_result_article.py rename to pyrogram/client/types/inline_mode/inline_query_result_article.py index 6325e174..7916dba5 100644 --- a/pyrogram/client/types/bots/inline_query_result_article.py +++ b/pyrogram/client/types/inline_mode/inline_query_result_article.py @@ -32,40 +32,44 @@ class InlineQueryResultArticle(InlineQueryResult): title (``str``): Title for the result. - input_message_content (``TODO``): + input_message_content (:obj:`InputMessageContent `): Content of the message to be sent. reply_markup (:obj:`InlineKeyboardMarkup `, *optional*): - Inline keyboard attached to the message + Inline keyboard attached to the message. url (``str``, *optional*): - URL of the result + URL of the result. - description (``str``, optional): - Short description of the result + description (``str``, *optional*): + Short description of the result. - thumb_url (``str``, optional): - Url of the thumbnail for the result + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. thumb_width (``int``, *optional*): Thumbnail width. thumb_height (``int``, *optional*): Thumbnail height. - """ + __slots__ = [ + "title", "input_message_content", "reply_markup", "url", "description", "thumb_url", "thumb_width", + "thumb_height" + ] + def __init__( - self, - id: str, - title: str, - input_message_content, - reply_markup=None, - url: str = None, - description: str = None, - thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + self, + id: str, + title: str, + input_message_content, + reply_markup=None, + url: str = None, + description: str = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 ): super().__init__("article", id) diff --git a/pyrogram/client/types/bots/inline_query_result_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_audio.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py index f8b21be8..a67163c6 100644 --- a/pyrogram/client/types/bots/inline_query_result_audio.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultAudio(Object): +class InlineQueryResultAudio(PyrogramType): """Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. Attributes: @@ -57,7 +57,6 @@ class InlineQueryResultAudio(Object): Content of the message to be sent instead of the audio. """ - ID = 0xb0700004 def __init__(self, type: str, id: str, audio_url: str, title: str, caption: str = None, parse_mode: str = None, performer: str = None, audio_duration: int = None, reply_markup=None, input_message_content=None): self.type = type # string diff --git a/pyrogram/client/types/bots/inline_query_result_cached_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py similarity index 92% rename from pyrogram/client/types/bots/inline_query_result_cached_audio.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py index c2e1779d..1f3a1963 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_audio.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py @@ -23,9 +23,10 @@ from pyrogram.api import types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import utils, BaseClient from pyrogram.client.style import HTML, Markdown +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedAudio: +class InlineQueryResultCachedAudio(PyrogramType): """Represents a link to an audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use *input_message_content* to send a message with the specified content instead of the audio. @@ -53,13 +54,13 @@ class InlineQueryResultCachedAudio: """ def __init__( - self, - id: str, - audio_file_id: str, - caption: str = "", - parse_mode: str = "", - reply_markup=None, - input_message_content=None + self, + id: str, + audio_file_id: str, + caption: str = "", + parse_mode: str = "", + reply_markup=None, + input_message_content=None ): self.id = id self.audio_file_id = audio_file_id diff --git a/pyrogram/client/types/bots/inline_query_result_cached_document.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_cached_document.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py index cf9a3012..ab1637d2 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_document.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedDocument(Object): +class InlineQueryResultCachedDocument(PyrogramType): """Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_cached_gif.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py index 2ecca3a8..4c457873 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedGif(Object): +class InlineQueryResultCachedGif(PyrogramType): """Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py index caa9a478..93ec1efb 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedMpeg4Gif(Object): +class InlineQueryResultCachedMpeg4Gif(PyrogramType): """Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_cached_photo.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py index e18117f5..ee6b2654 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_photo.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedPhoto(Object): +class InlineQueryResultCachedPhoto(PyrogramType): """Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_sticker.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py similarity index 94% rename from pyrogram/client/types/bots/inline_query_result_cached_sticker.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py index 6f381d39..6142b1fa 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_sticker.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedSticker(Object): +class InlineQueryResultCachedSticker(PyrogramType): """Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_cached_video.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py index 5eb5c745..8c00c61a 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_video.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedVideo(Object): +class InlineQueryResultCachedVideo(PyrogramType): """Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_cached_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py similarity index 95% rename from pyrogram/client/types/bots/inline_query_result_cached_voice.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py index 47962ba6..741df389 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_voice.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultCachedVoice(Object): +class InlineQueryResultCachedVoice(PyrogramType): """Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_contact.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_contact.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py index 4e1b85d5..e26af4ea 100644 --- a/pyrogram/client/types/bots/inline_query_result_contact.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultContact(Object): +class InlineQueryResultContact(PyrogramType): """Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_document.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py similarity index 97% rename from pyrogram/client/types/bots/inline_query_result_document.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_document.py index 47b3fff4..93b8fcae 100644 --- a/pyrogram/client/types/bots/inline_query_result_document.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultDocument(Object): +class InlineQueryResultDocument(PyrogramType): """Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_game.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py similarity index 93% rename from pyrogram/client/types/bots/inline_query_result_game.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_game.py index cc965c7c..3e7cfb73 100644 --- a/pyrogram/client/types/bots/inline_query_result_game.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultGame(Object): +class InlineQueryResultGame(PyrogramType): """Represents a Game. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_gif.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py index 8ce701d9..13f4fc18 100644 --- a/pyrogram/client/types/bots/inline_query_result_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultGif(Object): +class InlineQueryResultGif(PyrogramType): """Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_location.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_location.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_location.py index 4a6c1401..176591d2 100644 --- a/pyrogram/client/types/bots/inline_query_result_location.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultLocation(Object): +class InlineQueryResultLocation(PyrogramType): """Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py index 10778def..37aa8986 100644 --- a/pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultMpeg4Gif(Object): +class InlineQueryResultMpeg4Gif(PyrogramType): """Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py similarity index 97% rename from pyrogram/client/types/bots/inline_query_result_photo.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py index 1cc3af7e..2ba7c312 100644 --- a/pyrogram/client/types/bots/inline_query_result_photo.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py @@ -18,9 +18,10 @@ from pyrogram.api import types from pyrogram.client.style import HTML, Markdown +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultPhoto: +class InlineQueryResultPhoto(PyrogramType): """Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. diff --git a/pyrogram/client/types/bots/inline_query_result_venue.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py similarity index 97% rename from pyrogram/client/types/bots/inline_query_result_venue.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py index 69e47f2d..23ddfc35 100644 --- a/pyrogram/client/types/bots/inline_query_result_venue.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultVenue(Object): +class InlineQueryResultVenue(PyrogramType): """Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py similarity index 97% rename from pyrogram/client/types/bots/inline_query_result_video.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_video.py index c7a3627e..9b1723e1 100644 --- a/pyrogram/client/types/bots/inline_query_result_video.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultVideo(Object): +class InlineQueryResultVideo(PyrogramType): """Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. Attributes: diff --git a/pyrogram/client/types/bots/inline_query_result_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py similarity index 96% rename from pyrogram/client/types/bots/inline_query_result_voice.py rename to pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py index 04edac6e..188063ec 100644 --- a/pyrogram/client/types/bots/inline_query_result_voice.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +from pyrogram.client.types.pyrogram_type import PyrogramType -class InlineQueryResultVoice(Object): +class InlineQueryResultVoice(PyrogramType): """Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message. Attributes: diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py index b8ce832c..e2e0b0f6 100644 --- a/pyrogram/client/types/input_media/__init__.py +++ b/pyrogram/client/types/input_media/__init__.py @@ -22,6 +22,4 @@ from .input_media_audio import InputMediaAudio from .input_media_document import InputMediaDocument from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo -from .input_message_content import InputMessageContent from .input_phone_contact import InputPhoneContact -from .input_text_message_content import InputTextMessageContent diff --git a/pyrogram/client/types/input_message_content/__init__.py b/pyrogram/client/types/input_message_content/__init__.py new file mode 100644 index 00000000..39081574 --- /dev/null +++ b/pyrogram/client/types/input_message_content/__init__.py @@ -0,0 +1,20 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .input_message_content import InputMessageContent +from .input_text_message_content import InputTextMessageContent diff --git a/pyrogram/client/types/input_media/input_message_content.py b/pyrogram/client/types/input_message_content/input_message_content.py similarity index 83% rename from pyrogram/client/types/input_media/input_message_content.py rename to pyrogram/client/types/input_message_content/input_message_content.py index 1479bf63..f3e238b8 100644 --- a/pyrogram/client/types/input_media/input_message_content.py +++ b/pyrogram/client/types/input_message_content/input_message_content.py @@ -16,17 +16,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from ..pyrogram_type import PyrogramType -class InputMessageContent: +"""- :obj:`InputLocationMessageContent` + - :obj:`InputVenueMessageContent` + - :obj:`InputContactMessageContent`""" + + +class InputMessageContent(PyrogramType): """This object represents the content of a message to be sent as a result of an inline query. Pyrogram currently supports the following 4 types: - :obj:`InputTextMessageContent` - - :obj:`InputLocationMessageContent` - - :obj:`InputVenueMessageContent` - - :obj:`InputContactMessageContent` """ + __slots__ = [] + def __init__(self): - pass + super().__init__(None) diff --git a/pyrogram/client/types/input_media/input_text_message_content.py b/pyrogram/client/types/input_message_content/input_text_message_content.py similarity index 57% rename from pyrogram/client/types/input_media/input_text_message_content.py rename to pyrogram/client/types/input_message_content/input_text_message_content.py index 3c74d34d..0e6ffa8b 100644 --- a/pyrogram/client/types/input_media/input_text_message_content.py +++ b/pyrogram/client/types/input_message_content/input_text_message_content.py @@ -17,20 +17,38 @@ # along with Pyrogram. If not, see . from pyrogram.api import types -from pyrogram.client.style import HTML, Markdown +from .input_message_content import InputMessageContent +from ...style import HTML, Markdown -class InputTextMessageContent: +class InputTextMessageContent(InputMessageContent): + """This object represents the content of a text message to be sent as the result of an inline query. + + Args: + message_text (``str``): + Text of the message to be sent, 1-4096 characters. + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your message. + Defaults to Markdown. + + disable_web_page_preview (``bool``, *optional*): + Disables link previews for links in this message. + """ + + __slots__ = ["message_text", "parse_mode", "disable_web_page_preview"] + def __init__(self, message_text: str, parse_mode: str = "", disable_web_page_preview: bool = None): + super().__init__() + self.message_text = message_text self.parse_mode = parse_mode self.disable_web_page_preview = disable_web_page_preview - self.style = HTML() if parse_mode.lower() == "html" else Markdown() - def write(self, reply_markup): return types.InputBotInlineMessageText( no_webpage=self.disable_web_page_preview or None, reply_markup=reply_markup.write() if reply_markup else None, - **self.style.parse(self.message_text) + **(HTML() if self.parse_mode.lower() == "html" else Markdown()).parse(self.message_text) )