mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 20:59:29 +00:00
Merge pull request #137 from pyrogram/multiple-command-prefixes
Allow multiple command prefixes in a single filter
This commit is contained in:
commit
cc7db735b0
@ -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,9 +180,9 @@ 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 the filter should look for.
|
||||||
Examples: /start, .help, !settings.
|
Defaults to "/" (slash). Examples: ".", "!", ["/", "!", "."].
|
||||||
|
|
||||||
separator (``str``, *optional*):
|
separator (``str``, *optional*):
|
||||||
The command arguments separator. Defaults to " " (white space).
|
The command arguments separator. Defaults to " " (white space).
|
||||||
@ -194,11 +194,14 @@ class Filters:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def f(_, m):
|
def f(_, m):
|
||||||
if m.text and m.text.startswith(_.p):
|
if m.text:
|
||||||
t = m.text.split(_.s)
|
for i in _.p:
|
||||||
c, a = t[0][len(_.p):], t[1:]
|
if m.text.startswith(i):
|
||||||
c = c if _.cs else c.lower()
|
t = m.text.split(_.s)
|
||||||
m.command = ([c] + a) if c in _.c else None
|
c, a = t[0][len(i):], t[1:]
|
||||||
|
c = c if _.cs else c.lower()
|
||||||
|
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
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user