mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Handle more key errors on forward message
This commit is contained in:
		
							parent
							
								
									a71b095c1d
								
							
						
					
					
						commit
						a4c2e45d6d
					
				| 
						 | 
					@ -142,18 +142,23 @@ class MessageParseMethods(UserMethods):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        random_id = request if isinstance(request, int) else request.random_id
 | 
					        random_id = request if isinstance(request, int) else request.random_id
 | 
				
			||||||
        if not utils.is_list_like(random_id):
 | 
					        if not utils.is_list_like(random_id):
 | 
				
			||||||
            if random_id in random_to_id:
 | 
					            msg = id_to_message.get(random_to_id.get(random_id))
 | 
				
			||||||
                return id_to_message[random_to_id[random_id]]
 | 
					            if not msg:
 | 
				
			||||||
            else:
 | 
					                self._log[__name__].warning(
 | 
				
			||||||
                return None
 | 
					                    'Request %s had missing message mapping %s', request, result)
 | 
				
			||||||
        else:
 | 
					
 | 
				
			||||||
            # ``rnd in random_to_id`` is needed because trying to forward only
 | 
					            return msg
 | 
				
			||||||
            # deleted messages causes `MESSAGE_ID_INVALID`, but forwarding
 | 
					
 | 
				
			||||||
            # valid and invalid messages in the same call makes the call
 | 
					        try:
 | 
				
			||||||
            # succeed, although the API won't return those messages thus
 | 
					            return [id_to_message[random_to_id[rnd]] for rnd in random_id]
 | 
				
			||||||
            # `random_to_id[rnd]` would `KeyError`.
 | 
					        except KeyError:
 | 
				
			||||||
            return [id_to_message[random_to_id[rnd]]
 | 
					            # Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets
 | 
				
			||||||
                    if rnd in random_to_id else None
 | 
					            # deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at
 | 
				
			||||||
                    for rnd in random_id]
 | 
					            # Telegram), in which case we get some "missing" message mappings.
 | 
				
			||||||
 | 
					            # Log them with the hope that we can better work around them.
 | 
				
			||||||
 | 
					            self._log[__name__].warning(
 | 
				
			||||||
 | 
					                'Request %s had missing message mappings %s', request, result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return [id_to_message.get(random_to_id.get(rnd)) for rnd in random_to_id]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # endregion
 | 
					    # endregion
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -270,4 +270,5 @@ WALLPAPER_INVALID,400,The input wallpaper was not valid
 | 
				
			||||||
WC_CONVERT_URL_INVALID,400,WC convert URL invalid
 | 
					WC_CONVERT_URL_INVALID,400,WC convert URL invalid
 | 
				
			||||||
WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL
 | 
					WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL
 | 
				
			||||||
WEBPAGE_MEDIA_EMPTY,400,Webpage media empty
 | 
					WEBPAGE_MEDIA_EMPTY,400,Webpage media empty
 | 
				
			||||||
 | 
					WORKER_BUSY_TOO_LONG_RETRY,500,Telegram workers are too busy to respond immediately
 | 
				
			||||||
YOU_BLOCKED_USER,400,You blocked this user
 | 
					YOU_BLOCKED_USER,400,You blocked this user
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		
		
			
  | 
		Loading…
	
		Reference in New Issue
	
	Block a user