mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-30 13:57:54 +00:00
Allow specifying more than one prefix in Filters.command
This commit is contained in:
@@ -168,7 +168,7 @@ class Filters:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def command(command: str or list,
|
def command(command: str or list,
|
||||||
prefix: str = "/",
|
prefix: str or list = "/",
|
||||||
separator: str = " ",
|
separator: str = " ",
|
||||||
case_sensitive: bool = False):
|
case_sensitive: bool = False):
|
||||||
"""Filter commands, i.e.: text messages starting with "/" or any other custom prefix.
|
"""Filter commands, i.e.: text messages starting with "/" or any other custom prefix.
|
||||||
@@ -180,8 +180,8 @@ class Filters:
|
|||||||
a command arrives, the command itself and its arguments will be stored in the *command*
|
a command arrives, the command itself and its arguments will be stored in the *command*
|
||||||
field of the :class:`Message <pyrogram.Message>`.
|
field of the :class:`Message <pyrogram.Message>`.
|
||||||
|
|
||||||
prefix (``str``, *optional*):
|
prefix (``str`` | ``list``, *optional*):
|
||||||
The command prefix. Defaults to "/" (slash).
|
A prefix or a list of prefixes as string. Defaults to "/" (slash).
|
||||||
Examples: /start, .help, !settings.
|
Examples: /start, .help, !settings.
|
||||||
|
|
||||||
separator (``str``, *optional*):
|
separator (``str``, *optional*):
|
||||||
@@ -194,11 +194,14 @@ class Filters:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def f(_, m):
|
def f(_, m):
|
||||||
if m.text and m.text.startswith(_.p):
|
if m.text:
|
||||||
|
for i in _.p:
|
||||||
|
if m.text.startswith(i):
|
||||||
t = m.text.split(_.s)
|
t = m.text.split(_.s)
|
||||||
c, a = t[0][len(_.p):], t[1:]
|
c, a = t[0][len(i):], t[1:]
|
||||||
c = c if _.cs else c.lower()
|
c = c if _.cs else c.lower()
|
||||||
m.command = ([c] + a) if c in _.c else None
|
m.command = ([c] + a) if c in _.c else None
|
||||||
|
break
|
||||||
|
|
||||||
return bool(m.command)
|
return bool(m.command)
|
||||||
|
|
||||||
@@ -211,7 +214,7 @@ class Filters:
|
|||||||
else {c if case_sensitive
|
else {c if case_sensitive
|
||||||
else c.lower()
|
else c.lower()
|
||||||
for c in command},
|
for c in command},
|
||||||
p=prefix,
|
p=set(prefix),
|
||||||
s=separator,
|
s=separator,
|
||||||
cs=case_sensitive
|
cs=case_sensitive
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user