mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 09:57:29 +03:00 
			
		
		
		
	Return None from ChatGetter when there isn't enough info
This commit is contained in:
		
							parent
							
								
									35ba9848d9
								
							
						
					
					
						commit
						83789aaa42
					
				| 
						 | 
					@ -133,7 +133,7 @@ class EventCommon(ChatGetter, abc.ABC):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    _event_name = 'Event'
 | 
					    _event_name = 'Event'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, chat_peer=None, msg_id=None, broadcast=False):
 | 
					    def __init__(self, chat_peer=None, msg_id=None, broadcast=None):
 | 
				
			||||||
        super().__init__(chat_peer, broadcast=broadcast)
 | 
					        super().__init__(chat_peer, broadcast=broadcast)
 | 
				
			||||||
        self._entities = {}
 | 
					        self._entities = {}
 | 
				
			||||||
        self._client = None
 | 
					        self._client = None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,23 +108,39 @@ class ChatGetter(abc.ABC):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def is_private(self):
 | 
					    def is_private(self):
 | 
				
			||||||
        """True if the message was sent as a private message."""
 | 
					        """
 | 
				
			||||||
        return isinstance(self._chat_peer, types.PeerUser)
 | 
					        ``True`` if the message was sent as a private message.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Returns ``None`` if there isn't enough information
 | 
				
			||||||
 | 
					        (e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        return isinstance(self._chat_peer, types.PeerUser) if self._chat_peer else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def is_group(self):
 | 
					    def is_group(self):
 | 
				
			||||||
        """True if the message was sent on a group or megagroup."""
 | 
					        """
 | 
				
			||||||
        if self._broadcast is None and self.chat:
 | 
					        True if the message was sent on a group or megagroup.
 | 
				
			||||||
            self._broadcast = getattr(self.chat, 'broadcast', None)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return (
 | 
					        Returns ``None`` if there isn't enough information
 | 
				
			||||||
            isinstance(self._chat_peer, (types.PeerChat, types.PeerChannel))
 | 
					        (e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
 | 
				
			||||||
            and not self._broadcast
 | 
					        """
 | 
				
			||||||
        )
 | 
					        # TODO Cache could tell us more in the future
 | 
				
			||||||
 | 
					        if self._broadcast is None and hasattr(self.chat, 'broadcast'):
 | 
				
			||||||
 | 
					            self._broadcast = bool(self.chat.broadcast)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if isinstance(self._chat_peer, types.PeerChannel):
 | 
				
			||||||
 | 
					            if self._broadcast is None:
 | 
				
			||||||
 | 
					                return None
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return not self._broadcast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return isinstance(self._chat_peer, types.PeerChat)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def is_channel(self):
 | 
					    def is_channel(self):
 | 
				
			||||||
        """True if the message was sent on a megagroup or channel."""
 | 
					        """``True`` if the message was sent on a megagroup or channel."""
 | 
				
			||||||
 | 
					        # The only case where chat peer could be none is in MessageDeleted,
 | 
				
			||||||
 | 
					        # however those always have the peer in channels.
 | 
				
			||||||
        return isinstance(self._chat_peer, types.PeerChannel)
 | 
					        return isinstance(self._chat_peer, types.PeerChannel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def _refetch_chat(self):
 | 
					    async def _refetch_chat(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user