From a9fe0fffc69e7d6bf9a6f5854babd4fd1d2a2287 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 10:48:07 +0200 Subject: [PATCH 01/37] Add InlineQuery type --- pyrogram/__init__.py | 3 +- pyrogram/client/types/__init__.py | 2 +- pyrogram/client/types/bots/__init__.py | 1 + pyrogram/client/types/bots/inline_query.py | 58 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 pyrogram/client/types/bots/inline_query.py diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 6fb6fff4..a741d9b0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -31,7 +31,8 @@ from .client.types import ( InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, - InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove + InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, + InlineQuery ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 230d5e5d..fe8b8b65 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -18,7 +18,7 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery ) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/bots/__init__.py b/pyrogram/client/types/bots/__init__.py index 9f7cc7e6..43f7c0cb 100644 --- a/pyrogram/client/types/bots/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -20,6 +20,7 @@ from .callback_query import CallbackQuery from .force_reply import ForceReply from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup +from .inline_query import InlineQuery from .keyboard_button import KeyboardButton from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove diff --git a/pyrogram/client/types/bots/inline_query.py b/pyrogram/client/types/bots/inline_query.py new file mode 100644 index 00000000..d90996de --- /dev/null +++ b/pyrogram/client/types/bots/inline_query.py @@ -0,0 +1,58 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQuery(Object): + """This object represents an incoming inline query. + When the user sends an empty query, your bot could return some default or trending results + + Args: + id (``str``): + Unique identifier for this query. + + from_user (:obj:`User `): + Sender. + + query (``str``): + Text of the query (up to 512 characters). + + offset (``str``): + Offset of the results to be returned, can be controlled by the bot. + + location (:obj:`Location `. *optional*): + Sender location, only for bots that request user location. + """ + ID = 0xb0700024 + + def __init__( + self, + client, + id: str, + from_user, + query: str, + offset: str, + location=None, + ): + self._client = client + self.id = id + self.from_user = from_user + self.query = query + self.offset = offset + self.location = location From c37dcb07cf7ef125ac38d08b16a2d57ab1c98802 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 10:50:17 +0200 Subject: [PATCH 02/37] Add parse_inline_query util method --- compiler/api/compiler.py | 1 + pyrogram/client/ext/utils.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index bcb96ea4..67c66c18 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -506,6 +506,7 @@ def start(): f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") f.write("\n 0xb0700029: \"pyrogram.client.types.Dialogs\",") f.write("\n 0xb0700030: \"pyrogram.client.types.ChatMembers\",") + f.write("\n 0xb0700032: \"pyrogram.client.types.InlineQuery\"") f.write("\n}\n") diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a497e3c9..925ca0a8 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -889,6 +889,20 @@ def parse_inline_callback_query(client, callback_query, users): ) +def parse_inline_query(client, inline_query: types.UpdateBotInlineQuery, users): + return pyrogram_types.InlineQuery( + client=client, + id=str(inline_query.query_id), + from_user=parse_user(users[inline_query.user_id]), + query=inline_query.query, + offset=inline_query.offset, + location=pyrogram_types.Location( + longitude=inline_query.geo.long, + latitude=inline_query.geo.lat + ) if inline_query.geo else None + ) + + def parse_chat_full( client, chat_full: types.messages.ChatFull or types.UserFull From dd642f5b9d1f851eab60f1c45ae54037a32a13e0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 11:34:27 +0200 Subject: [PATCH 03/37] Add scraped inline query results --- compiler/api/compiler.py | 5 +- pyrogram/client/types/bots/__init__.py | 19 ++++ .../types/bots/inline_query_result_audio.py | 72 +++++++++++++++ .../bots/inline_query_result_cached_audio.py | 60 +++++++++++++ .../inline_query_result_cached_document.py | 68 ++++++++++++++ .../bots/inline_query_result_cached_gif.py | 64 ++++++++++++++ .../inline_query_result_cached_mpeg4_gif.py | 64 ++++++++++++++ .../bots/inline_query_result_cached_photo.py | 68 ++++++++++++++ .../inline_query_result_cached_sticker.py | 52 +++++++++++ .../bots/inline_query_result_cached_video.py | 68 ++++++++++++++ .../bots/inline_query_result_cached_voice.py | 64 ++++++++++++++ .../types/bots/inline_query_result_contact.py | 76 ++++++++++++++++ .../bots/inline_query_result_document.py | 84 ++++++++++++++++++ .../types/bots/inline_query_result_game.py | 48 ++++++++++ .../types/bots/inline_query_result_gif.py | 80 +++++++++++++++++ .../bots/inline_query_result_location.py | 76 ++++++++++++++++ .../bots/inline_query_result_mpeg4_gif.py | 80 +++++++++++++++++ .../types/bots/inline_query_result_photo.py | 80 +++++++++++++++++ .../types/bots/inline_query_result_venue.py | 84 ++++++++++++++++++ .../types/bots/inline_query_result_video.py | 88 +++++++++++++++++++ .../types/bots/inline_query_result_voice.py | 68 ++++++++++++++ 21 files changed, 1366 insertions(+), 2 deletions(-) create mode 100644 pyrogram/client/types/bots/inline_query_result_audio.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_audio.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_document.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_gif.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_photo.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_sticker.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_video.py create mode 100644 pyrogram/client/types/bots/inline_query_result_cached_voice.py create mode 100644 pyrogram/client/types/bots/inline_query_result_contact.py create mode 100644 pyrogram/client/types/bots/inline_query_result_document.py create mode 100644 pyrogram/client/types/bots/inline_query_result_game.py create mode 100644 pyrogram/client/types/bots/inline_query_result_gif.py create mode 100644 pyrogram/client/types/bots/inline_query_result_location.py create mode 100644 pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py create mode 100644 pyrogram/client/types/bots/inline_query_result_photo.py create mode 100644 pyrogram/client/types/bots/inline_query_result_venue.py create mode 100644 pyrogram/client/types/bots/inline_query_result_video.py create mode 100644 pyrogram/client/types/bots/inline_query_result_voice.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 67c66c18..a561cf42 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -172,8 +172,9 @@ def start(): with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \ open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ - open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: - schema = (auth.read() + system.read() + api.read()).splitlines() + open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api, \ + open("{}/source/bot.tl".format(HOME), encoding="utf-8") as pyro: + schema = (auth.read() + system.read() + api.read() + pyro.read()).splitlines() with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f: mtproto_template = f.read() diff --git a/pyrogram/client/types/bots/__init__.py b/pyrogram/client/types/bots/__init__.py index 43f7c0cb..bf85e354 100644 --- a/pyrogram/client/types/bots/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -21,6 +21,25 @@ from .force_reply import ForceReply from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup from .inline_query import InlineQuery +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/bots/inline_query_result_audio.py b/pyrogram/client/types/bots/inline_query_result_audio.py new file mode 100644 index 00000000..f8b21be8 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_audio.py @@ -0,0 +1,72 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultAudio(Object): + """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: + ID: ``0xb0700004`` + + Args: + type (``str``): + Type of the result, must be audio. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + audio_url (``str``): + A valid URL for the audio file. + + title (``str``): + Title. + + caption (``str``, optional): + Caption, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + performer (``str``, optional): + Performer. + + audio_duration (``int`` ``32-bit``, optional): + Audio duration in seconds. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + 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 + self.id = id # string + self.audio_url = audio_url # string + self.title = title # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.performer = performer # flags.2?string + self.audio_duration = audio_duration # flags.3?int + self.reply_markup = reply_markup # flags.4?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.5?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_audio.py b/pyrogram/client/types/bots/inline_query_result_cached_audio.py new file mode 100644 index 00000000..3dc53982 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_audio.py @@ -0,0 +1,60 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedAudio(Object): + """Represents a link to an mp3 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. + + Attributes: + ID: ``0xb0700018`` + + Args: + type (``str``): + Type of the result, must be audio. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + audio_file_id (``str``): + A valid file identifier for the audio file. + + caption (``str``, optional): + Caption, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the audio. + + """ + ID = 0xb0700018 + + def __init__(self, type: str, id: str, audio_file_id: str, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.audio_file_id = audio_file_id # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.3?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_document.py b/pyrogram/client/types/bots/inline_query_result_cached_document.py new file mode 100644 index 00000000..cf9a3012 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_document.py @@ -0,0 +1,68 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedDocument(Object): + """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: + ID: ``0xb0700015`` + + Args: + type (``str``): + Type of the result, must be document. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + title (``str``): + Title for the result. + + document_file_id (``str``): + A valid file identifier for the file. + + description (``str``, optional): + Short description of the result. + + caption (``str``, optional): + Caption of the document to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the file. + + """ + ID = 0xb0700015 + + def __init__(self, type: str, id: str, title: str, document_file_id: str, description: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.title = title # string + self.document_file_id = document_file_id # string + self.description = description # flags.0?string + self.caption = caption # flags.1?string + self.parse_mode = parse_mode # flags.2?string + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_gif.py b/pyrogram/client/types/bots/inline_query_result_cached_gif.py new file mode 100644 index 00000000..2ecca3a8 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_gif.py @@ -0,0 +1,64 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedGif(Object): + """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: + ID: ``0xb0700012`` + + Args: + type (``str``): + Type of the result, must be gif. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + gif_file_id (``str``): + A valid file identifier for the GIF file. + + title (``str``, optional): + Title for the result. + + caption (``str``, optional): + Caption of the GIF file to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the GIF animation. + + """ + ID = 0xb0700012 + + def __init__(self, type: str, id: str, gif_file_id: str, title: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.gif_file_id = gif_file_id # string + self.title = title # flags.0?string + self.caption = caption # flags.1?string + self.parse_mode = parse_mode # flags.2?string + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py b/pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py new file mode 100644 index 00000000..caa9a478 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_mpeg4_gif.py @@ -0,0 +1,64 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedMpeg4Gif(Object): + """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: + ID: ``0xb0700013`` + + Args: + type (``str``): + Type of the result, must be mpeg4_gif. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + mpeg4_file_id (``str``): + A valid file identifier for the MP4 file. + + title (``str``, optional): + Title for the result. + + caption (``str``, optional): + Caption of the MPEG-4 file to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the video animation. + + """ + ID = 0xb0700013 + + def __init__(self, type: str, id: str, mpeg4_file_id: str, title: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.mpeg4_file_id = mpeg4_file_id # string + self.title = title # flags.0?string + self.caption = caption # flags.1?string + self.parse_mode = parse_mode # flags.2?string + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_photo.py b/pyrogram/client/types/bots/inline_query_result_cached_photo.py new file mode 100644 index 00000000..e18117f5 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_photo.py @@ -0,0 +1,68 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedPhoto(Object): + """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: + ID: ``0xb0700011`` + + Args: + type (``str``): + Type of the result, must be photo. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + photo_file_id (``str``): + A valid file identifier of the photo. + + title (``str``, optional): + Title for the result. + + description (``str``, optional): + Short description of the result. + + caption (``str``, optional): + Caption of the photo to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the photo. + + """ + ID = 0xb0700011 + + def __init__(self, type: str, id: str, photo_file_id: str, title: str = None, description: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.photo_file_id = photo_file_id # string + self.title = title # flags.0?string + self.description = description # flags.1?string + self.caption = caption # flags.2?string + self.parse_mode = parse_mode # flags.3?string + self.reply_markup = reply_markup # flags.4?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.5?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_sticker.py b/pyrogram/client/types/bots/inline_query_result_cached_sticker.py new file mode 100644 index 00000000..6f381d39 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_sticker.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedSticker(Object): + """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: + ID: ``0xb0700014`` + + Args: + type (``str``): + Type of the result, must be sticker. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + sticker_file_id (``str``): + A valid file identifier of the sticker. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the sticker. + + """ + ID = 0xb0700014 + + def __init__(self, type: str, id: str, sticker_file_id: str, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.sticker_file_id = sticker_file_id # string + self.reply_markup = reply_markup # flags.0?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.1?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_video.py b/pyrogram/client/types/bots/inline_query_result_cached_video.py new file mode 100644 index 00000000..5eb5c745 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_video.py @@ -0,0 +1,68 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedVideo(Object): + """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: + ID: ``0xb0700016`` + + Args: + type (``str``): + Type of the result, must be video. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + video_file_id (``str``): + A valid file identifier for the video file. + + title (``str``): + Title for the result. + + description (``str``, optional): + Short description of the result. + + caption (``str``, optional): + Caption of the video to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the video. + + """ + ID = 0xb0700016 + + def __init__(self, type: str, id: str, video_file_id: str, title: str, description: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.video_file_id = video_file_id # string + self.title = title # string + self.description = description # flags.0?string + self.caption = caption # flags.1?string + self.parse_mode = parse_mode # flags.2?string + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_cached_voice.py b/pyrogram/client/types/bots/inline_query_result_cached_voice.py new file mode 100644 index 00000000..47962ba6 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_cached_voice.py @@ -0,0 +1,64 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultCachedVoice(Object): + """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: + ID: ``0xb0700017`` + + Args: + type (``str``): + Type of the result, must be voice. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + voice_file_id (``str``): + A valid file identifier for the voice message. + + title (``str``): + Voice message title. + + caption (``str``, optional): + Caption, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the voice message. + + """ + ID = 0xb0700017 + + def __init__(self, type: str, id: str, voice_file_id: str, title: str, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.voice_file_id = voice_file_id # string + self.title = title # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.3?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_contact.py b/pyrogram/client/types/bots/inline_query_result_contact.py new file mode 100644 index 00000000..4e1b85d5 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_contact.py @@ -0,0 +1,76 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultContact(Object): + """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: + ID: ``0xb0700009`` + + Args: + type (``str``): + Type of the result, must be contact. + + id (``str``): + Unique identifier for this result, 1-64 Bytes. + + phone_number (``str``): + Contact's phone number. + + first_name (``str``): + Contact's first name. + + last_name (``str``, optional): + Contact's last name. + + vcard (``str``, optional): + Additional data about the contact in the form of a vCard, 0-2048 bytes. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the contact. + + thumb_url (``str``, optional): + Url of the thumbnail for the result. + + thumb_width (``int`` ``32-bit``, optional): + Thumbnail width. + + thumb_height (``int`` ``32-bit``, optional): + Thumbnail height. + + """ + ID = 0xb0700009 + + def __init__(self, type: str, id: str, phone_number: str, first_name: str, last_name: str = None, vcard: str = None, reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None, thumb_height: int = None): + self.type = type # string + self.id = id # string + self.phone_number = phone_number # string + self.first_name = first_name # string + self.last_name = last_name # flags.0?string + self.vcard = vcard # flags.1?string + self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.3?InputMessageContent + self.thumb_url = thumb_url # flags.4?string + self.thumb_width = thumb_width # flags.5?int + self.thumb_height = thumb_height # flags.6?int diff --git a/pyrogram/client/types/bots/inline_query_result_document.py b/pyrogram/client/types/bots/inline_query_result_document.py new file mode 100644 index 00000000..47b3fff4 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_document.py @@ -0,0 +1,84 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultDocument(Object): + """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: + ID: ``0xb0700006`` + + Args: + type (``str``): + Type of the result, must be document. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + title (``str``): + Title for the result. + + document_url (``str``, optional): + Caption of the document to be sent, 0-200 characters. + + mime_type (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + caption (``str``): + A valid URL for the file. + + parse_mode (``str``): + Mime type of the content of the file, either "application/pdf" or "application/zip". + + description (``str``, optional): + Short description of the result. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the file. + + thumb_url (``str``, optional): + URL of the thumbnail (jpeg only) for the file. + + thumb_width (``int`` ``32-bit``, optional): + Thumbnail width. + + thumb_height (``int`` ``32-bit``, optional): + Thumbnail height. + + """ + ID = 0xb0700006 + + def __init__(self, type: str, id: str, title: str, document_url: str, mime_type: str, caption: str = None, parse_mode: str = None, description: str = None, reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None, thumb_height: int = None): + self.type = type # string + self.id = id # string + self.title = title # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.document_url = document_url # string + self.mime_type = mime_type # string + self.description = description # flags.2?string + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent + self.thumb_url = thumb_url # flags.5?string + self.thumb_width = thumb_width # flags.6?int + self.thumb_height = thumb_height # flags.7?int diff --git a/pyrogram/client/types/bots/inline_query_result_game.py b/pyrogram/client/types/bots/inline_query_result_game.py new file mode 100644 index 00000000..cc965c7c --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_game.py @@ -0,0 +1,48 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultGame(Object): + """Represents a Game. + + Attributes: + ID: ``0xb0700010`` + + Args: + type (``str``): + Type of the result, must be game. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + game_short_name (``str``): + Short name of the game. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + """ + ID = 0xb0700010 + + def __init__(self, type: str, id: str, game_short_name: str, reply_markup=None): + self.type = type # string + self.id = id # string + self.game_short_name = game_short_name # string + self.reply_markup = reply_markup # flags.0?InlineKeyboardMarkup diff --git a/pyrogram/client/types/bots/inline_query_result_gif.py b/pyrogram/client/types/bots/inline_query_result_gif.py new file mode 100644 index 00000000..8ce701d9 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_gif.py @@ -0,0 +1,80 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultGif(Object): + """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: + ID: ``0xb0700001`` + + Args: + type (``str``): + Type of the result, must be gif. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + gif_url (``str``): + A valid URL for the GIF file. File size must not exceed 1MB. + + thumb_url (``str``, optional): + Width of the GIF. + + gif_width (``int`` ``32-bit``, optional): + Height of the GIF. + + gif_height (``int`` ``32-bit``, optional): + Duration of the GIF. + + gif_duration (``int`` ``32-bit``): + URL of the static thumbnail for the result (jpeg or gif). + + title (``str``, optional): + Title for the result. + + caption (``str``, optional): + Caption of the GIF file to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the GIF animation. + + """ + ID = 0xb0700001 + + def __init__(self, type: str, id: str, gif_url: str, thumb_url: str, gif_width: int = None, gif_height: int = None, gif_duration: int = None, title: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.gif_url = gif_url # string + self.gif_width = gif_width # flags.0?int + self.gif_height = gif_height # flags.1?int + self.gif_duration = gif_duration # flags.2?int + self.thumb_url = thumb_url # string + self.title = title # flags.3?string + self.caption = caption # flags.4?string + self.parse_mode = parse_mode # flags.5?string + self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.7?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_location.py b/pyrogram/client/types/bots/inline_query_result_location.py new file mode 100644 index 00000000..4a6c1401 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_location.py @@ -0,0 +1,76 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultLocation(Object): + """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: + ID: ``0xb0700007`` + + Args: + type (``str``): + Type of the result, must be location. + + id (``str``): + Unique identifier for this result, 1-64 Bytes. + + latitude (``float`` ``64-bit``): + Location latitude in degrees. + + longitude (``float`` ``64-bit``): + Location longitude in degrees. + + title (``str``): + Location title. + + live_period (``int`` ``32-bit``, optional): + Period in seconds for which the location can be updated, should be between 60 and 86400. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the location. + + thumb_url (``str``, optional): + Url of the thumbnail for the result. + + thumb_width (``int`` ``32-bit``, optional): + Thumbnail width. + + thumb_height (``int`` ``32-bit``, optional): + Thumbnail height. + + """ + ID = 0xb0700007 + + def __init__(self, type: str, id: str, latitude: float, longitude: float, title: str, live_period: int = None, reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None, thumb_height: int = None): + self.type = type # string + self.id = id # string + self.latitude = latitude # double + self.longitude = longitude # double + self.title = title # string + self.live_period = live_period # flags.0?int + self.reply_markup = reply_markup # flags.1?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.2?InputMessageContent + self.thumb_url = thumb_url # flags.3?string + self.thumb_width = thumb_width # flags.4?int + self.thumb_height = thumb_height # flags.5?int diff --git a/pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py b/pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py new file mode 100644 index 00000000..10778def --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_mpeg4_gif.py @@ -0,0 +1,80 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultMpeg4Gif(Object): + """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: + ID: ``0xb0700002`` + + Args: + type (``str``): + Type of the result, must be mpeg4_gif. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + mpeg4_url (``str``): + A valid URL for the MP4 file. File size must not exceed 1MB. + + thumb_url (``str``, optional): + Video width. + + mpeg4_width (``int`` ``32-bit``, optional): + Video height. + + mpeg4_height (``int`` ``32-bit``, optional): + Video duration. + + mpeg4_duration (``int`` ``32-bit``): + URL of the static thumbnail (jpeg or gif) for the result. + + title (``str``, optional): + Title for the result. + + caption (``str``, optional): + Caption of the MPEG-4 file to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the video animation. + + """ + ID = 0xb0700002 + + def __init__(self, type: str, id: str, mpeg4_url: str, thumb_url: str, mpeg4_width: int = None, mpeg4_height: int = None, mpeg4_duration: int = None, title: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.mpeg4_url = mpeg4_url # string + self.mpeg4_width = mpeg4_width # flags.0?int + self.mpeg4_height = mpeg4_height # flags.1?int + self.mpeg4_duration = mpeg4_duration # flags.2?int + self.thumb_url = thumb_url # string + self.title = title # flags.3?string + self.caption = caption # flags.4?string + self.parse_mode = parse_mode # flags.5?string + self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.7?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_photo.py b/pyrogram/client/types/bots/inline_query_result_photo.py new file mode 100644 index 00000000..09ea96b6 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_photo.py @@ -0,0 +1,80 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultPhoto(Object): + """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. + + Attributes: + ID: ``0xb0700000`` + + Args: + type (``str``): + Type of the result, must be photo. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + photo_url (``str``): + A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB. + + thumb_url (``str``): + URL of the thumbnail for the photo. + + photo_width (``int`` ``32-bit``, optional): + Width of the photo. + + photo_height (``int`` ``32-bit``, optional): + Height of the photo. + + title (``str``, optional): + Title for the result. + + description (``str``, optional): + Short description of the result. + + caption (``str``, optional): + Caption of the photo to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the photo. + + """ + ID = 0xb0700000 + + def __init__(self, type: str, id: str, photo_url: str, thumb_url: str, photo_width: int = None, photo_height: int = None, title: str = None, description: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.photo_url = photo_url # string + self.thumb_url = thumb_url # string + self.photo_width = photo_width # flags.0?int + self.photo_height = photo_height # flags.1?int + self.title = title # flags.2?string + self.description = description # flags.3?string + self.caption = caption # flags.4?string + self.parse_mode = parse_mode # flags.5?string + self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.7?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_venue.py b/pyrogram/client/types/bots/inline_query_result_venue.py new file mode 100644 index 00000000..69e47f2d --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_venue.py @@ -0,0 +1,84 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultVenue(Object): + """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: + ID: ``0xb0700008`` + + Args: + type (``str``): + Type of the result, must be venue. + + id (``str``): + Unique identifier for this result, 1-64 Bytes. + + latitude (``float`` ``64-bit``): + Latitude of the venue location in degrees. + + longitude (``float`` ``64-bit``): + Longitude of the venue location in degrees. + + title (``str``): + Title of the venue. + + address (``str``): + Address of the venue. + + foursquare_id (``str``, optional): + Foursquare identifier of the venue if known. + + foursquare_type (``str``, optional): + Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".). + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the venue. + + thumb_url (``str``, optional): + Url of the thumbnail for the result. + + thumb_width (``int`` ``32-bit``, optional): + Thumbnail width. + + thumb_height (``int`` ``32-bit``, optional): + Thumbnail height. + + """ + ID = 0xb0700008 + + def __init__(self, type: str, id: str, latitude: float, longitude: float, title: str, address: str, foursquare_id: str = None, foursquare_type: str = None, reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None, thumb_height: int = None): + self.type = type # string + self.id = id # string + self.latitude = latitude # double + self.longitude = longitude # double + self.title = title # string + self.address = address # string + self.foursquare_id = foursquare_id # flags.0?string + self.foursquare_type = foursquare_type # flags.1?string + self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.3?InputMessageContent + self.thumb_url = thumb_url # flags.4?string + self.thumb_width = thumb_width # flags.5?int + self.thumb_height = thumb_height # flags.6?int diff --git a/pyrogram/client/types/bots/inline_query_result_video.py b/pyrogram/client/types/bots/inline_query_result_video.py new file mode 100644 index 00000000..c7a3627e --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_video.py @@ -0,0 +1,88 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultVideo(Object): + """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: + ID: ``0xb0700003`` + + Args: + type (``str``): + Type of the result, must be video. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + video_url (``str``): + A valid URL for the embedded video player or video file. + + mime_type (``str``): + Mime type of the content of video url, "text/html" or "video/mp4". + + thumb_url (``str``): + URL of the thumbnail (jpeg only) for the video. + + title (``str``): + Title for the result. + + caption (``str``, optional): + Caption of the video to be sent, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + video_width (``int`` ``32-bit``, optional): + Video width. + + video_height (``int`` ``32-bit``, optional): + Video height. + + video_duration (``int`` ``32-bit``, optional): + Video duration in seconds. + + description (``str``, optional): + Short description of the result. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video). + + """ + ID = 0xb0700003 + + def __init__(self, type: str, id: str, video_url: str, mime_type: str, thumb_url: str, title: str, caption: str = None, parse_mode: str = None, video_width: int = None, video_height: int = None, video_duration: int = None, description: str = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.video_url = video_url # string + self.mime_type = mime_type # string + self.thumb_url = thumb_url # string + self.title = title # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.video_width = video_width # flags.2?int + self.video_height = video_height # flags.3?int + self.video_duration = video_duration # flags.4?int + self.description = description # flags.5?string + self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.7?InputMessageContent diff --git a/pyrogram/client/types/bots/inline_query_result_voice.py b/pyrogram/client/types/bots/inline_query_result_voice.py new file mode 100644 index 00000000..04edac6e --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_voice.py @@ -0,0 +1,68 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class InlineQueryResultVoice(Object): + """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: + ID: ``0xb0700005`` + + Args: + type (``str``): + Type of the result, must be voice. + + id (``str``): + Unique identifier for this result, 1-64 bytes. + + voice_url (``str``): + A valid URL for the voice recording. + + title (``str``): + Recording title. + + caption (``str``, optional): + Caption, 0-200 characters. + + parse_mode (``str``, optional): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + voice_duration (``int`` ``32-bit``, optional): + Recording duration in seconds. + + reply_markup (:obj:`InlineKeyboardMarkup `, optional): + Inline keyboard attached to the message. + + input_message_content (:obj:`InputMessageContent `, optional): + Content of the message to be sent instead of the voice recording. + + """ + ID = 0xb0700005 + + def __init__(self, type: str, id: str, voice_url: str, title: str, caption: str = None, parse_mode: str = None, voice_duration: int = None, reply_markup=None, input_message_content=None): + self.type = type # string + self.id = id # string + self.voice_url = voice_url # string + self.title = title # string + self.caption = caption # flags.0?string + self.parse_mode = parse_mode # flags.1?string + self.voice_duration = voice_duration # flags.2?int + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.input_message_content = input_message_content # flags.4?InputMessageContent From d6c0e614568ca62ff7e3dc88a13ec50e763395d0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:24:33 +0200 Subject: [PATCH 04/37] Add InputTextMessageContent type --- pyrogram/client/types/input_media/__init__.py | 1 + .../input_media/input_text_message_content.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 pyrogram/client/types/input_media/input_text_message_content.py diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py index 5f5be30d..3a8f9b16 100644 --- a/pyrogram/client/types/input_media/__init__.py +++ b/pyrogram/client/types/input_media/__init__.py @@ -23,3 +23,4 @@ from .input_media_document import InputMediaDocument from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo from .input_phone_contact import InputPhoneContact +from .input_text_message_content import InputTextMessageContent diff --git a/pyrogram/client/types/input_media/input_text_message_content.py b/pyrogram/client/types/input_media/input_text_message_content.py new file mode 100644 index 00000000..b6c3435f --- /dev/null +++ b/pyrogram/client/types/input_media/input_text_message_content.py @@ -0,0 +1,35 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api import types +from pyrogram.client.style import HTML, Markdown + + +class InputTextMessageContent: + def __init__(self, message_text: str, parse_mode: str = "", disable_web_page_preview: bool = None): + 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): + return types.InputBotInlineMessageText( + no_webpage=self.disable_web_page_preview or None, + **self.style.parse(self.message_text) + ) From 59c3aa05896582348cdcb81b357efc5206808338 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:25:02 +0200 Subject: [PATCH 05/37] Inject reply_markup --- .../client/types/input_media/input_text_message_content.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/input_media/input_text_message_content.py b/pyrogram/client/types/input_media/input_text_message_content.py index b6c3435f..1dffff43 100644 --- a/pyrogram/client/types/input_media/input_text_message_content.py +++ b/pyrogram/client/types/input_media/input_text_message_content.py @@ -28,8 +28,9 @@ class InputTextMessageContent: self.style = HTML() if parse_mode.lower() == "html" else Markdown() - def write(self): + def write(self, reply_markup): return types.InputBotInlineMessageText( no_webpage=self.disable_web_page_preview or None, + reply_markup=reply_markup.write(), **self.style.parse(self.message_text) ) From e59d07af1e82da481b66ac099d12f360e48203e9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:28:11 +0200 Subject: [PATCH 06/37] Add missing InlineQueryResultArticle --- pyrogram/client/types/bots/__init__.py | 1 + .../types/bots/inline_query_result_article.py | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 pyrogram/client/types/bots/inline_query_result_article.py diff --git a/pyrogram/client/types/bots/__init__.py b/pyrogram/client/types/bots/__init__.py index bf85e354..6f350a21 100644 --- a/pyrogram/client/types/bots/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -21,6 +21,7 @@ from .force_reply import ForceReply from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup from .inline_query import InlineQuery +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 diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/bots/inline_query_result_article.py new file mode 100644 index 00000000..d27f4236 --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result_article.py @@ -0,0 +1,104 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api import types +from pyrogram.api.core import Object + + +class InlineQueryResultArticle(Object): + """Represents a link to an article or web page. + + Args: + id (``str``): + Unique identifier for this result, 1-64 bytes. + + title (``str``): + Title for the result. + + input_message_content (``TODO``): + Content of the message to be sent. + + reply_markup (:obj:`InlineKeyboardMarkup `, *optional*): + Inline keyboard attached to the message + + url (``str``, *optional*): + URL of the result + + hide_url (``bool``, *optional*): + Pass True, if you don't want the URL to be shown in the message + + description (``str``, optional): + Short description of 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. + + """ + ID = 0xb0700033 + + def __init__( + self, + id: str, + title: str, + input_message_content, + reply_markup=None, + url: str = None, + hide_url: bool = None, + description: str = None, + thumb_url: str = "", + thumb_width: int = 0, + thumb_height: int = 0 + ): + self.id = id # string + self.title = title # string + self.input_message_content = input_message_content # flags.4?InputMessageContent + self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.url = url + self.hide_url = hide_url + self.description = description # flags.2?string + self.thumb_url = thumb_url # flags.5?string + self.thumb_width = thumb_width # flags.6?int + self.thumb_height = thumb_height # flags.7?int + + def write(self): + return types.InputBotInlineResult( + id=self.id, + type="article", + send_message=self.input_message_content.write(self.reply_markup), + title=self.title, + description=self.description, + url=self.url, + thumb=types.InputWebDocument( + url=self.thumb_url, + size=0, + mime_type="image/jpeg", + attributes=[ + types.DocumentAttributeImageSize( + w=self.thumb_width, + h=self.thumb_height + ) + ] + ) if self.thumb_url else None, + content=None + ) From c5cedd880d49b7546599078e1884b81b8f312b5a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:29:23 +0200 Subject: [PATCH 07/37] Allow Markdown and HTML styles to work on an empty dict. For inline results. User mentions are disabled this way --- pyrogram/client/style/html.py | 4 ++-- pyrogram/client/style/markdown.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/style/html.py b/pyrogram/client/style/html.py index 63a80733..4cafeb35 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -34,8 +34,8 @@ class HTML: HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])([^<]+)\2)?>([^>]+)") MENTION_RE = re.compile(r"tg://user\?id=(\d+)") - def __init__(self, peers_by_id): - self.peers_by_id = peers_by_id + def __init__(self, peers_by_id: dict = None): + self.peers_by_id = peers_by_id or {} def parse(self, text): entities = [] diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index 7a67d0ae..61b60e17 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -51,8 +51,8 @@ class Markdown: )) MENTION_RE = re.compile(r"tg://user\?id=(\d+)") - def __init__(self, peers_by_id: dict): - self.peers_by_id = peers_by_id + def __init__(self, peers_by_id: dict = None): + self.peers_by_id = peers_by_id or {} def parse(self, message: str): message = utils.add_surrogates(message).strip() From 350265aaae4cdcbfa392b33ede86785975342ba6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:29:58 +0200 Subject: [PATCH 08/37] Add answer_inline_query method --- .../methods/bots/answer_inline_query.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pyrogram/client/methods/bots/answer_inline_query.py diff --git a/pyrogram/client/methods/bots/answer_inline_query.py b/pyrogram/client/methods/bots/answer_inline_query.py new file mode 100644 index 00000000..07eb594d --- /dev/null +++ b/pyrogram/client/methods/bots/answer_inline_query.py @@ -0,0 +1,46 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api import functions, types +from pyrogram.client.ext import BaseClient + + +class AnswerInlineQuery(BaseClient): + def answer_inline_query(self, + inline_query_id: str, + results: list, + cache_time: int = 300, + is_personal: bool = None, + next_offset: str = "", + switch_pm_text: str = "", + switch_pm_parameter: str = ""): + # TODO: Docs + return self.send( + functions.messages.SetInlineBotResults( + query_id=int(inline_query_id), + results=[r.write() for r in results], + cache_time=cache_time, + gallery=None, + private=is_personal or None, + next_offset=next_offset or None, + switch_pm=types.InlineBotSwitchPM( + switch_pm_text, + switch_pm_parameter + ) if switch_pm_text else None + ) + ) From 0a057cc233c09d50140b5926a5b9e3608b024111 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:30:12 +0200 Subject: [PATCH 09/37] Expose new types and methods --- pyrogram/__init__.py | 2 +- pyrogram/client/methods/bots/__init__.py | 2 ++ pyrogram/client/types/__init__.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a741d9b0..8fd41a9d 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,7 +32,7 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery + InlineQuery, InlineQueryResultArticle, InputTextMessageContent ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/methods/bots/__init__.py b/pyrogram/client/methods/bots/__init__.py index 2d89c2fb..24cab1dd 100644 --- a/pyrogram/client/methods/bots/__init__.py +++ b/pyrogram/client/methods/bots/__init__.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from .answer_callback_query import AnswerCallbackQuery +from .answer_inline_query import AnswerInlineQuery from .get_inline_bot_results import GetInlineBotResults from .request_callback_answer import RequestCallbackAnswer from .send_inline_bot_result import SendInlineBotResult @@ -24,6 +25,7 @@ from .send_inline_bot_result import SendInlineBotResult class Bots( AnswerCallbackQuery, + AnswerInlineQuery, GetInlineBotResults, RequestCallbackAnswer, SendInlineBotResult diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index fe8b8b65..45690b90 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -18,7 +18,8 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, + InlineQueryResultArticle ) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, @@ -26,7 +27,7 @@ from .bots import ( ) from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, - InputMediaDocument, InputMediaAnimation + InputMediaDocument, InputMediaAnimation, InputTextMessageContent ) from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, From c8fc995c83f3577eea72b8368c218732bca75144 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 14:31:16 +0200 Subject: [PATCH 10/37] No need to inherit from Object --- pyrogram/client/types/bots/inline_query_result_article.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/bots/inline_query_result_article.py index d27f4236..991e8f11 100644 --- a/pyrogram/client/types/bots/inline_query_result_article.py +++ b/pyrogram/client/types/bots/inline_query_result_article.py @@ -17,10 +17,9 @@ # along with Pyrogram. If not, see . from pyrogram.api import types -from pyrogram.api.core import Object -class InlineQueryResultArticle(Object): +class InlineQueryResultArticle: """Represents a link to an article or web page. Args: @@ -55,7 +54,6 @@ class InlineQueryResultArticle(Object): Thumbnail height. """ - ID = 0xb0700033 def __init__( self, From 797a0df0879883c76ab12384b8b3b3b60d834fc5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 15:04:49 +0200 Subject: [PATCH 11/37] Implement InlineQueryResultPhoto --- pyrogram/__init__.py | 2 +- pyrogram/client/types/__init__.py | 2 +- .../types/bots/inline_query_result_photo.py | 87 ++++++++++++++----- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 8fd41a9d..00d269eb 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,7 +32,7 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery, InlineQueryResultArticle, InputTextMessageContent + InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 45690b90..cceac77a 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -19,7 +19,7 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, - InlineQueryResultArticle + InlineQueryResultArticle, InlineQueryResultPhoto ) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/bots/inline_query_result_photo.py b/pyrogram/client/types/bots/inline_query_result_photo.py index 09ea96b6..1cc3af7e 100644 --- a/pyrogram/client/types/bots/inline_query_result_photo.py +++ b/pyrogram/client/types/bots/inline_query_result_photo.py @@ -16,19 +16,15 @@ # 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.api import types +from pyrogram.client.style import HTML, Markdown -class InlineQueryResultPhoto(Object): - """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. - - Attributes: - ID: ``0xb0700000`` +class InlineQueryResultPhoto: + """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. Args: - type (``str``): - Type of the result, must be photo. - id (``str``): Unique identifier for this result, 1-64 bytes. @@ -38,35 +34,47 @@ class InlineQueryResultPhoto(Object): thumb_url (``str``): URL of the thumbnail for the photo. - photo_width (``int`` ``32-bit``, optional): + photo_width (``int``, *optional*): Width of the photo. - photo_height (``int`` ``32-bit``, optional): + photo_height (``int``, *optional*): Height of the photo. - title (``str``, optional): + title (``str``, *optional*): Title for the result. - description (``str``, optional): + description (``str``, *optional*): Short description of the result. - caption (``str``, optional): + caption (``str``, *optional*): Caption of the photo to be sent, 0-200 characters. - parse_mode (``str``, optional): - Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + parse_mode (``str``, *optional*): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in + the media caption. - reply_markup (:obj:`InlineKeyboardMarkup `, optional): + reply_markup (:obj:`InlineKeyboardMarkup `, *optional*): Inline keyboard attached to the message. - input_message_content (:obj:`InputMessageContent `, optional): + input_message_content (:obj:`InputMessageContent `, *optional*): Content of the message to be sent instead of the photo. """ - ID = 0xb0700000 - def __init__(self, type: str, id: str, photo_url: str, thumb_url: str, photo_width: int = None, photo_height: int = None, title: str = None, description: str = None, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): - self.type = type # string + def __init__( + self, + id: str, + photo_url: str, + thumb_url: str, + photo_width: int = 0, + photo_height: int = 0, + title: str = None, + description: str = None, + caption: str = "", + parse_mode: str = "", + reply_markup=None, + input_message_content=None + ): self.id = id # string self.photo_url = photo_url # string self.thumb_url = thumb_url # string @@ -78,3 +86,40 @@ class InlineQueryResultPhoto(Object): self.parse_mode = parse_mode # flags.5?string self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup self.input_message_content = input_message_content # flags.7?InputMessageContent + + self.style = HTML() if parse_mode.lower() == "html" else Markdown() + + def write(self): + return types.InputBotInlineResult( + id=self.id, + type="photo", + send_message=types.InputBotInlineMessageMediaAuto( + reply_markup=self.reply_markup.write() if self.reply_markup else None, + **self.style.parse(self.caption) + ), + title=self.title, + description=self.description, + url=self.photo_url, + thumb=types.InputWebDocument( + url=self.thumb_url, + size=0, + mime_type="image/jpeg", + attributes=[ + types.DocumentAttributeImageSize( + w=0, + h=0 + ) + ] + ), + content=types.InputWebDocument( + url=self.thumb_url, + size=0, + mime_type="image/jpeg", + attributes=[ + types.DocumentAttributeImageSize( + w=self.photo_width, + h=self.photo_height + ) + ] + ) + ) From c94c79edacd43f4b7cc668aff17be25579e206fc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:34:44 +0200 Subject: [PATCH 12/37] Implement InlineQueryResultCachedAudio --- pyrogram/__init__.py | 2 +- pyrogram/client/types/__init__.py | 2 +- .../bots/inline_query_result_cached_audio.py | 88 ++++++++++++++----- 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 00d269eb..003e835a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,7 +32,7 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent + InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, InlineQueryResultCachedAudio ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index cceac77a..3f5eb39c 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -19,7 +19,7 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, - InlineQueryResultArticle, InlineQueryResultPhoto + InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio ) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/bots/inline_query_result_cached_audio.py b/pyrogram/client/types/bots/inline_query_result_cached_audio.py index 3dc53982..c2e1779d 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_audio.py +++ b/pyrogram/client/types/bots/inline_query_result_cached_audio.py @@ -16,45 +16,87 @@ # 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 +import binascii +import struct + +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 -class InlineQueryResultCachedAudio(Object): - """Represents a link to an mp3 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. - - Attributes: - ID: ``0xb0700018`` +class InlineQueryResultCachedAudio: + """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. Args: - type (``str``): - Type of the result, must be audio. - id (``str``): Unique identifier for this result, 1-64 bytes. audio_file_id (``str``): A valid file identifier for the audio file. - caption (``str``, optional): + caption (``str``, *optional*): Caption, 0-200 characters. - parse_mode (``str``, optional): - Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + parse_mode (``str``, *optional*): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in + the media caption. - reply_markup (:obj:`InlineKeyboardMarkup `, optional): + reply_markup (:obj:`InlineKeyboardMarkup `, *optional*): Inline keyboard attached to the message. - input_message_content (:obj:`InputMessageContent `, optional): + input_message_content (:obj:`InputMessageContent `, *optional*): Content of the message to be sent instead of the audio. """ - ID = 0xb0700018 - def __init__(self, type: str, id: str, audio_file_id: str, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): - self.type = type # string - self.id = id # string - self.audio_file_id = audio_file_id # string - self.caption = caption # flags.0?string - self.parse_mode = parse_mode # flags.1?string - self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup - self.input_message_content = input_message_content # flags.3?InputMessageContent + def __init__( + 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 + self.caption = caption + self.parse_mode = parse_mode + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + self.style = HTML() if parse_mode.lower() == "html" else Markdown() + + def write(self): + try: + decoded = utils.decode(self.audio_file_id) + fmt = " 24 else " Date: Fri, 9 Nov 2018 08:53:34 +0100 Subject: [PATCH 13/37] Fix InlineQuery ID --- pyrogram/client/types/bots/inline_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/bots/inline_query.py b/pyrogram/client/types/bots/inline_query.py index d90996de..128a6188 100644 --- a/pyrogram/client/types/bots/inline_query.py +++ b/pyrogram/client/types/bots/inline_query.py @@ -39,7 +39,7 @@ class InlineQuery(Object): location (:obj:`Location `. *optional*): Sender location, only for bots that request user location. """ - ID = 0xb0700024 + ID = 0xb0700032 def __init__( self, From aaded7564edd96fe76db8c60c196f99b1818e082 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 08:54:54 +0100 Subject: [PATCH 14/37] Clean up auto generated comments --- .../types/bots/inline_query_result_article.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/bots/inline_query_result_article.py index 991e8f11..82f64a04 100644 --- a/pyrogram/client/types/bots/inline_query_result_article.py +++ b/pyrogram/client/types/bots/inline_query_result_article.py @@ -68,16 +68,16 @@ class InlineQueryResultArticle: thumb_width: int = 0, thumb_height: int = 0 ): - self.id = id # string - self.title = title # string - self.input_message_content = input_message_content # flags.4?InputMessageContent - self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup + self.id = id + self.title = title + self.input_message_content = input_message_content + self.reply_markup = reply_markup self.url = url self.hide_url = hide_url - self.description = description # flags.2?string - self.thumb_url = thumb_url # flags.5?string - self.thumb_width = thumb_width # flags.6?int - self.thumb_height = thumb_height # flags.7?int + self.description = description + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height def write(self): return types.InputBotInlineResult( From c7fe5b810a5c8354437bfe1adf53612255ca4d5e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 09:13:20 +0100 Subject: [PATCH 15/37] Add InlineQueryResult type --- .../client/types/bots/inline_query_result.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pyrogram/client/types/bots/inline_query_result.py diff --git a/pyrogram/client/types/bots/inline_query_result.py b/pyrogram/client/types/bots/inline_query_result.py new file mode 100644 index 00000000..7225651e --- /dev/null +++ b/pyrogram/client/types/bots/inline_query_result.py @@ -0,0 +1,27 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 . + + +class InlineQueryResult: + """This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: + TODO: List types + """ + + def __init__(self, type: str, id: str): + self.type = type + self.id = id From b98345b20e64660af39b57f78ef9e0975f4bbdd8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 09:13:32 +0100 Subject: [PATCH 16/37] Add InputMessageContent type --- .../input_media/input_message_content.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyrogram/client/types/input_media/input_message_content.py diff --git a/pyrogram/client/types/input_media/input_message_content.py b/pyrogram/client/types/input_media/input_message_content.py new file mode 100644 index 00000000..fa901476 --- /dev/null +++ b/pyrogram/client/types/input_media/input_message_content.py @@ -0,0 +1,28 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 . + + +class InputMessageContent: + """This object represents the content of a message to be sent as a result of an inline query. + Telegram clients currently support the following 4 types: + + TODO: List types + """ + + def __init__(self): + pass From dfadf92742bb1d656ec48c118e9dbcb79d507074 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 09:14:03 +0100 Subject: [PATCH 17/37] Update InlineQueryResultArticle Inherit from InlineQueryResult --- .../types/bots/inline_query_result_article.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/bots/inline_query_result_article.py index 82f64a04..a6f14edb 100644 --- a/pyrogram/client/types/bots/inline_query_result_article.py +++ b/pyrogram/client/types/bots/inline_query_result_article.py @@ -17,9 +17,10 @@ # along with Pyrogram. If not, see . from pyrogram.api import types +from .inline_query_result import InlineQueryResult -class InlineQueryResultArticle: +class InlineQueryResultArticle(InlineQueryResult): """Represents a link to an article or web page. Args: @@ -64,11 +65,12 @@ class InlineQueryResultArticle: url: str = None, hide_url: bool = None, description: str = None, - thumb_url: str = "", + thumb_url: str = None, thumb_width: int = 0, thumb_height: int = 0 ): - self.id = id + super().__init__("article", id) + self.title = title self.input_message_content = input_message_content self.reply_markup = reply_markup @@ -82,7 +84,7 @@ class InlineQueryResultArticle: def write(self): return types.InputBotInlineResult( id=self.id, - type="article", + type=self.type, send_message=self.input_message_content.write(self.reply_markup), title=self.title, description=self.description, @@ -97,6 +99,5 @@ class InlineQueryResultArticle: h=self.thumb_height ) ] - ) if self.thumb_url else None, - content=None + ) if self.thumb_url else None ) From cfcfea99dd9df30138bc2ccb22f8c1bd0ac94513 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:07:46 +0100 Subject: [PATCH 18/37] Add missing comma, remove unneeded file read --- compiler/api/compiler.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 1baa12a7..6b1954c4 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -172,9 +172,8 @@ def start(): with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \ open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ - open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api, \ - open("{}/source/bot.tl".format(HOME), encoding="utf-8") as pyro: - schema = (auth.read() + system.read() + api.read() + pyro.read()).splitlines() + open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: + schema = (auth.read() + system.read() + api.read()).splitlines() with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f: mtproto_template = f.read() @@ -507,7 +506,7 @@ def start(): f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") f.write("\n 0xb0700029: \"pyrogram.client.types.Dialogs\",") f.write("\n 0xb0700030: \"pyrogram.client.types.ChatMembers\",") - f.write("\n 0xb0700031: \"pyrogram.client.types.UserStatus\"") + f.write("\n 0xb0700031: \"pyrogram.client.types.UserStatus\",") f.write("\n 0xb0700032: \"pyrogram.client.types.InlineQuery\"") f.write("\n}\n") From 07cb14de61e9a0cd237586a9ade57dad5726f668 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:08:28 +0100 Subject: [PATCH 19/37] Add InlineQueryHandler --- pyrogram/client/dispatcher/dispatcher.py | 10 +++- pyrogram/client/handlers/__init__.py | 1 + .../client/handlers/inline_query_handler.py | 54 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 pyrogram/client/handlers/inline_query_handler.py diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index fa65f987..9fecab7d 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -24,7 +24,10 @@ from threading import Thread from pyrogram.api import types from ..ext import utils -from ..handlers import CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, UserStatusHandler, RawUpdateHandler +from ..handlers import ( + CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, + UserStatusHandler, RawUpdateHandler, InlineQueryHandler +) log = logging.getLogger(__name__) @@ -73,7 +76,10 @@ class Dispatcher: lambda upd, usr, cht: (utils.parse_callback_query(self.client, upd, usr), CallbackQueryHandler), (types.UpdateUserStatus,): - lambda upd, usr, cht: (utils.parse_user_status(upd.status, upd.user_id), UserStatusHandler) + lambda upd, usr, cht: (utils.parse_user_status(upd.status, upd.user_id), UserStatusHandler), + + (types.UpdateBotInlineQuery,): + lambda upd, usr, cht: (utils.parse_inline_query(self.client, upd, usr), InlineQueryHandler) } Dispatcher.UPDATES = {key: value for key_tuple, value in Dispatcher.UPDATES.items() for key in key_tuple} diff --git a/pyrogram/client/handlers/__init__.py b/pyrogram/client/handlers/__init__.py index ff1ead7a..7c7f7efd 100644 --- a/pyrogram/client/handlers/__init__.py +++ b/pyrogram/client/handlers/__init__.py @@ -19,6 +19,7 @@ from .callback_query_handler import CallbackQueryHandler from .deleted_messages_handler import DeletedMessagesHandler from .disconnect_handler import DisconnectHandler +from .inline_query_handler import InlineQueryHandler from .message_handler import MessageHandler from .raw_update_handler import RawUpdateHandler from .user_status_handler import UserStatusHandler diff --git a/pyrogram/client/handlers/inline_query_handler.py b/pyrogram/client/handlers/inline_query_handler.py new file mode 100644 index 00000000..e59514c0 --- /dev/null +++ b/pyrogram/client/handlers/inline_query_handler.py @@ -0,0 +1,54 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 .handler import Handler + + +class InlineQueryHandler(Handler): + """The InlineQuery handler class. Used to handle inline queries. + It is intended to be used with :meth:`add_handler() ` + + For a nicer way to register this handler, have a look at the + :meth:`on_inline_query() ` decorator. + + Args: + callback (``callable``): + Pass a function that will be called when a new InlineQuery arrives. It takes *(client, inline_query)* + as positional arguments (look at the section below for a detailed description). + + filters (:obj:`Filters `): + Pass one or more filters to allow only a subset of inline queries to be passed + in your callback function. + + Other parameters: + client (:obj:`Client `): + The Client itself, useful when you want to call other API methods inside the inline query handler. + + inline_query (:obj:`InlineQuery `): + The received inline query. + """ + + def __init__(self, callback: callable, filters=None): + super().__init__(callback, filters) + + def check(self, callback_query): + return ( + self.filters(callback_query) + if callable(self.filters) + else True + ) From 55cca004018f9175d6c5579fe54efa92620c865d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:08:50 +0100 Subject: [PATCH 20/37] Add on_inline_query decorator --- .../client/methods/decorators/__init__.py | 4 +- .../methods/decorators/on_inline_query.py | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/decorators/on_inline_query.py diff --git a/pyrogram/client/methods/decorators/__init__.py b/pyrogram/client/methods/decorators/__init__.py index 6cf9940a..c9ba80e5 100644 --- a/pyrogram/client/methods/decorators/__init__.py +++ b/pyrogram/client/methods/decorators/__init__.py @@ -19,6 +19,7 @@ from .on_callback_query import OnCallbackQuery from .on_deleted_messages import OnDeletedMessages from .on_disconnect import OnDisconnect +from .on_inline_query import OnInlineQuery from .on_message import OnMessage from .on_raw_update import OnRawUpdate from .on_user_status import OnUserStatus @@ -30,6 +31,7 @@ class Decorators( OnCallbackQuery, OnRawUpdate, OnDisconnect, - OnUserStatus + OnUserStatus, + OnInlineQuery ): pass diff --git a/pyrogram/client/methods/decorators/on_inline_query.py b/pyrogram/client/methods/decorators/on_inline_query.py new file mode 100644 index 00000000..c104be62 --- /dev/null +++ b/pyrogram/client/methods/decorators/on_inline_query.py @@ -0,0 +1,50 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 . + +import pyrogram +from pyrogram.client.filters.filter import Filter +from ...ext import BaseClient + + +class OnInlineQuery(BaseClient): + def on_inline_query(self, filters=None, group: int = 0): + """Use this decorator to automatically register a function for handling + inline queries. This does the same thing as :meth:`add_handler` using the + :class:`InlineQueryHandler`. + + Args: + filters (:obj:`Filters `): + Pass one or more filters to allow only a subset of inline queries to be passed + in your function. + + group (``int``, *optional*): + The group identifier, defaults to 0. + """ + + def decorator(func): + handler = pyrogram.InlineQueryHandler(func, filters) + + if isinstance(self, Filter): + return pyrogram.InlineQueryHandler(func, self), group if filters is None else filters + + if self is not None: + self.add_handler(handler, group) + + return handler, group + + return decorator From 06797d32f093e8abc943a2dd62d879800b7d2251 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:09:27 +0100 Subject: [PATCH 21/37] Add InlineQueryResult super class --- pyrogram/client/types/bots/__init__.py | 1 + .../client/types/bots/inline_query_result.py | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/bots/__init__.py b/pyrogram/client/types/bots/__init__.py index 6f350a21..8e179ca0 100644 --- a/pyrogram/client/types/bots/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -21,6 +21,7 @@ from .force_reply import ForceReply 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 diff --git a/pyrogram/client/types/bots/inline_query_result.py b/pyrogram/client/types/bots/inline_query_result.py index 7225651e..7c4c0c30 100644 --- a/pyrogram/client/types/bots/inline_query_result.py +++ b/pyrogram/client/types/bots/inline_query_result.py @@ -18,8 +18,29 @@ class InlineQueryResult: - """This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: - TODO: List types + """This object represents one result of an inline query. + Pyrogram currently supports results of the following 20 types: + + - :obj:`InlineQueryResultCachedAudio` + - :obj:`InlineQueryResultCachedDocument` + - :obj:`InlineQueryResultCachedGif` + - :obj:`InlineQueryResultCachedMpeg4Gif` + - :obj:`InlineQueryResultCachedPhoto` + - :obj:`InlineQueryResultCachedSticker` + - :obj:`InlineQueryResultCachedVideo` + - :obj:`InlineQueryResultCachedVoice` + - :obj:`InlineQueryResultArticle` + - :obj:`InlineQueryResultAudio` + - :obj:`InlineQueryResultContact` + - :obj:`InlineQueryResultGame` + - :obj:`InlineQueryResultDocument` + - :obj:`InlineQueryResultGif` + - :obj:`InlineQueryResultLocation` + - :obj:`InlineQueryResultMpeg4Gif` + - :obj:`InlineQueryResultPhoto` + - :obj:`InlineQueryResultVenue` + - :obj:`InlineQueryResultVideo` + - :obj:`InlineQueryResultVoice` """ def __init__(self, type: str, id: str): From 5ed904a2e4eef6703e74a99770d6060f443a10f2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:15:20 +0100 Subject: [PATCH 22/37] Update inline_query_result_article --- pyrogram/client/types/bots/inline_query_result_article.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/bots/inline_query_result_article.py b/pyrogram/client/types/bots/inline_query_result_article.py index a6f14edb..6325e174 100644 --- a/pyrogram/client/types/bots/inline_query_result_article.py +++ b/pyrogram/client/types/bots/inline_query_result_article.py @@ -23,6 +23,8 @@ from .inline_query_result import InlineQueryResult class InlineQueryResultArticle(InlineQueryResult): """Represents a link to an article or web page. + TODO: Hide url? + Args: id (``str``): Unique identifier for this result, 1-64 bytes. @@ -39,9 +41,6 @@ class InlineQueryResultArticle(InlineQueryResult): url (``str``, *optional*): URL of the result - hide_url (``bool``, *optional*): - Pass True, if you don't want the URL to be shown in the message - description (``str``, optional): Short description of the result @@ -63,7 +62,6 @@ class InlineQueryResultArticle(InlineQueryResult): input_message_content, reply_markup=None, url: str = None, - hide_url: bool = None, description: str = None, thumb_url: str = None, thumb_width: int = 0, @@ -75,7 +73,6 @@ class InlineQueryResultArticle(InlineQueryResult): self.input_message_content = input_message_content self.reply_markup = reply_markup self.url = url - self.hide_url = hide_url self.description = description self.thumb_url = thumb_url self.thumb_width = thumb_width From 1ab17d801553f3e2ef86723b54aac70b42cdd5b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:15:54 +0100 Subject: [PATCH 23/37] Fix InputTextMessageContent with empty reply markups --- pyrogram/client/types/input_media/input_text_message_content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/input_media/input_text_message_content.py b/pyrogram/client/types/input_media/input_text_message_content.py index 1dffff43..3c74d34d 100644 --- a/pyrogram/client/types/input_media/input_text_message_content.py +++ b/pyrogram/client/types/input_media/input_text_message_content.py @@ -31,6 +31,6 @@ class InputTextMessageContent: def write(self, reply_markup): return types.InputBotInlineMessageText( no_webpage=self.disable_web_page_preview or None, - reply_markup=reply_markup.write(), + reply_markup=reply_markup.write() if reply_markup else None, **self.style.parse(self.message_text) ) From ebfb64e139104ee413173160c2c2069551f28976 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:16:27 +0100 Subject: [PATCH 24/37] Add InputMessageContent docstrings --- .../client/types/input_media/input_message_content.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/input_media/input_message_content.py b/pyrogram/client/types/input_media/input_message_content.py index fa901476..1479bf63 100644 --- a/pyrogram/client/types/input_media/input_message_content.py +++ b/pyrogram/client/types/input_media/input_message_content.py @@ -19,9 +19,13 @@ class InputMessageContent: """This object represents the content of a message to be sent as a result of an inline query. - Telegram clients currently support the following 4 types: - TODO: List types + Pyrogram currently supports the following 4 types: + + - :obj:`InputTextMessageContent` + - :obj:`InputLocationMessageContent` + - :obj:`InputVenueMessageContent` + - :obj:`InputContactMessageContent` """ def __init__(self): From 97e705f833d1cba105b2e3c0afdd7c0912b58711 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:16:44 +0100 Subject: [PATCH 25/37] Make new types importable --- pyrogram/__init__.py | 6 ++++-- pyrogram/client/__init__.py | 3 ++- pyrogram/client/types/__init__.py | 4 ++-- pyrogram/client/types/input_media/__init__.py | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 8b5aaf1b..258c11c2 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,10 +32,12 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserStatus, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, InlineQueryResultCachedAudio + InlineQuery, InlineQueryResult, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, + InlineQueryResultCachedAudio, InputMessageContent ) from .client import ( Client, ChatAction, ParseMode, Emoji, MessageHandler, DeletedMessagesHandler, CallbackQueryHandler, - RawUpdateHandler, DisconnectHandler, UserStatusHandler, Filters + RawUpdateHandler, DisconnectHandler, UserStatusHandler, Filters, + InlineQueryHandler ) diff --git a/pyrogram/client/__init__.py b/pyrogram/client/__init__.py index 00b9905a..e83c9387 100644 --- a/pyrogram/client/__init__.py +++ b/pyrogram/client/__init__.py @@ -22,5 +22,6 @@ from .filters import Filters from .handlers import ( MessageHandler, DeletedMessagesHandler, CallbackQueryHandler, RawUpdateHandler, - DisconnectHandler, UserStatusHandler + DisconnectHandler, UserStatusHandler, + InlineQueryHandler ) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index ce321038..fbc3d7da 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -18,7 +18,7 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, InlineQueryResult, InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio ) from .bots import ( @@ -27,7 +27,7 @@ from .bots import ( ) from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, - InputMediaDocument, InputMediaAnimation, InputTextMessageContent + InputMediaDocument, InputMediaAnimation, InputMessageContent, InputTextMessageContent ) from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py index 3a8f9b16..737fbb40 100644 --- a/pyrogram/client/types/input_media/__init__.py +++ b/pyrogram/client/types/input_media/__init__.py @@ -22,5 +22,6 @@ 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 From 5bff8236b57f31cca59ab25718e49bba716bd4de Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:17:00 +0100 Subject: [PATCH 26/37] Add Inline Mode section to docs --- docs/source/pyrogram/Types.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst index 8763c0e1..d51ebdc9 100644 --- a/docs/source/pyrogram/Types.rst +++ b/docs/source/pyrogram/Types.rst @@ -68,6 +68,17 @@ Input Media InputMediaDocument InputPhoneContact +Inline Mode +------------ + +.. autosummary:: + :nosignatures: + + InlineQueryResult + InlineQueryResultArticle + InputMessageContent + InputTextMessageContent + .. User & Chats ------------ @@ -190,3 +201,19 @@ Input Media .. autoclass:: InputPhoneContact :members: + + +.. Inline Mode + ----------- + +.. autoclass:: InlineQueryResult + :members: + +.. autoclass:: InlineQueryResultArticle + :members: + +.. autoclass:: InputMessageContent + :members: + +.. autoclass:: InputTextMessageContent + :members: From 72bad9622a76f63b4600a0169282f9f213c30a83 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:21:10 +0100 Subject: [PATCH 27/37] Add RESULTS_TOO_MUCH error --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 382e521e..8bb7735d 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -68,4 +68,5 @@ USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side USER_NOT_PARTICIPANT The user is not a member of this chat CHANNEL_PRIVATE The channel/supergroup is not accessible -MESSAGE_IDS_EMPTY The requested message doesn't exist \ No newline at end of file +MESSAGE_IDS_EMPTY The requested message doesn't exist +RESULTS_TOO_MUCH You have put too many items in your result \ No newline at end of file From c71d6781a22d80137935a31ee3d50e096bcb03a4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:22:27 +0100 Subject: [PATCH 28/37] Add RESULT_ID_DUPLICATE error --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 8bb7735d..a2df7317 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -69,4 +69,5 @@ API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server si USER_NOT_PARTICIPANT The user is not a member of this chat CHANNEL_PRIVATE The channel/supergroup is not accessible MESSAGE_IDS_EMPTY The requested message doesn't exist -RESULTS_TOO_MUCH You have put too many items in your result \ No newline at end of file +RESULTS_TOO_MUCH You have put too many items in your result +RESULT_ID_DUPLICATE The result contains items with duplicated identifiers \ No newline at end of file From b9a82f5dc5eea1f8be6178f0d4dd83e8833978ff Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 9 Nov 2018 13:22:48 +0100 Subject: [PATCH 29/37] Reword RESULTS_TOO_MUCH --- compiler/error/source/400_BAD_REQUEST.tsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index a2df7317..636aba21 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -69,5 +69,5 @@ API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server si USER_NOT_PARTICIPANT The user is not a member of this chat CHANNEL_PRIVATE The channel/supergroup is not accessible MESSAGE_IDS_EMPTY The requested message doesn't exist -RESULTS_TOO_MUCH You have put too many items in your result +RESULTS_TOO_MUCH The result contains too many items RESULT_ID_DUPLICATE The result contains items with duplicated identifiers \ No newline at end of file From fede74398cae6d0507018f7c083473d3d7b01499 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 21 Mar 2019 18:37:00 +0100 Subject: [PATCH 30/37] Fix inline-mode branch breaking after many commits from develop --- pyrogram/client/dispatcher/dispatcher.py | 2 +- pyrogram/client/ext/base_client.py | 3 + .../methods/bots/answer_inline_query.py | 22 ++++--- .../methods/decorators/on_inline_query.py | 14 ++++- pyrogram/client/types/bots/inline_query.py | 63 ++++++++++++++++--- 5 files changed, 81 insertions(+), 23 deletions(-) diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index f651ce18..43f80ebb 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -80,7 +80,7 @@ class Dispatcher: ), (types.UpdateBotInlineQuery,): - lambda upd, usr, cht: (utils.parse_inline_query(self.client, upd, usr), InlineQueryHandler) + lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler) } self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple} diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index c90d5e8a..8c994ece 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -129,3 +129,6 @@ class BaseClient: def get_chat_members_count(self, *args, **kwargs): pass + + def answer_inline_query(self, *args, **kwargs): + pass diff --git a/pyrogram/client/methods/bots/answer_inline_query.py b/pyrogram/client/methods/bots/answer_inline_query.py index 07eb594d..49328d40 100644 --- a/pyrogram/client/methods/bots/answer_inline_query.py +++ b/pyrogram/client/methods/bots/answer_inline_query.py @@ -21,14 +21,16 @@ from pyrogram.client.ext import BaseClient class AnswerInlineQuery(BaseClient): - def answer_inline_query(self, - inline_query_id: str, - results: list, - cache_time: int = 300, - is_personal: bool = None, - next_offset: str = "", - switch_pm_text: str = "", - switch_pm_parameter: str = ""): + def answer_inline_query( + self, + inline_query_id: str, + results: list, + cache_time: int = 300, + is_personal: bool = None, + next_offset: str = "", + switch_pm_text: str = "", + switch_pm_parameter: str = "" + ): # TODO: Docs return self.send( functions.messages.SetInlineBotResults( @@ -39,8 +41,8 @@ class AnswerInlineQuery(BaseClient): private=is_personal or None, next_offset=next_offset or None, switch_pm=types.InlineBotSwitchPM( - switch_pm_text, - switch_pm_parameter + text=switch_pm_text, + start_param=switch_pm_parameter ) if switch_pm_text else None ) ) diff --git a/pyrogram/client/methods/decorators/on_inline_query.py b/pyrogram/client/methods/decorators/on_inline_query.py index c104be62..d4e96261 100644 --- a/pyrogram/client/methods/decorators/on_inline_query.py +++ b/pyrogram/client/methods/decorators/on_inline_query.py @@ -16,13 +16,20 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Tuple + import pyrogram from pyrogram.client.filters.filter import Filter +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnInlineQuery(BaseClient): - def on_inline_query(self, filters=None, group: int = 0): + def on_inline_query( + self=None, + filters=None, + group: int = 0 + ) -> callable: """Use this decorator to automatically register a function for handling inline queries. This does the same thing as :meth:`add_handler` using the :class:`InlineQueryHandler`. @@ -36,7 +43,10 @@ class OnInlineQuery(BaseClient): The group identifier, defaults to 0. """ - def decorator(func): + def decorator(func: callable) -> Tuple[Handler, int]: + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.InlineQueryHandler(func, filters) if isinstance(self, Filter): diff --git a/pyrogram/client/types/bots/inline_query.py b/pyrogram/client/types/bots/inline_query.py index 128a6188..3c311468 100644 --- a/pyrogram/client/types/bots/inline_query.py +++ b/pyrogram/client/types/bots/inline_query.py @@ -16,10 +16,17 @@ # 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 typing import List + +import pyrogram +from pyrogram.api import types +from ..bots.inline_query_result import InlineQueryResult +from ..messages_and_media import Location +from ..pyrogram_type import PyrogramType +from ..user_and_chats import User -class InlineQuery(Object): +class InlineQuery(PyrogramType): """This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results @@ -39,20 +46,56 @@ class InlineQuery(Object): location (:obj:`Location `. *optional*): Sender location, only for bots that request user location. """ - ID = 0xb0700032 + __slots__ = ["id", "from_user", "query", "offset", "location"] def __init__( - self, - client, - id: str, - from_user, - query: str, - offset: str, - location=None, + self, + client: "pyrogram.client.ext.BaseClient", + id: str, + from_user: User, + query: str, + offset: str, + location: Location = None ): + super().__init__(client) + self._client = client self.id = id self.from_user = from_user self.query = query self.offset = offset self.location = location + + @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, + offset=inline_query.offset, + location=Location( + longitude=inline_query.geo.long, + latitude=inline_query.geo.lat, + client=client + ) if inline_query.geo else None + ) + + def answer( + self, + results: List[InlineQueryResult], + cache_time: int = 300, + is_personal: bool = None, + next_offset: str = "", + switch_pm_text: str = "", + switch_pm_parameter: str = "" + ): + return self._client.answer_inline_query( + inline_query_id=self.id, + results=results, + cache_time=cache_time, + is_personal=is_personal, + next_offset=next_offset, + switch_pm_text=switch_pm_text, + switch_pm_parameter=switch_pm_parameter + ) From 4138e668c0cc7a5434c1fd80563af63727303d4b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 21 Mar 2019 19:02:31 +0100 Subject: [PATCH 31/37] Remove trailing slashes from links --- docs/source/index.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 6a333d6d..c3b082db 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -115,7 +115,7 @@ To get started, press the Next button. functions/index types/index -.. _`Telegram`: https://telegram.org/ -.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto/ +.. _`Telegram`: https://telegram.org +.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto .. _`MTProto API`: https://core.telegram.org/api#telegram-api -.. _`MTProto 2.0`: https://core.telegram.org/mtproto \ No newline at end of file +.. _`MTProto 2.0`: https://core.telegram.org/mtproto From bc9f9023760885699a6e35e858c00954d02060d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 11:35:35 +0100 Subject: [PATCH 32/37] Clean up inline-mode --- docs/source/pyrogram/Client.rst | 1 + docs/source/pyrogram/Types.rst | 14 +++++ pyrogram/__init__.py | 8 +-- .../methods/bots/answer_inline_query.py | 47 +++++++++++++- pyrogram/client/types/__init__.py | 15 ++--- pyrogram/client/types/bots/__init__.py | 22 ------- pyrogram/client/types/inline_mode/__init__.py | 21 +++++++ .../{bots => inline_mode}/inline_query.py | 61 +++++++++++++++++-- .../inline_query_result.py | 25 +++++--- .../inline_query_result_article.py | 40 ++++++------ .../todo}/inline_query_result_audio.py | 5 +- .../todo}/inline_query_result_cached_audio.py | 17 +++--- .../inline_query_result_cached_document.py | 4 +- .../todo}/inline_query_result_cached_gif.py | 4 +- .../inline_query_result_cached_mpeg4_gif.py | 4 +- .../todo}/inline_query_result_cached_photo.py | 4 +- .../inline_query_result_cached_sticker.py | 4 +- .../todo}/inline_query_result_cached_video.py | 4 +- .../todo}/inline_query_result_cached_voice.py | 4 +- .../todo}/inline_query_result_contact.py | 4 +- .../todo}/inline_query_result_document.py | 4 +- .../todo}/inline_query_result_game.py | 4 +- .../todo}/inline_query_result_gif.py | 4 +- .../todo}/inline_query_result_location.py | 4 +- .../todo}/inline_query_result_mpeg4_gif.py | 4 +- .../todo}/inline_query_result_photo.py | 3 +- .../todo}/inline_query_result_venue.py | 4 +- .../todo}/inline_query_result_video.py | 4 +- .../todo}/inline_query_result_voice.py | 4 +- pyrogram/client/types/input_media/__init__.py | 2 - .../types/input_message_content/__init__.py | 20 ++++++ .../input_message_content.py | 15 +++-- .../input_text_message_content.py | 28 +++++++-- 33 files changed, 287 insertions(+), 121 deletions(-) create mode 100644 pyrogram/client/types/inline_mode/__init__.py rename pyrogram/client/types/{bots => inline_mode}/inline_query.py (53%) rename pyrogram/client/types/{bots => inline_mode}/inline_query_result.py (86%) rename pyrogram/client/types/{bots => inline_mode}/inline_query_result_article.py (77%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_audio.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_audio.py (92%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_document.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_gif.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_mpeg4_gif.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_photo.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_sticker.py (94%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_video.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_cached_voice.py (95%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_contact.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_document.py (97%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_game.py (93%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_gif.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_location.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_mpeg4_gif.py (96%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_photo.py (97%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_venue.py (97%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_video.py (97%) rename pyrogram/client/types/{bots => inline_mode/todo}/inline_query_result_voice.py (96%) create mode 100644 pyrogram/client/types/input_message_content/__init__.py rename pyrogram/client/types/{input_media => input_message_content}/input_message_content.py (83%) rename pyrogram/client/types/{input_media => input_message_content}/input_text_message_content.py (57%) 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) ) From 921800f90252a60c946abee710039e3222343561 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 11:53:25 +0100 Subject: [PATCH 33/37] Clean up docstrings --- .../methods/bots/request_callback_answer.py | 4 ++-- pyrogram/client/methods/chats/get_chat.py | 5 +++-- pyrogram/client/methods/chats/get_dialogs.py | 2 +- .../methods/chats/restrict_chat_member.py | 7 ++++--- .../methods/contacts/delete_contacts.py | 2 +- .../methods/decorators/on_callback_query.py | 5 ++--- .../methods/decorators/on_deleted_messages.py | 5 ++--- .../methods/decorators/on_disconnect.py | 5 ++--- .../methods/decorators/on_inline_query.py | 5 ++--- .../client/methods/decorators/on_message.py | 5 ++--- .../methods/decorators/on_raw_update.py | 5 ++--- .../methods/decorators/on_user_status.py | 5 ++--- .../methods/messages/delete_messages.py | 4 +++- .../client/methods/messages/download_media.py | 2 +- .../users/delete_user_profile_photos.py | 2 +- pyrogram/client/types/bots/force_reply.py | 5 +++-- .../types/bots/reply_keyboard_remove.py | 7 +++---- .../client/types/input_media/input_media.py | 21 ++++++++++++------- .../types/input_media/input_phone_contact.py | 12 ++++------- .../types/messages_and_media/video_note.py | 2 +- .../client/types/user_and_chats/dialogs.py | 2 +- 21 files changed, 56 insertions(+), 56 deletions(-) diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index 0d440fd9..87247126 100644 --- a/pyrogram/client/methods/bots/request_callback_answer.py +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -29,8 +29,8 @@ class RequestCallbackAnswer(BaseClient): message_id: int, callback_data: bytes ): - """Use this method to request a callback answer from bots. This is the equivalent of clicking an - inline button containing callback data. + """Use this method to request a callback answer from bots. + This is the equivalent of clicking an inline button containing callback data. Args: chat_id (``int`` | ``str``): diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index 89a72722..31e0a293 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -28,8 +28,9 @@ class GetChat(BaseClient): self, chat_id: Union[int, str] ) -> "pyrogram.Chat": - """Use this method to get up to date information about the chat (current name of the user for - one-on-one conversations, current username of a user, group or channel, etc.) + """Use this method to get up to date information about the chat. + Information include current name of the user for one-on-one conversations, current username of a user, group or + channel, etc. Args: chat_id (``int`` | ``str``): diff --git a/pyrogram/client/methods/chats/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py index b73d0efa..e062a00b 100644 --- a/pyrogram/client/methods/chats/get_dialogs.py +++ b/pyrogram/client/methods/chats/get_dialogs.py @@ -34,7 +34,7 @@ class GetDialogs(BaseClient): limit: int = 100, pinned_only: bool = False ) -> "pyrogram.Dialogs": - """Use this method to get a chunk of the user's dialogs + """Use this method to get a chunk of the user's dialogs. You can get up to 100 dialogs at once. For a more convenient way of getting a user's dialogs see :meth:`iter_dialogs`. diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index d75d1fa4..72788188 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -38,9 +38,10 @@ class RestrictChatMember(BaseClient): can_invite_users: bool = False, can_pin_messages: bool = False ) -> Chat: - """Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for - this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift - restrictions from a user. + """Use this method to restrict a user in a supergroup. + + The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. + Pass True for all boolean parameters to lift restrictions from a user. Args: chat_id (``int`` | ``str``): diff --git a/pyrogram/client/methods/contacts/delete_contacts.py b/pyrogram/client/methods/contacts/delete_contacts.py index c7e7c0e6..7ac6d02a 100644 --- a/pyrogram/client/methods/contacts/delete_contacts.py +++ b/pyrogram/client/methods/contacts/delete_contacts.py @@ -28,7 +28,7 @@ class DeleteContacts(BaseClient): self, ids: List[int] ): - """Use this method to delete contacts from your Telegram address book + """Use this method to delete contacts from your Telegram address book. Args: ids (List of ``int``): diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index f030f929..18aed7d5 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -30,9 +30,8 @@ class OnCallbackQuery(BaseClient): filters=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - callback queries. This does the same thing as :meth:`add_handler` using the - :class:`CallbackQueryHandler`. + """Use this decorator to automatically register a function for handling callback queries. + This does the same thing as :meth:`add_handler` using the :class:`CallbackQueryHandler`. .. note:: This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*. diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index b5a95381..b32889ef 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -30,9 +30,8 @@ class OnDeletedMessages(BaseClient): filters=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - deleted messages. This does the same thing as :meth:`add_handler` using the - :class:`DeletedMessagesHandler`. + """Use this decorator to automatically register a function for handling deleted messages. + This does the same thing as :meth:`add_handler` using the :class:`DeletedMessagesHandler`. .. note:: This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*. diff --git a/pyrogram/client/methods/decorators/on_disconnect.py b/pyrogram/client/methods/decorators/on_disconnect.py index 4657af3b..515a28c1 100644 --- a/pyrogram/client/methods/decorators/on_disconnect.py +++ b/pyrogram/client/methods/decorators/on_disconnect.py @@ -23,9 +23,8 @@ from ...ext import BaseClient class OnDisconnect(BaseClient): def on_disconnect(self=None) -> callable: - """Use this decorator to automatically register a function for handling - disconnections. This does the same thing as :meth:`add_handler` using the - :class:`DisconnectHandler`. + """Use this decorator to automatically register a function for handling disconnections. + This does the same thing as :meth:`add_handler` using the :class:`DisconnectHandler`. """ def decorator(func: callable) -> Handler: diff --git a/pyrogram/client/methods/decorators/on_inline_query.py b/pyrogram/client/methods/decorators/on_inline_query.py index d4e96261..81f0f676 100644 --- a/pyrogram/client/methods/decorators/on_inline_query.py +++ b/pyrogram/client/methods/decorators/on_inline_query.py @@ -30,9 +30,8 @@ class OnInlineQuery(BaseClient): filters=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - inline queries. This does the same thing as :meth:`add_handler` using the - :class:`InlineQueryHandler`. + """Use this decorator to automatically register a function for handling inline queries. + This does the same thing as :meth:`add_handler` using the :class:`InlineQueryHandler`. Args: filters (:obj:`Filters `): diff --git a/pyrogram/client/methods/decorators/on_message.py b/pyrogram/client/methods/decorators/on_message.py index 41eb73e5..9bbd96c1 100644 --- a/pyrogram/client/methods/decorators/on_message.py +++ b/pyrogram/client/methods/decorators/on_message.py @@ -30,9 +30,8 @@ class OnMessage(BaseClient): filters=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - messages. This does the same thing as :meth:`add_handler` using the - :class:`MessageHandler`. + """Use this decorator to automatically register a function for handling messages. + This does the same thing as :meth:`add_handler` using the :class:`MessageHandler`. .. note:: This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*. diff --git a/pyrogram/client/methods/decorators/on_raw_update.py b/pyrogram/client/methods/decorators/on_raw_update.py index a176ab50..cf1da94d 100644 --- a/pyrogram/client/methods/decorators/on_raw_update.py +++ b/pyrogram/client/methods/decorators/on_raw_update.py @@ -28,9 +28,8 @@ class OnRawUpdate(BaseClient): self=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - raw updates. This does the same thing as :meth:`add_handler` using the - :class:`RawUpdateHandler`. + """Use this decorator to automatically register a function for handling raw updates. + This does the same thing as :meth:`add_handler` using the :class:`RawUpdateHandler`. .. note:: This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*. diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py index 580dc498..5f962270 100644 --- a/pyrogram/client/methods/decorators/on_user_status.py +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -30,9 +30,8 @@ class OnUserStatus(BaseClient): filters=None, group: int = 0 ) -> callable: - """Use this decorator to automatically register a function for handling - user status updates. This does the same thing as :meth:`add_handler` using the - :class:`UserStatusHandler`. + """Use this decorator to automatically register a function for handling user status updates. + This does the same thing as :meth:`add_handler` using the :class:`UserStatusHandler`. .. note:: This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*. diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index 8ea729ff..df26aff6 100644 --- a/pyrogram/client/methods/messages/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -29,7 +29,9 @@ class DeleteMessages(BaseClient): message_ids: Iterable[int], revoke: bool = True ) -> bool: - """Use this method to delete messages, including service messages, with the following limitations: + """Use this method to delete messages, including service messages. + + Deleting messages have the following limitations: - A message can only be deleted if it was sent less than 48 hours ago. - Users can delete outgoing messages in groups and supergroups. diff --git a/pyrogram/client/methods/messages/download_media.py b/pyrogram/client/methods/messages/download_media.py index 29ba7af5..6fc47601 100644 --- a/pyrogram/client/methods/messages/download_media.py +++ b/pyrogram/client/methods/messages/download_media.py @@ -32,7 +32,7 @@ class DownloadMedia(BaseClient): progress: callable = None, progress_args: tuple = () ) -> Union[str, None]: - """Use this method to download the media from a Message. + """Use this method to download the media from a message. Args: message (:obj:`Message ` | ``str``): diff --git a/pyrogram/client/methods/users/delete_user_profile_photos.py b/pyrogram/client/methods/users/delete_user_profile_photos.py index 84c68dd4..6c0eb8d2 100644 --- a/pyrogram/client/methods/users/delete_user_profile_photos.py +++ b/pyrogram/client/methods/users/delete_user_profile_photos.py @@ -29,7 +29,7 @@ class DeleteUserProfilePhotos(BaseClient): self, id: Union[str, List[str]] ) -> bool: - """Use this method to delete your own profile photos + """Use this method to delete your own profile photos. Args: id (``str`` | ``list``): diff --git a/pyrogram/client/types/bots/force_reply.py b/pyrogram/client/types/bots/force_reply.py index fca2c061..12969742 100644 --- a/pyrogram/client/types/bots/force_reply.py +++ b/pyrogram/client/types/bots/force_reply.py @@ -21,8 +21,9 @@ from ..pyrogram_type import PyrogramType class ForceReply(PyrogramType): - """Upon receiving a message with this object, Telegram clients will display a reply interface to the user - (act as if the user has selected the bot's message and tapped 'Reply'). + """Upon receiving a message with this object, Telegram clients will display a reply interface to the user. + + This acts as if the user has selected the bot's message and tapped "Reply". This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. diff --git a/pyrogram/client/types/bots/reply_keyboard_remove.py b/pyrogram/client/types/bots/reply_keyboard_remove.py index 3298ab6f..75f2a7b5 100644 --- a/pyrogram/client/types/bots/reply_keyboard_remove.py +++ b/pyrogram/client/types/bots/reply_keyboard_remove.py @@ -21,10 +21,9 @@ from ..pyrogram_type import PyrogramType class ReplyKeyboardRemove(PyrogramType): - """Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and - display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent - by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a - button (see ReplyKeyboardMarkup). + """Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. + By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time + keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). Args: selective (``bool``, *optional*): diff --git a/pyrogram/client/types/input_media/input_media.py b/pyrogram/client/types/input_media/input_media.py index aeeef350..3062f136 100644 --- a/pyrogram/client/types/input_media/input_media.py +++ b/pyrogram/client/types/input_media/input_media.py @@ -16,16 +16,23 @@ # 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 InputMedia: + +class InputMedia(PyrogramType): + """This object represents the content of a media message to be sent. It should be one of: + + - :obj:`InputMediaAnimation ` + - :obj:`InputMediaDocument ` + - :obj:`InputMediaAudio ` + - :obj:`InputMediaPhoto ` + - :obj:`InputMediaVideo ` + """ __slots__ = ["media", "caption", "parse_mode"] - def __init__( - self, - media: str, - caption: str, - parse_mode: str - ): + def __init__(self, media: str, caption: str, parse_mode: str): + super().__init__(None) + self.media = media self.caption = caption self.parse_mode = parse_mode diff --git a/pyrogram/client/types/input_media/input_phone_contact.py b/pyrogram/client/types/input_media/input_phone_contact.py index 4fe7ee60..d2ac8012 100644 --- a/pyrogram/client/types/input_media/input_phone_contact.py +++ b/pyrogram/client/types/input_media/input_phone_contact.py @@ -18,9 +18,10 @@ from pyrogram.api.types import InputPhoneContact as RawInputPhoneContact from pyrogram.session.internals import MsgId +from ..pyrogram_type import PyrogramType -class InputPhoneContact: +class InputPhoneContact(PyrogramType): """This object represents a Phone Contact to be added in your Telegram address book. It is intended to be used with :meth:`add_contacts() ` @@ -37,13 +38,8 @@ class InputPhoneContact: __slots__ = [] - def __init__( - self, - phone: str, - first_name: str, - last_name: str = "" - ): - pass + def __init__(self, phone: str, first_name: str, last_name: str = ""): + super().__init__(None) def __new__(cls, phone: str, diff --git a/pyrogram/client/types/messages_and_media/video_note.py b/pyrogram/client/types/messages_and_media/video_note.py index a1b3856c..e6c2ab31 100644 --- a/pyrogram/client/types/messages_and_media/video_note.py +++ b/pyrogram/client/types/messages_and_media/video_note.py @@ -26,7 +26,7 @@ from ...ext.utils import encode class VideoNote(PyrogramType): - """This object represents a video message (available in Telegram apps as of v.4.0). + """This object represents a video note. Args: file_id (``str``): diff --git a/pyrogram/client/types/user_and_chats/dialogs.py b/pyrogram/client/types/user_and_chats/dialogs.py index bd29ea83..431cca8d 100644 --- a/pyrogram/client/types/user_and_chats/dialogs.py +++ b/pyrogram/client/types/user_and_chats/dialogs.py @@ -26,7 +26,7 @@ from ..pyrogram_type import PyrogramType class Dialogs(PyrogramType): - """This object represents a user's dialogs chunk + """This object represents a user's dialogs chunk. Args: total_count (``int``): From f0138ce555f87ea3d8a1950d4de050a2016111f5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 11:58:49 +0100 Subject: [PATCH 34/37] Fix Inline buttons parsing --- pyrogram/client/types/bots/inline_keyboard_button.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index ff6f3cdb..c0c3eb8c 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -110,21 +110,21 @@ class InlineKeyboardButton(PyrogramType): ) def write(self): - if self.callback_data: + if self.callback_data is not None: return KeyboardButtonCallback(text=self.text, data=self.callback_data) - if self.url: + if self.url is not None: return KeyboardButtonUrl(text=self.text, url=self.url) - if self.switch_inline_query: + if self.switch_inline_query is not None: return KeyboardButtonSwitchInline(text=self.text, query=self.switch_inline_query) - if self.switch_inline_query_current_chat: + if self.switch_inline_query_current_chat is not None: return KeyboardButtonSwitchInline( text=self.text, query=self.switch_inline_query_current_chat, same_peer=True ) - if self.callback_game: + if self.callback_game is not None: return KeyboardButtonGame(text=self.text) From 27666ec1743c707d01f787314a1730c05b80d8a1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 12:14:31 +0100 Subject: [PATCH 35/37] Small docs fixes --- docs/source/pyrogram/Types.rst | 4 ++++ pyrogram/__init__.py | 2 +- pyrogram/client/methods/messages/edit_message_media.py | 2 +- pyrogram/client/methods/messages/send_media_group.py | 6 ++---- pyrogram/client/types/__init__.py | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst index 4fe01873..39335ee2 100644 --- a/docs/source/pyrogram/Types.rst +++ b/docs/source/pyrogram/Types.rst @@ -66,6 +66,7 @@ Input Media .. autosummary:: :nosignatures: + InputMedia InputMediaPhoto InputMediaVideo InputMediaAudio @@ -215,6 +216,9 @@ InputMessageContent .. Input Media ----------- +.. autoclass:: InputMedia + :members: + .. autoclass:: InputMediaPhoto :members: diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index d8f96c66..4b155c65 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -33,7 +33,7 @@ __version__ = "0.12.0.develop" from .api.errors import Error from .client.types import ( - Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, + Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMedia, InputMediaPhoto, InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index cbb00aa3..57600ead 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -56,7 +56,7 @@ class EditMessageMedia(BaseClient): message_id (``int``): Message identifier in the chat specified in chat_id. - media (:obj:`InputMediaAnimation` | :obj:`InputMediaAudio` | :obj:`InputMediaDocument` | :obj:`InputMediaPhoto` | :obj:`InputMediaVideo`) + media (:obj:`InputMedia`) One of the InputMedia objects describing an animation, audio, document, photo or video. reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index aff0a29f..a546e114 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -49,10 +49,8 @@ class SendMediaGroup(BaseClient): For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - media (``list``): - A list containing either :obj:`InputMediaPhoto ` or - :obj:`InputMediaVideo ` objects - describing photos and videos to be sent, must include 2–10 items. + media (List of :obj:`InputMediaPhoto` and :obj:`InputMediaVideo`): + A list describing photos and videos to be sent, must include 2–10 items. disable_notification (``bool``, *optional*): Sends the message silently. diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index e51a8413..c70ec83f 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -25,7 +25,7 @@ from .inline_mode import ( InlineQuery, InlineQueryResult, InlineQueryResultArticle ) from .input_media import ( - InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, + InputMedia, InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation ) from .input_message_content import ( From 5edd971118ec08cdf8b3b38543698f4bb11b0dd5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 12:39:15 +0100 Subject: [PATCH 36/37] Update docs to use bot_token parameter --- docs/source/start/Setup.rst | 9 ++++--- pyrogram/client/client.py | 52 +++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 24caa1f4..26d9d1c6 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -92,18 +92,19 @@ and as long as you keep the session alive, Pyrogram won't ask you again to enter Bot Authorization ----------------- -Bots are a special kind of users and are authorized via their tokens (instead of phone numbers), which are created by +Bots are a special kind of users that are authorized via their tokens (instead of phone numbers), which are created by BotFather_. Bot tokens replace the Users' phone numbers only — you still need to `configure a Telegram API key <#configuration>`_ with Pyrogram, even when using Bots. -The authorization process is automatically managed. All you need to do is pass the bot token as ``session_name``. -The session file will be named after the Bot user_id, which is ``123456.session`` for the example below. +The authorization process is automatically managed. All you need to do is choose a ``session_name`` (can be anything, +but is usually your bot username) and pass your bot token using the ``bot_token`` parameter. +The session file will be named after the session name, which will be ``pyrogrambot.session`` for the example below. .. code-block:: python from pyrogram import Client - app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") + app = Client("pyrogrambot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") app.run() .. _installed Pyrogram: Installation.html diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 737139ca..ca74e25b 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -183,31 +183,33 @@ class Client(Methods, BaseClient): terms_of_service_displayed = False - def __init__(self, - session_name: str, - api_id: Union[int, str] = None, - api_hash: str = None, - app_version: str = None, - device_model: str = None, - system_version: str = None, - lang_code: str = None, - ipv6: bool = False, - proxy: dict = None, - test_mode: bool = False, - phone_number: str = None, - phone_code: Union[str, callable] = None, - password: str = None, - recovery_code: callable = None, - force_sms: bool = False, - bot_token: str = None, - first_name: str = None, - last_name: str = None, - workers: int = BaseClient.WORKERS, - workdir: str = BaseClient.WORKDIR, - config_file: str = BaseClient.CONFIG_FILE, - plugins: dict = None, - no_updates: bool = None, - takeout: bool = None): + def __init__( + self, + session_name: str, + api_id: Union[int, str] = None, + api_hash: str = None, + app_version: str = None, + device_model: str = None, + system_version: str = None, + lang_code: str = None, + ipv6: bool = False, + proxy: dict = None, + test_mode: bool = False, + phone_number: str = None, + phone_code: Union[str, callable] = None, + password: str = None, + recovery_code: callable = None, + force_sms: bool = False, + bot_token: str = None, + first_name: str = None, + last_name: str = None, + workers: int = BaseClient.WORKERS, + workdir: str = BaseClient.WORKDIR, + config_file: str = BaseClient.CONFIG_FILE, + plugins: dict = None, + no_updates: bool = None, + takeout: bool = None + ): super().__init__() self.session_name = session_name From 4b7c6810c09955dc8267d7c76c38247ced8daa1b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Mar 2019 13:33:47 +0100 Subject: [PATCH 37/37] Make get_sticker_set_name "private" with a leading underscore _ --- pyrogram/client/types/messages_and_media/sticker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py index 43fb6e98..18dc5e13 100644 --- a/pyrogram/client/types/messages_and_media/sticker.py +++ b/pyrogram/client/types/messages_and_media/sticker.py @@ -99,7 +99,7 @@ class Sticker(PyrogramType): @staticmethod @lru_cache(maxsize=256) - def get_sticker_set_name(send, input_sticker_set_id): + def _get_sticker_set_name(send, input_sticker_set_id): try: return send( functions.messages.GetStickerSet( @@ -119,7 +119,7 @@ class Sticker(PyrogramType): if isinstance(sticker_set, types.InputStickerSetID): input_sticker_set_id = (sticker_set.id, sticker_set.access_hash) - set_name = Sticker.get_sticker_set_name(client.send, input_sticker_set_id) + set_name = Sticker._get_sticker_set_name(client.send, input_sticker_set_id) else: set_name = None