Expose entity parameter in client.inline_query

Some bots, such as @gamee, use this to determine the type of results
to return (and "disable" themselves in channels).
This commit is contained in:
Lonami Exo
2020-10-11 16:57:38 +02:00
parent d0faaa2ead
commit adf52a1b74
4 changed files with 32 additions and 8 deletions

View File

@@ -25,10 +25,11 @@ class InlineResult:
CONTACT = 'contact'
GAME = 'game'
def __init__(self, client, original, query_id=None):
def __init__(self, client, original, query_id=None, *, entity=None):
self._client = client
self.result = original
self._query_id = query_id
self._entity = entity
@property
def type(self):
@@ -97,7 +98,7 @@ class InlineResult:
elif isinstance(self.result, types.BotInlineMediaResult):
return self.result.document
async def click(self, entity, reply_to=None,
async def click(self, entity=None, reply_to=None,
silent=False, clear_draft=False, hide_via=False):
"""
Clicks this result and sends the associated `message`.
@@ -123,7 +124,13 @@ class InlineResult:
Whether the "via @bot" should be hidden or not.
Only works with certain bots (like @bing or @gif).
"""
entity = await self._client.get_input_entity(entity)
if entity:
entity = await self._client.get_input_entity(entity)
elif self._entity:
entity = self._entity
else:
raise ValueError('You must provide the entity where the result should be sent to')
reply_id = None if reply_to is None else utils.get_message_id(reply_to)
req = functions.messages.SendInlineBotResultRequest(
peer=entity,

View File

@@ -44,8 +44,8 @@ class InlineResults(list):
switch to a private conversation with the bot using
the text in this object.
"""
def __init__(self, client, original):
super().__init__(InlineResult(client, x, original.query_id)
def __init__(self, client, original, *, entity=None):
super().__init__(InlineResult(client, x, original.query_id, entity=entity)
for x in original.results)
self.result = original