mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Simplify user and chat filters implementation
This commit is contained in:
parent
0c5f5738a5
commit
88078d4573
@ -311,21 +311,20 @@ class Filters:
|
|||||||
|
|
||||||
def __init__(self, users: int or str or list = None):
|
def __init__(self, users: int or str or list = None):
|
||||||
users = [] if users is None else users if type(users) is list else [users]
|
users = [] if users is None else users if type(users) is list else [users]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
{"me" if i in ["me", "self"] else i.lower().strip("@") if type(i) is str else i for i in users}
|
"me" if u in ["me", "self"]
|
||||||
if type(users) is list else
|
else u.lower().strip("@") if type(u) is str
|
||||||
{"me" if users in ["me", "self"] else users.lower().strip("@") if type(users) is str else users}
|
else u for u in users
|
||||||
)
|
)
|
||||||
|
|
||||||
def __call__(self, message):
|
def __call__(self, message):
|
||||||
return bool(
|
return (message.from_user
|
||||||
message.from_user
|
and (message.from_user.id in self
|
||||||
and (message.from_user.id in self
|
or (message.from_user.username
|
||||||
or (message.from_user.username
|
and message.from_user.username.lower() in self)
|
||||||
and message.from_user.username.lower() in self)
|
or ("me" in self
|
||||||
or ("me" in self
|
and message.from_user.is_self)))
|
||||||
and message.from_user.is_self))
|
|
||||||
)
|
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
class chat(Filter, set):
|
class chat(Filter, set):
|
||||||
@ -343,21 +342,21 @@ class Filters:
|
|||||||
|
|
||||||
def __init__(self, chats: int or str or list = None):
|
def __init__(self, chats: int or str or list = None):
|
||||||
chats = [] if chats is None else chats if type(chats) is list else [chats]
|
chats = [] if chats is None else chats if type(chats) is list else [chats]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
{"me" if i in ["me", "self"] else i.lower().strip("@") if type(i) is str else i for i in chats}
|
"me" if c in ["me", "self"]
|
||||||
if type(chats) is list else
|
else c.lower().strip("@") if type(c) is str
|
||||||
{"me" if chats in ["me", "self"] else chats.lower().strip("@") if type(chats) is str else chats}
|
else c for c in chats
|
||||||
)
|
)
|
||||||
|
|
||||||
def __call__(self, message):
|
def __call__(self, message):
|
||||||
return bool(
|
return (message.chat
|
||||||
message.chat
|
and (message.chat.id in self
|
||||||
and (message.chat.id in self
|
or (message.chat.username
|
||||||
or (message.chat.username
|
and message.chat.username.lower() in self)
|
||||||
and message.chat.username.lower() in self)
|
or ("me" in self
|
||||||
or ("me" in self and message.from_user
|
and message.from_user
|
||||||
and message.from_user.is_self
|
and message.from_user.is_self
|
||||||
and not message.outgoing))
|
and not message.outgoing)))
|
||||||
)
|
|
||||||
|
|
||||||
dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162))
|
dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user