From b79df81f14dcb1cb1cb08ce609d7f3e634d9408a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Oct 2018 14:24:53 +0200 Subject: [PATCH 1/2] Allow specifying more than one prefix in Filters.command --- pyrogram/client/filters/filters.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 79ab0f5f..93322e1d 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -168,7 +168,7 @@ class Filters: @staticmethod def command(command: str or list, - prefix: str = "/", + prefix: str or list = "/", separator: str = " ", case_sensitive: bool = False): """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* field of the :class:`Message `. - prefix (``str``, *optional*): - The command prefix. Defaults to "/" (slash). + prefix (``str`` | ``list``, *optional*): + A prefix or a list of prefixes as string. Defaults to "/" (slash). Examples: /start, .help, !settings. separator (``str``, *optional*): @@ -194,11 +194,14 @@ class Filters: """ def f(_, m): - if m.text and m.text.startswith(_.p): - t = m.text.split(_.s) - c, a = t[0][len(_.p):], t[1:] - c = c if _.cs else c.lower() - m.command = ([c] + a) if c in _.c else None + if m.text: + for i in _.p: + if m.text.startswith(i): + t = m.text.split(_.s) + 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) @@ -211,7 +214,7 @@ class Filters: else {c if case_sensitive else c.lower() for c in command}, - p=prefix, + p=set(prefix), s=separator, cs=case_sensitive ) From 841141077f663c393186e6f18a21a96ff0e34e44 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:53:05 +0200 Subject: [PATCH 2/2] Add better examples to Filters.command --- pyrogram/client/filters/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 93322e1d..e80e230e 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -181,8 +181,8 @@ class Filters: field of the :class:`Message `. prefix (``str`` | ``list``, *optional*): - A prefix or a list of prefixes as string. Defaults to "/" (slash). - Examples: /start, .help, !settings. + A prefix or a list of prefixes as string the filter should look for. + Defaults to "/" (slash). Examples: ".", "!", ["/", "!", "."]. separator (``str``, *optional*): The command arguments separator. Defaults to " " (white space).