From b893698f1e8bbd04d44dfb4fd6d2a01e98c60908 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 14:37:04 +0200 Subject: [PATCH] Add ability to add/remove users from the user filter. Use .users to access the inner set of users --- pyrogram/client/filters/filters.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 4cd4b191..26ef8219 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -237,23 +237,27 @@ class Filters: return create("Regex", f, p=re.compile(pattern, flags)) @staticmethod - def user(user: int or str or list): - """Filter messages coming from specific users. + def user(users: int or str or list = None): + """Filter messages coming from one or more specific users. Args: - user (``int`` | ``str`` | ``list``): - The user or list of user IDs (int) or usernames (str) the filter should look for. + users (``int`` | ``str`` | ``list``): + Pass one or more user ids/usernames to filter the users. + The argument passed will be stored as a python set in the *.users* field of the filter instance. + To add or remove users dynamically, simply manipulate the inner set. + Defaults to None (empty set). """ return create( "User", lambda _, m: bool(m.from_user - and (m.from_user.id in _.u + and (m.from_user.id in _.users or (m.from_user.username - and m.from_user.username.lower() in _.u))), - u=( - {user.lower().strip("@") if type(user) is str else user} - if not isinstance(user, list) - else {i.lower().strip("@") if type(i) is str else i for i in user} + and m.from_user.username.lower() in _.users))), + users=( + set() if users is None + else {users.lower().strip("@") if type(users) is str else users} + if not isinstance(users, list) + else {i.lower().strip("@") if type(i) is str else i for i in users} ) )