mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Fix pattern= and move pattern_match to events.NewMessage
This commit is contained in:
		
							parent
							
								
									a1477a84bf
								
							
						
					
					
						commit
						9e3f6483e8
					
				| 
						 | 
					@ -85,25 +85,9 @@ class EventCommon(abc.ABC):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Intermediate class with common things to all events.
 | 
					    Intermediate class with common things to all events.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Attributes:
 | 
					    All events (except `Raw`) have ``is_private``, ``is_group``
 | 
				
			||||||
        pattern_match (`obj`):
 | 
					    and ``is_channel`` boolean properties, as well as an
 | 
				
			||||||
            The resulting object from calling the passed ``pattern`` function.
 | 
					    ``original_update`` field containing the original :tl:`Update`.
 | 
				
			||||||
            Here's an example using a string (defaults to regex match):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            >>> from telethon import TelegramClient, events
 | 
					 | 
				
			||||||
            >>> client = TelegramClient(...)
 | 
					 | 
				
			||||||
            >>>
 | 
					 | 
				
			||||||
            >>> @client.on(events.NewMessage(pattern=r'hi (\w+)!'))
 | 
					 | 
				
			||||||
            ... def handler(event):
 | 
					 | 
				
			||||||
            ...     # In this case, the result is a ``Match`` object
 | 
					 | 
				
			||||||
            ...     # since the ``str`` pattern was converted into
 | 
					 | 
				
			||||||
            ...     # the ``re.compile(pattern).match`` function.
 | 
					 | 
				
			||||||
            ...     print('Welcomed', event.pattern_match.group(1))
 | 
					 | 
				
			||||||
            ...
 | 
					 | 
				
			||||||
            >>>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        original_update (:tl:`Update`):
 | 
					 | 
				
			||||||
            The original Telegram update object that caused this event.
 | 
					 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    _event_name = 'Event'
 | 
					    _event_name = 'Event'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,8 +98,6 @@ class EventCommon(abc.ABC):
 | 
				
			||||||
        self._message_id = msg_id
 | 
					        self._message_id = msg_id
 | 
				
			||||||
        self._input_chat = None
 | 
					        self._input_chat = None
 | 
				
			||||||
        self._chat = None
 | 
					        self._chat = None
 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.pattern_match = None
 | 
					 | 
				
			||||||
        self.original_update = None
 | 
					        self.original_update = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.is_private = isinstance(chat_peer, types.PeerUser)
 | 
					        self.is_private = isinstance(chat_peer, types.PeerUser)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ class NewMessage(EventBuilder):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Should we short-circuit? E.g. perform no check at all
 | 
					        # Should we short-circuit? E.g. perform no check at all
 | 
				
			||||||
        self._no_check = all(x is None for x in (
 | 
					        self._no_check = all(x is None for x in (
 | 
				
			||||||
            self.chats, self.incoming, self.outgoing,
 | 
					            self.chats, self.incoming, self.outgoing, self.pattern,
 | 
				
			||||||
            self.from_users, self.forwards, self.from_users
 | 
					            self.from_users, self.forwards, self.from_users
 | 
				
			||||||
        ))
 | 
					        ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,6 +166,22 @@ class NewMessage(EventBuilder):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                See `telethon.tl.custom.message.Message` for the rest of
 | 
					                See `telethon.tl.custom.message.Message` for the rest of
 | 
				
			||||||
                available members and methods.
 | 
					                available members and methods.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            pattern_match (`obj`):
 | 
				
			||||||
 | 
					                The resulting object from calling the passed ``pattern`` function.
 | 
				
			||||||
 | 
					                Here's an example using a string (defaults to regex match):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                >>> from telethon import TelegramClient, events
 | 
				
			||||||
 | 
					                >>> client = TelegramClient(...)
 | 
				
			||||||
 | 
					                >>>
 | 
				
			||||||
 | 
					                >>> @client.on(events.NewMessage(pattern=r'hi (\w+)!'))
 | 
				
			||||||
 | 
					                ... def handler(event):
 | 
				
			||||||
 | 
					                ...     # In this case, the result is a ``Match`` object
 | 
				
			||||||
 | 
					                ...     # since the ``str`` pattern was converted into
 | 
				
			||||||
 | 
					                ...     # the ``re.compile(pattern).match`` function.
 | 
				
			||||||
 | 
					                ...     print('Welcomed', event.pattern_match.group(1))
 | 
				
			||||||
 | 
					                ...
 | 
				
			||||||
 | 
					                >>>
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def __init__(self, message):
 | 
					        def __init__(self, message):
 | 
				
			||||||
            self.__dict__['_init'] = False
 | 
					            self.__dict__['_init'] = False
 | 
				
			||||||
| 
						 | 
					@ -179,6 +195,7 @@ class NewMessage(EventBuilder):
 | 
				
			||||||
            super().__init__(chat_peer=chat_peer,
 | 
					            super().__init__(chat_peer=chat_peer,
 | 
				
			||||||
                             msg_id=message.id, broadcast=bool(message.post))
 | 
					                             msg_id=message.id, broadcast=bool(message.post))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.pattern_match = None
 | 
				
			||||||
            self.message = message
 | 
					            self.message = message
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def _set_client(self, client):
 | 
					        def _set_client(self, client):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user