mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Compare commits
7 commits
07a96f932b
...
ddb1f2b11c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddb1f2b11c | ||
|
|
907f03197a | ||
|
|
eb2b854ea6 | ||
|
|
7d10a6fb9c | ||
|
|
315f61d1ed | ||
|
|
f6599d8ef4 | ||
|
|
47b054c996 |
3 changed files with 59 additions and 4 deletions
|
|
@ -484,6 +484,7 @@ def pyrogram_api():
|
|||
BusinessWeeklyOpen
|
||||
BusinessWorkingHours
|
||||
User
|
||||
Username
|
||||
Chat
|
||||
ChatPreview
|
||||
ChatPhoto
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
__fork_name__ = "PyroFork"
|
||||
__version__ = "2.3.63"
|
||||
__version__ = "2.3.64"
|
||||
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
|
||||
__copyright__ = "Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>"
|
||||
|
||||
|
|
|
|||
|
|
@ -890,7 +890,12 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "
|
|||
command_re = re.compile(r"([\"'])(.*?)(?<!\\)\1|(\S+)")
|
||||
|
||||
async def func(flt, client: pyrogram.Client, message: Message):
|
||||
usernames = []
|
||||
username = client.me.username or ""
|
||||
if client.me.usernames:
|
||||
usernames.append(username)
|
||||
for user in client.me.usernames:
|
||||
usernames.append(user.username)
|
||||
text = message.text or message.caption
|
||||
message.command = None
|
||||
|
||||
|
|
@ -904,6 +909,24 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "
|
|||
without_prefix = text[len(prefix):]
|
||||
|
||||
for cmd in flt.commands:
|
||||
if usernames:
|
||||
for username in usernames:
|
||||
if not re.match(rf"^(?:{cmd}(?:@?{username})?)(?:\s|$)", without_prefix,
|
||||
flags=re.IGNORECASE if not flt.case_sensitive else 0):
|
||||
continue
|
||||
|
||||
without_command = re.sub(rf"{cmd}(?:@?{username})?\s?", "", without_prefix, count=1,
|
||||
flags=re.IGNORECASE if not flt.case_sensitive else 0)
|
||||
|
||||
# match.groups are 1-indexed, group(1) is the quote, group(2) is the text
|
||||
# between the quotes, group(3) is unquoted, whitespace-split text
|
||||
|
||||
# Remove the escape character from the arguments
|
||||
message.command = [cmd] + [
|
||||
re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "")
|
||||
for m in command_re.finditer(without_command)
|
||||
]
|
||||
return True
|
||||
if not re.match(rf"^(?:{cmd}(?:@?{username})?)(?:\s|$)", without_prefix,
|
||||
flags=re.IGNORECASE if not flt.case_sensitive else 0):
|
||||
continue
|
||||
|
|
@ -1011,12 +1034,22 @@ class user(Filter, set):
|
|||
)
|
||||
|
||||
async def __call__(self, _, message: Message):
|
||||
is_usernames_in_filters = False
|
||||
if message.from_user.usernames:
|
||||
for username in message.from_user.usernames:
|
||||
if (
|
||||
username.username in self
|
||||
or username.username.lower() in self
|
||||
):
|
||||
is_usernames_in_filters = True
|
||||
break
|
||||
return (message.from_user
|
||||
and (message.from_user.id in self
|
||||
or (message.from_user.username
|
||||
and message.from_user.username.lower() in self)
|
||||
or ("me" in self
|
||||
and message.from_user.is_self)))
|
||||
and message.from_user.is_self))
|
||||
or is_usernames_in_filters)
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
|
|
@ -1044,6 +1077,15 @@ class chat(Filter, set):
|
|||
|
||||
async def __call__(self, _, message: Union[Message, Story]):
|
||||
if isinstance(message, Story):
|
||||
is_usernames_in_filters = False
|
||||
if message.sender_chat.usernames:
|
||||
for username in message.sender_chat.usernames:
|
||||
if (
|
||||
username.username in self
|
||||
or username.username.lower() in self
|
||||
):
|
||||
is_usernames_in_filters = True
|
||||
break
|
||||
return (
|
||||
message.sender_chat
|
||||
and (
|
||||
|
|
@ -1062,8 +1104,17 @@ class chat(Filter, set):
|
|||
and message.from_user.username.lower() in self
|
||||
)
|
||||
)
|
||||
)
|
||||
) or is_usernames_in_filters
|
||||
else:
|
||||
is_usernames_in_filters = False
|
||||
if message.chat.usernames:
|
||||
for username in message._chat.usernames:
|
||||
if (
|
||||
username.username in self
|
||||
or username.username.lower() in self
|
||||
):
|
||||
is_usernames_in_filters = True
|
||||
break
|
||||
return (message.chat
|
||||
and (message.chat.id in self
|
||||
or (message.chat.username
|
||||
|
|
@ -1071,7 +1122,10 @@ class chat(Filter, set):
|
|||
or ("me" in self
|
||||
and message.from_user
|
||||
and message.from_user.is_self
|
||||
and not message.outgoing)))
|
||||
and not message.outgoing))
|
||||
or (is_usernames_in_filters
|
||||
and not message.outgoing)
|
||||
)
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
|
|
|
|||
Loading…
Reference in a new issue