Skip to content

Commit b893698

Browse files
committed
Add ability to add/remove users from the user filter.
Use .users to access the inner set of users
1 parent 05b3be1 commit b893698

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

pyrogram/client/filters/filters.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,27 @@ def f(_, m):
237237
return create("Regex", f, p=re.compile(pattern, flags))
238238

239239
@staticmethod
240-
def user(user: int or str or list):
241-
"""Filter messages coming from specific users.
240+
def user(users: int or str or list = None):
241+
"""Filter messages coming from one or more specific users.
242242
243243
Args:
244-
user (``int`` | ``str`` | ``list``):
245-
The user or list of user IDs (int) or usernames (str) the filter should look for.
244+
users (``int`` | ``str`` | ``list``):
245+
Pass one or more user ids/usernames to filter the users.
246+
The argument passed will be stored as a python set in the *.users* field of the filter instance.
247+
To add or remove users dynamically, simply manipulate the inner set.
248+
Defaults to None (empty set).
246249
"""
247250
return create(
248251
"User",
249252
lambda _, m: bool(m.from_user
250-
and (m.from_user.id in _.u
253+
and (m.from_user.id in _.users
251254
or (m.from_user.username
252-
and m.from_user.username.lower() in _.u))),
253-
u=(
254-
{user.lower().strip("@") if type(user) is str else user}
255-
if not isinstance(user, list)
256-
else {i.lower().strip("@") if type(i) is str else i for i in user}
255+
and m.from_user.username.lower() in _.users))),
256+
users=(
257+
set() if users is None
258+
else {users.lower().strip("@") if type(users) is str else users}
259+
if not isinstance(users, list)
260+
else {i.lower().strip("@") if type(i) is str else i for i in users}
257261
)
258262
)
259263

0 commit comments

Comments
 (0)