2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 21:38:04 +00:00

Fix inline-mode branch breaking after many commits from develop

This commit is contained in:
Dan 2019-03-21 18:37:00 +01:00
parent acbbfabb27
commit fede74398c
5 changed files with 81 additions and 23 deletions

View File

@ -80,7 +80,7 @@ class Dispatcher:
), ),
(types.UpdateBotInlineQuery,): (types.UpdateBotInlineQuery,):
lambda upd, usr, cht: (utils.parse_inline_query(self.client, upd, usr), InlineQueryHandler) lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler)
} }
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple} self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}

View File

@ -129,3 +129,6 @@ class BaseClient:
def get_chat_members_count(self, *args, **kwargs): def get_chat_members_count(self, *args, **kwargs):
pass pass
def answer_inline_query(self, *args, **kwargs):
pass

View File

@ -21,14 +21,16 @@ from pyrogram.client.ext import BaseClient
class AnswerInlineQuery(BaseClient): class AnswerInlineQuery(BaseClient):
def answer_inline_query(self, def answer_inline_query(
self,
inline_query_id: str, inline_query_id: str,
results: list, results: list,
cache_time: int = 300, cache_time: int = 300,
is_personal: bool = None, is_personal: bool = None,
next_offset: str = "", next_offset: str = "",
switch_pm_text: str = "", switch_pm_text: str = "",
switch_pm_parameter: str = ""): switch_pm_parameter: str = ""
):
# TODO: Docs # TODO: Docs
return self.send( return self.send(
functions.messages.SetInlineBotResults( functions.messages.SetInlineBotResults(
@ -39,8 +41,8 @@ class AnswerInlineQuery(BaseClient):
private=is_personal or None, private=is_personal or None,
next_offset=next_offset or None, next_offset=next_offset or None,
switch_pm=types.InlineBotSwitchPM( switch_pm=types.InlineBotSwitchPM(
switch_pm_text, text=switch_pm_text,
switch_pm_parameter start_param=switch_pm_parameter
) if switch_pm_text else None ) if switch_pm_text else None
) )
) )

View File

@ -16,13 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Tuple
import pyrogram import pyrogram
from pyrogram.client.filters.filter import Filter from pyrogram.client.filters.filter import Filter
from pyrogram.client.handlers.handler import Handler
from ...ext import BaseClient from ...ext import BaseClient
class OnInlineQuery(BaseClient): class OnInlineQuery(BaseClient):
def on_inline_query(self, filters=None, group: int = 0): def on_inline_query(
self=None,
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling """Use this decorator to automatically register a function for handling
inline queries. This does the same thing as :meth:`add_handler` using the inline queries. This does the same thing as :meth:`add_handler` using the
:class:`InlineQueryHandler`. :class:`InlineQueryHandler`.
@ -36,7 +43,10 @@ class OnInlineQuery(BaseClient):
The group identifier, defaults to 0. The group identifier, defaults to 0.
""" """
def decorator(func): def decorator(func: callable) -> Tuple[Handler, int]:
if isinstance(func, tuple):
func = func[0].callback
handler = pyrogram.InlineQueryHandler(func, filters) handler = pyrogram.InlineQueryHandler(func, filters)
if isinstance(self, Filter): if isinstance(self, Filter):

View File

@ -16,10 +16,17 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api.core import Object from typing import List
import pyrogram
from pyrogram.api import types
from ..bots.inline_query_result import InlineQueryResult
from ..messages_and_media import Location
from ..pyrogram_type import PyrogramType
from ..user_and_chats import User
class InlineQuery(Object): class InlineQuery(PyrogramType):
"""This object represents an incoming inline query. """This object represents an incoming inline query.
When the user sends an empty query, your bot could return some default or trending results When the user sends an empty query, your bot could return some default or trending results
@ -39,20 +46,56 @@ class InlineQuery(Object):
location (:obj:`Location <pyrogram.Location>`. *optional*): location (:obj:`Location <pyrogram.Location>`. *optional*):
Sender location, only for bots that request user location. Sender location, only for bots that request user location.
""" """
ID = 0xb0700032 __slots__ = ["id", "from_user", "query", "offset", "location"]
def __init__( def __init__(
self, self,
client, client: "pyrogram.client.ext.BaseClient",
id: str, id: str,
from_user, from_user: User,
query: str, query: str,
offset: str, offset: str,
location=None, location: Location = None
): ):
super().__init__(client)
self._client = client self._client = client
self.id = id self.id = id
self.from_user = from_user self.from_user = from_user
self.query = query self.query = query
self.offset = offset self.offset = offset
self.location = location self.location = location
@staticmethod
def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery":
return InlineQuery(
client=client,
id=str(inline_query.query_id),
from_user=User._parse(client, users[inline_query.user_id]),
query=inline_query.query,
offset=inline_query.offset,
location=Location(
longitude=inline_query.geo.long,
latitude=inline_query.geo.lat,
client=client
) if inline_query.geo else None
)
def answer(
self,
results: List[InlineQueryResult],
cache_time: int = 300,
is_personal: bool = None,
next_offset: str = "",
switch_pm_text: str = "",
switch_pm_parameter: str = ""
):
return self._client.answer_inline_query(
inline_query_id=self.id,
results=results,
cache_time=cache_time,
is_personal=is_personal,
next_offset=next_offset,
switch_pm_text=switch_pm_text,
switch_pm_parameter=switch_pm_parameter
)