mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-31 16:07:44 +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', | ||||
|             query: str, | ||||
|             *, | ||||
|             entity: 'hints.EntityLike' = None, | ||||
|             offset: str = None, | ||||
|             geo_point: 'types.GeoPoint' = None) -> custom.InlineResults: | ||||
|         """ | ||||
|  | @ -25,6 +26,15 @@ class BotMethods: | |||
|             query (`str`): | ||||
|                 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): | ||||
|                 The string offset to use for the bot. | ||||
| 
 | ||||
|  | @ -46,12 +56,17 @@ class BotMethods: | |||
|                 message = await results[0].click('TelethonOffTopic') | ||||
|         """ | ||||
|         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( | ||||
|             bot=bot, | ||||
|             peer=types.InputPeerEmpty(), | ||||
|             peer=peer, | ||||
|             query=query, | ||||
|             offset=offset or '', | ||||
|             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' | ||||
|     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, | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
| 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_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_INLINE_DISABLED,400,This bot can't be used in inline mode | ||||
| 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 | ||||
| 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 | ||||
| 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 | ||||
| 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) | ||||
|  |  | |||
| 
 | 
		Loading…
	
		Reference in New Issue
	
	Block a user