mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-25 00:34:19 +03:00
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:
parent
d0faaa2ead
commit
adf52a1b74
|
@ -13,6 +13,7 @@ class BotMethods:
|
||||||
bot: 'hints.EntityLike',
|
bot: 'hints.EntityLike',
|
||||||
query: str,
|
query: str,
|
||||||
*,
|
*,
|
||||||
|
entity: 'hints.EntityLike' = None,
|
||||||
offset: str = None,
|
offset: str = None,
|
||||||
geo_point: 'types.GeoPoint' = None) -> custom.InlineResults:
|
geo_point: 'types.GeoPoint' = None) -> custom.InlineResults:
|
||||||
"""
|
"""
|
||||||
|
@ -25,6 +26,15 @@ class BotMethods:
|
||||||
query (`str`):
|
query (`str`):
|
||||||
The query that should be made to the bot.
|
The query that should be made to the bot.
|
||||||
|
|
||||||
|
entity (`entity`, optional):
|
||||||
|
The entity where the inline query is being made from. Certain
|
||||||
|
bots use this to display different results depending on where
|
||||||
|
it's used, such as private chats, groups or channels.
|
||||||
|
|
||||||
|
If specified, it will also be the default entity where the
|
||||||
|
message will be sent after clicked. Otherwise, the "empty
|
||||||
|
peer" will be used, which some bots may not handle correctly.
|
||||||
|
|
||||||
offset (`str`, optional):
|
offset (`str`, optional):
|
||||||
The string offset to use for the bot.
|
The string offset to use for the bot.
|
||||||
|
|
||||||
|
@ -46,12 +56,17 @@ class BotMethods:
|
||||||
message = await results[0].click('TelethonOffTopic')
|
message = await results[0].click('TelethonOffTopic')
|
||||||
"""
|
"""
|
||||||
bot = await self.get_input_entity(bot)
|
bot = await self.get_input_entity(bot)
|
||||||
|
if entity:
|
||||||
|
peer = await self.get_input_entity(entity)
|
||||||
|
else:
|
||||||
|
peer = types.InputPeerEmpty()
|
||||||
|
|
||||||
result = await self(functions.messages.GetInlineBotResultsRequest(
|
result = await self(functions.messages.GetInlineBotResultsRequest(
|
||||||
bot=bot,
|
bot=bot,
|
||||||
peer=types.InputPeerEmpty(),
|
peer=peer,
|
||||||
query=query,
|
query=query,
|
||||||
offset=offset or '',
|
offset=offset or '',
|
||||||
geo_point=geo_point
|
geo_point=geo_point
|
||||||
))
|
))
|
||||||
|
|
||||||
return custom.InlineResults(self, result)
|
return custom.InlineResults(self, result, entity=peer if entity else None)
|
||||||
|
|
|
@ -25,10 +25,11 @@ class InlineResult:
|
||||||
CONTACT = 'contact'
|
CONTACT = 'contact'
|
||||||
GAME = 'game'
|
GAME = 'game'
|
||||||
|
|
||||||
def __init__(self, client, original, query_id=None):
|
def __init__(self, client, original, query_id=None, *, entity=None):
|
||||||
self._client = client
|
self._client = client
|
||||||
self.result = original
|
self.result = original
|
||||||
self._query_id = query_id
|
self._query_id = query_id
|
||||||
|
self._entity = entity
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
|
@ -97,7 +98,7 @@ class InlineResult:
|
||||||
elif isinstance(self.result, types.BotInlineMediaResult):
|
elif isinstance(self.result, types.BotInlineMediaResult):
|
||||||
return self.result.document
|
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):
|
silent=False, clear_draft=False, hide_via=False):
|
||||||
"""
|
"""
|
||||||
Clicks this result and sends the associated `message`.
|
Clicks this result and sends the associated `message`.
|
||||||
|
@ -123,7 +124,13 @@ class InlineResult:
|
||||||
Whether the "via @bot" should be hidden or not.
|
Whether the "via @bot" should be hidden or not.
|
||||||
Only works with certain bots (like @bing or @gif).
|
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)
|
reply_id = None if reply_to is None else utils.get_message_id(reply_to)
|
||||||
req = functions.messages.SendInlineBotResultRequest(
|
req = functions.messages.SendInlineBotResultRequest(
|
||||||
peer=entity,
|
peer=entity,
|
||||||
|
|
|
@ -44,8 +44,8 @@ class InlineResults(list):
|
||||||
switch to a private conversation with the bot using
|
switch to a private conversation with the bot using
|
||||||
the text in this object.
|
the text in this object.
|
||||||
"""
|
"""
|
||||||
def __init__(self, client, original):
|
def __init__(self, client, original, *, entity=None):
|
||||||
super().__init__(InlineResult(client, x, original.query_id)
|
super().__init__(InlineResult(client, x, original.query_id, entity=entity)
|
||||||
for x in original.results)
|
for x in original.results)
|
||||||
|
|
||||||
self.result = original
|
self.result = original
|
||||||
|
|
|
@ -22,6 +22,7 @@ BANNED_RIGHTS_INVALID,400,"You cannot use that set of permissions in this reques
|
||||||
BOTS_TOO_MUCH,400,There are too many bots in this chat/channel
|
BOTS_TOO_MUCH,400,There are too many bots in this chat/channel
|
||||||
BOT_CHANNELS_NA,400,Bots can't edit admin privileges
|
BOT_CHANNELS_NA,400,Bots can't edit admin privileges
|
||||||
BOT_COMMAND_DESCRIPTION_INVALID,400,"The command description was empty, too long or had invalid characters used"
|
BOT_COMMAND_DESCRIPTION_INVALID,400,"The command description was empty, too long or had invalid characters used"
|
||||||
|
BOT_GAMES_DISABLED,400,Bot games cannot be used in this type of chat
|
||||||
BOT_GROUPS_BLOCKED,400,This bot can't be added to groups
|
BOT_GROUPS_BLOCKED,400,This bot can't be added to groups
|
||||||
BOT_INLINE_DISABLED,400,This bot can't be used in inline mode
|
BOT_INLINE_DISABLED,400,This bot can't be used in inline mode
|
||||||
BOT_INVALID,400,This is not a valid bot
|
BOT_INVALID,400,This is not a valid bot
|
||||||
|
@ -244,7 +245,8 @@ REACTION_INVALID,400,Invalid reaction provided (only emoji are allowed)
|
||||||
REG_ID_GENERATE_FAILED,500,Failure while generating registration ID
|
REG_ID_GENERATE_FAILED,500,Failure while generating registration ID
|
||||||
REPLY_MARKUP_INVALID,400,The provided reply markup is invalid
|
REPLY_MARKUP_INVALID,400,The provided reply markup is invalid
|
||||||
REPLY_MARKUP_TOO_LONG,400,The data embedded in the reply markup buttons was too much
|
REPLY_MARKUP_TOO_LONG,400,The data embedded in the reply markup buttons was too much
|
||||||
RESULT_ID_DUPLICATE,400,Duplicated IDs on the sent results. Make sure to use unique IDs.
|
RESULT_ID_DUPLICATE,400,Duplicated IDs on the sent results. Make sure to use unique IDs
|
||||||
|
RESULT_ID_INVALID,400,The given result cannot be used to send the selection to the bot
|
||||||
RESULT_TYPE_INVALID,400,Result type invalid
|
RESULT_TYPE_INVALID,400,Result type invalid
|
||||||
RESULTS_TOO_MUCH,400,You sent too many results. See https://core.telegram.org/bots/api#answerinlinequery for the current limit.
|
RESULTS_TOO_MUCH,400,You sent too many results. See https://core.telegram.org/bots/api#answerinlinequery for the current limit.
|
||||||
RIGHT_FORBIDDEN,403,Either your admin rights do not allow you to do this or you passed the wrong rights combination (some rights only apply to channels and vice versa)
|
RIGHT_FORBIDDEN,403,Either your admin rights do not allow you to do this or you passed the wrong rights combination (some rights only apply to channels and vice versa)
|
||||||
|
|
|
Loading…
Reference in New Issue
Block a user