From 2468b32fc58f80362e5b153f90b196e8b558ce57 Mon Sep 17 00:00:00 2001 From: Manuel1510 Date: Thu, 4 Oct 2018 09:12:12 +0200 Subject: [PATCH] Implement next_offset and allow empty results in answer() (#1017) --- telethon/events/inlinequery.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/telethon/events/inlinequery.py b/telethon/events/inlinequery.py index 75e991a6..4e3c6c1f 100644 --- a/telethon/events/inlinequery.py +++ b/telethon/events/inlinequery.py @@ -124,7 +124,7 @@ class InlineQuery(EventBuilder): async def answer( self, results=None, cache_time=0, *, - gallery=False, private=False, + gallery=False, next_offset=None, private=False, switch_pm=None, switch_pm_param=''): """ Answers the inline query with the given results. @@ -147,6 +147,10 @@ class InlineQuery(EventBuilder): gallery (`bool`, optional): Whether the results should show as a gallery (grid) or not. + + next_offset (`str`, optional): + The offset the client will send when the user scrolls the + results and it repeats the request. private (`bool`, optional): Whether the results should be cached by Telegram @@ -163,11 +167,14 @@ class InlineQuery(EventBuilder): if self._answered: return - results = [self._as_awaitable(x, self._client.loop) - for x in results] + if results: + results = [self._as_awaitable(x, self._client.loop) + for x in results] - done, _ = await asyncio.wait(results, loop=self._client.loop) - results = [x.result() for x in done] + done, _ = await asyncio.wait(results, loop=self._client.loop) + results = [x.result() for x in done] + else: + results = [] if switch_pm: switch_pm = types.InlineBotSwitchPM(switch_pm, switch_pm_param) @@ -178,6 +185,7 @@ class InlineQuery(EventBuilder): results=results, cache_time=cache_time, gallery=gallery, + next_offset=next_offset, private=private, switch_pm=switch_pm )