diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index a2bbd345..a71976b0 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -93,4 +93,6 @@ CALL_ALREADY_ACCEPTED The call is already accepted CALL_ALREADY_DECLINED The call is already declined PHOTO_EXT_INVALID The photo extension is invalid EXTERNAL_URL_INVALID The external media URL is invalid -CHAT_NOT_MODIFIED The chat settings were not modified \ No newline at end of file +CHAT_NOT_MODIFIED The chat settings were not modified +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 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 14fb9147..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 @@ -73,6 +74,25 @@ Input Media InputMediaDocument InputPhoneContact +Inline Mode +------------ + +.. autosummary:: + :nosignatures: + + InlineQuery + InlineQueryResult + InlineQueryResultArticle + +InputMessageContent +------------------- + +.. autosummary:: + :nosignatures: + + InputMessageContent + InputTextMessageContent + .. User & Chats ------------ @@ -196,6 +216,9 @@ Input Media .. Input Media ----------- +.. autoclass:: InputMedia + :members: + .. autoclass:: InputMediaPhoto :members: @@ -213,3 +236,25 @@ Input Media .. autoclass:: InputPhoneContact :members: + + +.. Inline Mode + ----------- + +.. autoclass:: InlineQuery + :members: + +.. autoclass:: InlineQueryResult + :members: + +.. autoclass:: InlineQueryResultArticle + :members: + +.. InputMessageContent + ------------------- + +.. autoclass:: InputMessageContent + :members: + +.. autoclass:: InputTextMessageContent + :members: diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 9ec7fc9f..4b155c65 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -33,16 +33,19 @@ __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, 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, 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 2719d82e..125d1469 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/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index 5a463077..43f80ebb 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -24,7 +24,11 @@ from threading import Thread import pyrogram from pyrogram.api import types -from ..handlers import CallbackQueryHandler, MessageHandler, RawUpdateHandler, UserStatusHandler, DeletedMessagesHandler +from ..ext import utils +from ..handlers import ( + CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, + UserStatusHandler, RawUpdateHandler, InlineQueryHandler +) log = logging.getLogger(__name__) @@ -73,7 +77,10 @@ class Dispatcher: (types.UpdateUserStatus,): lambda upd, usr, cht: ( pyrogram.UserStatus._parse(self.client, upd.status, upd.user_id), UserStatusHandler - ) + ), + + (types.UpdateBotInlineQuery,): + 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/handlers/__init__.py b/pyrogram/client/handlers/__init__.py index 499ed007..54c98f7f 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 + ) diff --git a/pyrogram/client/methods/bots/__init__.py b/pyrogram/client/methods/bots/__init__.py index 65d132a0..916a62dc 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_game_high_scores import GetGameHighScores from .get_inline_bot_results import GetInlineBotResults from .request_callback_answer import RequestCallbackAnswer @@ -27,6 +28,7 @@ from .set_game_score import SetGameScore class Bots( AnswerCallbackQuery, + AnswerInlineQuery, GetInlineBotResults, RequestCallbackAnswer, SendInlineBotResult, 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..7b3524b2 --- /dev/null +++ b/pyrogram/client/methods/bots/answer_inline_query.py @@ -0,0 +1,91 @@ +# 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 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[InlineQueryResult], + cache_time: int = 300, + is_personal: bool = None, + next_offset: str = "", + switch_pm_text: str = "", + switch_pm_parameter: str = "" + ): + """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), + 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( + text=switch_pm_text, + start_param=switch_pm_parameter + ) if switch_pm_text else None + ) + ) 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/__init__.py b/pyrogram/client/methods/decorators/__init__.py index 07f84b54..33f55a3d 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_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 new file mode 100644 index 00000000..81f0f676 --- /dev/null +++ b/pyrogram/client/methods/decorators/on_inline_query.py @@ -0,0 +1,59 @@ +# 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 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=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`. + + 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: callable) -> Tuple[Handler, int]: + if isinstance(func, tuple): + func = func[0].callback + + 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 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/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/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/style/html.py b/pyrogram/client/style/html.py index 211716e1..9dfc17cb 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -35,8 +35,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, message: str): entities = [] diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index 45037a35..6dbb81c4 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -52,8 +52,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(str(message or "")).strip() diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index fa4c12cf..c70ec83f 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -17,14 +17,20 @@ # along with Pyrogram. If not, see . from .bots import ( - CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + 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, + InputMedia, InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation ) +from .input_message_content import ( + InputMessageContent, InputTextMessageContent +) from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos, 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/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) 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/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/inline_mode/inline_query.py b/pyrogram/client/types/inline_mode/inline_query.py new file mode 100644 index 00000000..9c1c02ac --- /dev/null +++ b/pyrogram/client/types/inline_mode/inline_query.py @@ -0,0 +1,152 @@ +# 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 typing import List + +import pyrogram +from pyrogram.api import types +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, Update): + """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. + """ + __slots__ = ["id", "from_user", "query", "offset", "location"] + + def __init__( + 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( + 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, + client=client + ) + + 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 = "" + ): + """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, + cache_time=cache_time, + is_personal=is_personal, + next_offset=next_offset, + switch_pm_text=switch_pm_text, + switch_pm_parameter=switch_pm_parameter + ) diff --git a/pyrogram/client/types/inline_mode/inline_query_result.py b/pyrogram/client/types/inline_mode/inline_query_result.py new file mode 100644 index 00000000..3e7fcb02 --- /dev/null +++ b/pyrogram/client/types/inline_mode/inline_query_result.py @@ -0,0 +1,59 @@ +# 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_type import PyrogramType + +"""- :obj:`InlineQueryResultCachedAudio` + - :obj:`InlineQueryResultCachedDocument` + - :obj:`InlineQueryResultCachedGif` + - :obj:`InlineQueryResultCachedMpeg4Gif` + - :obj:`InlineQueryResultCachedPhoto` + - :obj:`InlineQueryResultCachedSticker` + - :obj:`InlineQueryResultCachedVideo` + - :obj:`InlineQueryResultCachedVoice` + - :obj:`InlineQueryResultAudio` + - :obj:`InlineQueryResultContact` + - :obj:`InlineQueryResultGame` + - :obj:`InlineQueryResultDocument` + - :obj:`InlineQueryResultGif` + - :obj:`InlineQueryResultLocation` + - :obj:`InlineQueryResultMpeg4Gif` + - :obj:`InlineQueryResultPhoto` + - :obj:`InlineQueryResultVenue` + - :obj:`InlineQueryResultVideo` + - :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/inline_mode/inline_query_result_article.py b/pyrogram/client/types/inline_mode/inline_query_result_article.py new file mode 100644 index 00000000..7916dba5 --- /dev/null +++ b/pyrogram/client/types/inline_mode/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 .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. + + title (``str``): + Title for the result. + + input_message_content (:obj:`InputMessageContent `): + 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. + + 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. + """ + + __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 + ): + super().__init__("article", id) + + self.title = title + self.input_message_content = input_message_content + self.reply_markup = reply_markup + self.url = url + self.description = description + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height + + def write(self): + return types.InputBotInlineResult( + id=self.id, + type=self.type, + 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 + ) diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py new file mode 100644 index 00000000..a67163c6 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py @@ -0,0 +1,71 @@ +# 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.client.types.pyrogram_type import PyrogramType + + +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: + 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. + + """ + + 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/inline_mode/todo/inline_query_result_cached_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py new file mode 100644 index 00000000..1f3a1963 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py @@ -0,0 +1,103 @@ +# 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 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 +from pyrogram.client.types.pyrogram_type import PyrogramType + + +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. + + Args: + 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. + + """ + + 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 " +# +# 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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py new file mode 100644 index 00000000..4c457873 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py new file mode 100644 index 00000000..93ec1efb --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py new file mode 100644 index 00000000..ee6b2654 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_sticker.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py new file mode 100644 index 00000000..6142b1fa --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py new file mode 100644 index 00000000..8c00c61a --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_cached_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py new file mode 100644 index 00000000..741df389 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_contact.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py new file mode 100644 index 00000000..e26af4ea --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_document.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py new file mode 100644 index 00000000..93b8fcae --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_game.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py new file mode 100644 index 00000000..3e7cfb73 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +class InlineQueryResultGame(PyrogramType): + """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/inline_mode/todo/inline_query_result_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py new file mode 100644 index 00000000..13f4fc18 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_location.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py new file mode 100644 index 00000000..176591d2 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py new file mode 100644 index 00000000..37aa8986 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py new file mode 100644 index 00000000..2ba7c312 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py @@ -0,0 +1,126 @@ +# 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 +from pyrogram.client.types.pyrogram_type import PyrogramType + + +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. + + Args: + 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``, *optional*): + Width of the photo. + + photo_height (``int``, *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. + + """ + + 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 + 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 + + 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 + ) + ] + ) + ) diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py new file mode 100644 index 00000000..23ddfc35 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py new file mode 100644 index 00000000..9b1723e1 --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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/inline_mode/todo/inline_query_result_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py new file mode 100644 index 00000000..188063ec --- /dev/null +++ b/pyrogram/client/types/inline_mode/todo/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.client.types.pyrogram_type import PyrogramType + + +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: + 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 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/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_message_content/input_message_content.py b/pyrogram/client/types/input_message_content/input_message_content.py new file mode 100644 index 00000000..f3e238b8 --- /dev/null +++ b/pyrogram/client/types/input_message_content/input_message_content.py @@ -0,0 +1,37 @@ +# 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_type import PyrogramType + +"""- :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` + """ + + __slots__ = [] + + def __init__(self): + super().__init__(None) diff --git a/pyrogram/client/types/input_message_content/input_text_message_content.py b/pyrogram/client/types/input_message_content/input_text_message_content.py new file mode 100644 index 00000000..0e6ffa8b --- /dev/null +++ b/pyrogram/client/types/input_message_content/input_text_message_content.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 pyrogram.api import types +from .input_message_content import InputMessageContent +from ...style import HTML, Markdown + + +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 + + 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, + **(HTML() if self.parse_mode.lower() == "html" else Markdown()).parse(self.message_text) + ) 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``):