Clean up inline-mode

This commit is contained in:
Dan 2019-03-22 11:35:35 +01:00
parent fede74398c
commit bc9f902376
33 changed files with 287 additions and 121 deletions

View File

@ -143,6 +143,7 @@ Bots
send_game send_game
set_game_score set_game_score
get_game_high_scores get_game_high_scores
answer_inline_query
.. autoclass:: pyrogram.Client .. autoclass:: pyrogram.Client

View File

@ -79,8 +79,16 @@ Inline Mode
.. autosummary:: .. autosummary::
:nosignatures: :nosignatures:
InlineQuery
InlineQueryResult InlineQueryResult
InlineQueryResultArticle InlineQueryResultArticle
InputMessageContent
-------------------
.. autosummary::
:nosignatures:
InputMessageContent InputMessageContent
InputTextMessageContent InputTextMessageContent
@ -229,12 +237,18 @@ Inline Mode
.. Inline Mode .. Inline Mode
----------- -----------
.. autoclass:: InlineQuery
:members:
.. autoclass:: InlineQueryResult .. autoclass:: InlineQueryResult
:members: :members:
.. autoclass:: InlineQueryResultArticle .. autoclass:: InlineQueryResultArticle
:members: :members:
.. InputMessageContent
-------------------
.. autoclass:: InputMessageContent .. autoclass:: InputMessageContent
:members: :members:

View File

@ -38,10 +38,10 @@ from .client.types import (
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
InlineQuery, InlineQueryResult, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, InlineQuery, InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputTextMessageContent,
InlineQueryResultCachedAudio, InputMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll,
ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll, PollOption, ChatPreview, StopPropagation, ContinuePropagation, PollOption, ChatPreview, StopPropagation, ContinuePropagation, Game, CallbackGame, GameHighScore, GameHighScores,
Game, CallbackGame, GameHighScore, GameHighScores, ChatPermissions ChatPermissions
) )
from .client import ( from .client import (
Client, ChatAction, ParseMode, Emoji, Client, ChatAction, ParseMode, Emoji,

View File

@ -16,22 +16,65 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
from ...types.inline_mode import InlineQueryResult
class AnswerInlineQuery(BaseClient): class AnswerInlineQuery(BaseClient):
def answer_inline_query( def answer_inline_query(
self, self,
inline_query_id: str, inline_query_id: str,
results: list, results: List[InlineQueryResult],
cache_time: int = 300, cache_time: int = 300,
is_personal: bool = None, is_personal: bool = None,
next_offset: str = "", next_offset: str = "",
switch_pm_text: str = "", switch_pm_text: str = "",
switch_pm_parameter: 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 <pyrogram.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 dont support pagination.
Offset length cant 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 <https://core.telegram.org/bots#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( return self.send(
functions.messages.SetInlineBotResults( functions.messages.SetInlineBotResults(
query_id=int(inline_query_id), query_id=int(inline_query_id),

View File

@ -16,19 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .bots import (
CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, InlineQueryResult,
InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio
)
from .bots import ( from .bots import (
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame,
GameHighScore, GameHighScores GameHighScore, GameHighScores, CallbackQuery
)
from .inline_mode import (
InlineQuery, InlineQueryResult, InlineQueryResultArticle
) )
from .input_media import ( from .input_media import (
InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto,
InputMediaDocument, InputMediaAnimation, InputMessageContent, InputTextMessageContent InputMediaDocument, InputMediaAnimation
)
from .input_message_content import (
InputMessageContent, InputTextMessageContent
) )
from .messages_and_media import ( from .messages_and_media import (
Audio, Contact, Document, Animation, Location, Photo, PhotoSize, Audio, Contact, Document, Animation, Location, Photo, PhotoSize,

View File

@ -23,28 +23,6 @@ from .game_high_score import GameHighScore
from .game_high_scores import GameHighScores from .game_high_scores import GameHighScores
from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_button import InlineKeyboardButton
from .inline_keyboard_markup import InlineKeyboardMarkup 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 .keyboard_button import KeyboardButton
from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_markup import ReplyKeyboardMarkup
from .reply_keyboard_remove import ReplyKeyboardRemove from .reply_keyboard_remove import ReplyKeyboardRemove

View File

@ -0,0 +1,21 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
from .inline_query import InlineQuery
from .inline_query_result import InlineQueryResult
from .inline_query_result_article import InlineQueryResultArticle

View File

@ -20,15 +20,16 @@ from typing import List
import pyrogram import pyrogram
from pyrogram.api import types 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 ..messages_and_media import Location
from ..pyrogram_type import PyrogramType from ..pyrogram_type import PyrogramType
from ..update import Update
from ..user_and_chats import User from ..user_and_chats import User
class InlineQuery(PyrogramType): class InlineQuery(PyrogramType, Update):
"""This object represents an incoming inline query. """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: Args:
id (``str``): id (``str``):
@ -50,6 +51,7 @@ class InlineQuery(PyrogramType):
def __init__( def __init__(
self, self,
*,
client: "pyrogram.client.ext.BaseClient", client: "pyrogram.client.ext.BaseClient",
id: str, id: str,
from_user: User, from_user: User,
@ -69,7 +71,6 @@ class InlineQuery(PyrogramType):
@staticmethod @staticmethod
def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery": def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery":
return InlineQuery( return InlineQuery(
client=client,
id=str(inline_query.query_id), id=str(inline_query.query_id),
from_user=User._parse(client, users[inline_query.user_id]), from_user=User._parse(client, users[inline_query.user_id]),
query=inline_query.query, query=inline_query.query,
@ -78,7 +79,8 @@ class InlineQuery(PyrogramType):
longitude=inline_query.geo.long, longitude=inline_query.geo.long,
latitude=inline_query.geo.lat, latitude=inline_query.geo.lat,
client=client client=client
) if inline_query.geo else None ) if inline_query.geo else None,
client=client
) )
def answer( def answer(
@ -90,6 +92,55 @@ class InlineQuery(PyrogramType):
switch_pm_text: str = "", switch_pm_text: str = "",
switch_pm_parameter: str = "" switch_pm_parameter: str = ""
): ):
"""Bound method *answer* of :obj:`InlineQuery <pyrogram.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 <pyrogram.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 dont support pagination.
Offset length cant 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 <https://core.telegram.org/bots#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( return self._client.answer_inline_query(
inline_query_id=self.id, inline_query_id=self.id,
results=results, results=results,

View File

@ -16,12 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from ..pyrogram_type import PyrogramType
class InlineQueryResult: """- :obj:`InlineQueryResultCachedAudio`
"""This object represents one result of an inline query.
Pyrogram currently supports results of the following 20 types:
- :obj:`InlineQueryResultCachedAudio`
- :obj:`InlineQueryResultCachedDocument` - :obj:`InlineQueryResultCachedDocument`
- :obj:`InlineQueryResultCachedGif` - :obj:`InlineQueryResultCachedGif`
- :obj:`InlineQueryResultCachedMpeg4Gif` - :obj:`InlineQueryResultCachedMpeg4Gif`
@ -29,7 +26,6 @@ class InlineQueryResult:
- :obj:`InlineQueryResultCachedSticker` - :obj:`InlineQueryResultCachedSticker`
- :obj:`InlineQueryResultCachedVideo` - :obj:`InlineQueryResultCachedVideo`
- :obj:`InlineQueryResultCachedVoice` - :obj:`InlineQueryResultCachedVoice`
- :obj:`InlineQueryResultArticle`
- :obj:`InlineQueryResultAudio` - :obj:`InlineQueryResultAudio`
- :obj:`InlineQueryResultContact` - :obj:`InlineQueryResultContact`
- :obj:`InlineQueryResultGame` - :obj:`InlineQueryResultGame`
@ -40,9 +36,24 @@ class InlineQueryResult:
- :obj:`InlineQueryResultPhoto` - :obj:`InlineQueryResultPhoto`
- :obj:`InlineQueryResultVenue` - :obj:`InlineQueryResultVenue`
- :obj:`InlineQueryResultVideo` - :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): def __init__(self, type: str, id: str):
super().__init__(None)
self.type = type self.type = type
self.id = id self.id = id
def write(self):
pass

View File

@ -32,40 +32,44 @@ class InlineQueryResultArticle(InlineQueryResult):
title (``str``): title (``str``):
Title for the result. Title for the result.
input_message_content (``TODO``): input_message_content (:obj:`InputMessageContent <pyrogram.InputMessageContent>`):
Content of the message to be sent. Content of the message to be sent.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.InlineKeyboardMarkup>`, *optional*): reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.InlineKeyboardMarkup>`, *optional*):
Inline keyboard attached to the message Inline keyboard attached to the message.
url (``str``, *optional*): url (``str``, *optional*):
URL of the result URL of the result.
description (``str``, optional): description (``str``, *optional*):
Short description of the result Short description of the result.
thumb_url (``str``, optional): thumb_url (``str``, *optional*):
Url of the thumbnail for the result Url of the thumbnail for the result.
thumb_width (``int``, *optional*): thumb_width (``int``, *optional*):
Thumbnail width. Thumbnail width.
thumb_height (``int``, *optional*): thumb_height (``int``, *optional*):
Thumbnail height. Thumbnail height.
""" """
__slots__ = [
"title", "input_message_content", "reply_markup", "url", "description", "thumb_url", "thumb_width",
"thumb_height"
]
def __init__( def __init__(
self, self,
id: str, id: str,
title: str, title: str,
input_message_content, input_message_content,
reply_markup=None, reply_markup=None,
url: str = None, url: str = None,
description: str = None, description: str = None,
thumb_url: str = None, thumb_url: str = None,
thumb_width: int = 0, thumb_width: int = 0,
thumb_height: int = 0 thumb_height: int = 0
): ):
super().__init__("article", id) super().__init__("article", id)

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:
@ -57,7 +57,6 @@ class InlineQueryResultAudio(Object):
Content of the message to be sent instead of the audio. 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): 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 self.type = type # string

View File

@ -23,9 +23,10 @@ from pyrogram.api import types
from pyrogram.api.errors import FileIdInvalid from pyrogram.api.errors import FileIdInvalid
from pyrogram.client.ext import utils, BaseClient from pyrogram.client.ext import utils, BaseClient
from pyrogram.client.style import HTML, Markdown 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. """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 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. message with the specified content instead of the audio.
@ -53,13 +54,13 @@ class InlineQueryResultCachedAudio:
""" """
def __init__( def __init__(
self, self,
id: str, id: str,
audio_file_id: str, audio_file_id: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
reply_markup=None, reply_markup=None,
input_message_content=None input_message_content=None
): ):
self.id = id self.id = id
self.audio_file_id = audio_file_id self.audio_file_id = audio_file_id

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api.core import Object from pyrogram.client.types.pyrogram_type import PyrogramType
class InlineQueryResultGame(Object): class InlineQueryResultGame(PyrogramType):
"""Represents a Game. """Represents a Game.
Attributes: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -18,9 +18,10 @@
from pyrogram.api import types from pyrogram.api import types
from pyrogram.client.style import HTML, Markdown 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. """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. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Attributes:

View File

@ -22,6 +22,4 @@ from .input_media_audio import InputMediaAudio
from .input_media_document import InputMediaDocument from .input_media_document import InputMediaDocument
from .input_media_photo import InputMediaPhoto from .input_media_photo import InputMediaPhoto
from .input_media_video import InputMediaVideo from .input_media_video import InputMediaVideo
from .input_message_content import InputMessageContent
from .input_phone_contact import InputPhoneContact from .input_phone_contact import InputPhoneContact
from .input_text_message_content import InputTextMessageContent

View File

@ -0,0 +1,20 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
from .input_message_content import InputMessageContent
from .input_text_message_content import InputTextMessageContent

View File

@ -16,17 +16,22 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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. """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: Pyrogram currently supports the following 4 types:
- :obj:`InputTextMessageContent` - :obj:`InputTextMessageContent`
- :obj:`InputLocationMessageContent`
- :obj:`InputVenueMessageContent`
- :obj:`InputContactMessageContent`
""" """
__slots__ = []
def __init__(self): def __init__(self):
pass super().__init__(None)

View File

@ -17,20 +17,38 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api import types 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 <pyrogram.ParseMode.MARKDOWN>` or :obj:`HTML <pyrogram.ParseMode.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): def __init__(self, message_text: str, parse_mode: str = "", disable_web_page_preview: bool = None):
super().__init__()
self.message_text = message_text self.message_text = message_text
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
self.style = HTML() if parse_mode.lower() == "html" else Markdown()
def write(self, reply_markup): def write(self, reply_markup):
return types.InputBotInlineMessageText( return types.InputBotInlineMessageText(
no_webpage=self.disable_web_page_preview or None, no_webpage=self.disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else 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)
) )