diff --git a/pyrogram/client/methods/decorators/__init__.py b/pyrogram/client/methods/decorators/__init__.py index 6cf9940a..c9ba80e5 100644 --- a/pyrogram/client/methods/decorators/__init__.py +++ b/pyrogram/client/methods/decorators/__init__.py @@ -19,6 +19,7 @@ from .on_callback_query import OnCallbackQuery from .on_deleted_messages import OnDeletedMessages from .on_disconnect import OnDisconnect +from .on_inline_query import OnInlineQuery from .on_message import OnMessage from .on_raw_update import OnRawUpdate from .on_user_status import OnUserStatus @@ -30,6 +31,7 @@ class Decorators( OnCallbackQuery, OnRawUpdate, OnDisconnect, - OnUserStatus + OnUserStatus, + OnInlineQuery ): pass diff --git a/pyrogram/client/methods/decorators/on_inline_query.py b/pyrogram/client/methods/decorators/on_inline_query.py new file mode 100644 index 00000000..c104be62 --- /dev/null +++ b/pyrogram/client/methods/decorators/on_inline_query.py @@ -0,0 +1,50 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram.client.filters.filter import Filter +from ...ext import BaseClient + + +class OnInlineQuery(BaseClient): + def on_inline_query(self, filters=None, group: int = 0): + """Use this decorator to automatically register a function for handling + inline queries. This does the same thing as :meth:`add_handler` using the + :class:`InlineQueryHandler`. + + Args: + filters (:obj:`Filters `): + Pass one or more filters to allow only a subset of inline queries to be passed + in your function. + + group (``int``, *optional*): + The group identifier, defaults to 0. + """ + + def decorator(func): + handler = pyrogram.InlineQueryHandler(func, filters) + + if isinstance(self, Filter): + return pyrogram.InlineQueryHandler(func, self), group if filters is None else filters + + if self is not None: + self.add_handler(handler, group) + + return handler, group + + return decorator