mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Allow Filters.regex to pass all matches (as list)
This is done by using the new "matches" field in the Message type
This commit is contained in:
parent
7a20c8bca8
commit
e5de670d40
@ -147,15 +147,19 @@ class Filters:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
pattern (``str``):
|
pattern (``str``):
|
||||||
The RegEx pattern.
|
The RegEx pattern as string, it will be applied to the text of a message. When a pattern matches,
|
||||||
|
all the `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_
|
||||||
|
are stored in the *matches* field of the :class:`Message <pyrogram.Message>` itself.
|
||||||
|
|
||||||
flags (``int``, optional):
|
flags (``int``, optional):
|
||||||
RegEx flags.
|
RegEx flags.
|
||||||
"""
|
"""
|
||||||
return build(
|
|
||||||
"Regex", lambda _, m: bool(_.p.search(m.text or "")),
|
def f(_, m):
|
||||||
p=re.compile(pattern, flags)
|
m.matches = [i for i in _.p.finditer(m.text or "")]
|
||||||
)
|
return bool(m.matches)
|
||||||
|
|
||||||
|
return build("Regex", f, p=re.compile(pattern, flags))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def user(user: int or str or list):
|
def user(user: int or str or list):
|
||||||
|
@ -174,6 +174,10 @@ class Message(Object):
|
|||||||
|
|
||||||
via_bot (:obj:`User <pyrogram.User>`):
|
via_bot (:obj:`User <pyrogram.User>`):
|
||||||
Via bot.
|
Via bot.
|
||||||
|
|
||||||
|
matches (``list``):
|
||||||
|
A list containing all `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_ that match
|
||||||
|
the text of this message. Only applicable when using :obj:`Filters.regex <pyrogram.Filters.regex>`.
|
||||||
"""
|
"""
|
||||||
ID = 0xb0700003
|
ID = 0xb0700003
|
||||||
|
|
||||||
@ -181,7 +185,7 @@ class Message(Object):
|
|||||||
self,
|
self,
|
||||||
message_id: int,
|
message_id: int,
|
||||||
date: int = None,
|
date: int = None,
|
||||||
chat = None,
|
chat=None,
|
||||||
from_user=None,
|
from_user=None,
|
||||||
forward_from=None,
|
forward_from=None,
|
||||||
forward_from_chat=None,
|
forward_from_chat=None,
|
||||||
@ -222,7 +226,8 @@ class Message(Object):
|
|||||||
successful_payment=None,
|
successful_payment=None,
|
||||||
connected_website=None,
|
connected_website=None,
|
||||||
views: int = None,
|
views: int = None,
|
||||||
via_bot=None
|
via_bot=None,
|
||||||
|
matches: list = None
|
||||||
):
|
):
|
||||||
self.message_id = message_id # int
|
self.message_id = message_id # int
|
||||||
self.date = date # int
|
self.date = date # int
|
||||||
@ -268,3 +273,4 @@ class Message(Object):
|
|||||||
self.connected_website = connected_website # flags.38?string
|
self.connected_website = connected_website # flags.38?string
|
||||||
self.views = views # flags.39?int
|
self.views = views # flags.39?int
|
||||||
self.via_bot = via_bot # flags.40?User
|
self.via_bot = via_bot # flags.40?User
|
||||||
|
self.matches = matches
|
||||||
|
Loading…
Reference in New Issue
Block a user