We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CommandHandler should not check filters if not listening to the command
I have a filter to restrict some users from call some commands. I call `AdminFilter` and the relevant code can be seen below (actually, I check the admin users from a database).

```python
class AdminFilter(BaseFilter):
    def __init__(self, *admin_users):
        self.admin_users = admin_users

    def filter(self, message):
        if message.from_user.username in self.admin_users:
            return True
        else:
            message.reply_text("You're not an admin!", quote=True)
            return False
```

With this filter applied, when an user that is not an admin calls the forbidden command, then receives a reply warning. And here is the issue.

### Steps to reproduce
The following code illustrate the problem. In this scenario I have an administrative command `/jungle` and a normal command `/rain`.

If I am the admin, I call any command and see no issue, but If am not admin, I receive the warning for both commands.

```python
def jungle(bot, update):
    bot.send_message(update.message.chat_id, 'Welcome to the Jungle!')

def rain(bot, update):
    bot.send_message(update.message.chat_id, 'November Rain...')

dispatcher.add_handler(CommandHandler('jungle', jungle, AdminFilter('wagnermacedo')))
dispatcher.add_handler(CommandHandler('rain', rain))
```

### Expected behaviour
Suppose I'm not the bot administrator, then in a conversation with the bot, I expect the following:

```
me: /jungle
bot: > reply /jungle
       You're not an admin!
```
```
me: /rain
bot: November Rain...
```

### Actual behaviour
What happens instead is that bot reply that I'm not an admin for both commands.

For `/jungle`, it's okay, it was expected
```
me: /jungle
bot: > reply /jungle
       You're not an admin!
```

But `/rain` hasn't the admin filter, so it should not reply the warning.
```
me: /rain
bot: > reply /rain
       You're not an admin!
bot: November Rain...
```

:point_up_2: Surprisingly the command still works, even replying I'm not admin...

### Configuration
**Version of Python, python-telegram-bot & dependencies:**

I tested with the last version from master (59659ea).

```
$ python -m telegram
python-telegram-bot 10.0.1
certifi 2018.01.18
future 0.16.0
Python 3.4.8 (default, Apr 13 2018, 16:18:01)  [GCC 5.4.0 20160609]
```

### Fix
I have already fixed the issue in my machine, I'm going soon to create a pull request.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `telegram/ext/commandhandler.py`
Content:
```
1 #!/usr/bin/env python
2 #
3 # A library that provides a Python interface to the Telegram Bot API
4 # Copyright (C) 2015-2018
5 # Leandro Toledo de Souza <devs@python-telegram-bot.org>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser Public License
18 # along with this program.  If not, see [http://www.gnu.org/licenses/].
19 """This module contains the CommandHandler class."""
20 import warnings
21 
22 from future.utils import string_types
23 
24 from .handler import Handler
25 from telegram import Update
26 
27 
28 class CommandHandler(Handler):
29     """Handler class to handle Telegram commands.
30 
31     Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the
32     bot's name and/or some additional text.
33 
34     Attributes:
35         command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler
36             should listen for.
37         callback (:obj:`callable`): The callback function for this handler.
38         filters (:class:`telegram.ext.BaseFilter`): Optional. Only allow updates with these
39             Filters.
40         allow_edited (:obj:`bool`): Optional. Determines Whether the handler should also accept
41             edited messages.
42         pass_args (:obj:`bool`): Optional. Determines whether the handler should be passed
43             ``args``.
44         pass_update_queue (:obj:`bool`): Optional. Determines whether ``update_queue`` will be
45             passed to the callback function.
46         pass_job_queue (:obj:`bool`): Optional. Determines whether ``job_queue`` will be passed to
47             the callback function.
48         pass_user_data (:obj:`bool`): Optional. Determines whether ``user_data`` will be passed to
49             the callback function.
50         pass_chat_data (:obj:`bool`): Optional. Determines whether ``chat_data`` will be passed to
51             the callback function.
52 
53     Note:
54         :attr:`pass_user_data` and :attr:`pass_chat_data` determine whether a ``dict`` you
55         can use to keep any data in will be sent to the :attr:`callback` function.. Related to
56         either the user or the chat that the update was sent in. For each update from the same user
57         or in the same chat, it will be the same ``dict``.
58 
59     Args:
60         command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler
61             should listen for.
62         callback (:obj:`callable`): A function that takes ``bot, update`` as positional arguments.
63             It will be called when the :attr:`check_update` has determined that an update should be
64             processed by this handler.
65         filters (:class:`telegram.ext.BaseFilter`, optional): A filter inheriting from
66             :class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in
67             :class:`telegram.ext.filters.Filters`. Filters can be combined using bitwise
68             operators (& for and, | for or, ~ for not).
69         allow_edited (:obj:`bool`, optional): Determines whether the handler should also accept
70             edited messages. Default is ``False``.
71         pass_args (:obj:`bool`, optional): Determines whether the handler should be passed the
72             arguments passed to the command as a keyword argument called ``args``. It will contain
73             a list of strings, which is the text following the command split on single or
74             consecutive whitespace characters. Default is ``False``
75         pass_update_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called
76             ``update_queue`` will be passed to the callback function. It will be the ``Queue``
77             instance used by the :class:`telegram.ext.Updater` and :class:`telegram.ext.Dispatcher`
78             that contains new updates which can be used to insert updates. Default is ``False``.
79         pass_job_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called
80             ``job_queue`` will be passed to the callback function. It will be a
81             :class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`
82             which can be used to schedule new jobs. Default is ``False``.
83         pass_user_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
84             ``user_data`` will be passed to the callback function. Default is ``False``.
85         pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
86             ``chat_data`` will be passed to the callback function. Default is ``False``.
87 
88     """
89 
90     def __init__(self,
91                  command,
92                  callback,
93                  filters=None,
94                  allow_edited=False,
95                  pass_args=False,
96                  pass_update_queue=False,
97                  pass_job_queue=False,
98                  pass_user_data=False,
99                  pass_chat_data=False):
100         super(CommandHandler, self).__init__(
101             callback,
102             pass_update_queue=pass_update_queue,
103             pass_job_queue=pass_job_queue,
104             pass_user_data=pass_user_data,
105             pass_chat_data=pass_chat_data)
106 
107         if isinstance(command, string_types):
108             self.command = [command.lower()]
109         else:
110             self.command = [x.lower() for x in command]
111         self.filters = filters
112         self.allow_edited = allow_edited
113         self.pass_args = pass_args
114 
115         # We put this up here instead of with the rest of checking code
116         # in check_update since we don't wanna spam a ton
117         if isinstance(self.filters, list):
118             warnings.warn('Using a list of filters in MessageHandler is getting '
119                           'deprecated, please use bitwise operators (& and |) '
120                           'instead. More info: https://git.io/vPTbc.')
121 
122     def check_update(self, update):
123         """Determines whether an update should be passed to this handlers :attr:`callback`.
124 
125         Args:
126             update (:class:`telegram.Update`): Incoming telegram update.
127 
128         Returns:
129             :obj:`bool`
130 
131         """
132         if (isinstance(update, Update)
133                 and (update.message or update.edited_message and self.allow_edited)):
134             message = update.message or update.edited_message
135 
136             if message.text and message.text.startswith('/') and len(message.text) > 1:
137                 first_word = message.text_html.split(None, 1)[0]
138                 if len(first_word) > 1 and first_word.startswith('/'):
139                     command = first_word[1:].split('@')
140                     command.append(
141                         message.bot.username)  # in case the command was sent without a username
142 
143                     if self.filters is None:
144                         res = True
145                     elif isinstance(self.filters, list):
146                         res = any(func(message) for func in self.filters)
147                     else:
148                         res = self.filters(message)
149 
150                     return res and (command[0].lower() in self.command
151                                     and command[1].lower() == message.bot.username.lower())
152 
153         return False
154 
155     def handle_update(self, update, dispatcher):
156         """Send the update to the :attr:`callback`.
157 
158         Args:
159             update (:class:`telegram.Update`): Incoming telegram update.
160             dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
161 
162         """
163         optional_args = self.collect_optional_args(dispatcher, update)
164 
165         message = update.message or update.edited_message
166 
167         if self.pass_args:
168             optional_args['args'] = message.text.split()[1:]
169 
170         return self.callback(dispatcher.bot, update, **optional_args)
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py
--- a/telegram/ext/commandhandler.py
+++ b/telegram/ext/commandhandler.py
@@ -140,6 +140,10 @@
                     command.append(
                         message.bot.username)  # in case the command was sent without a username
 
+                    if not (command[0].lower() in self.command
+                            and command[1].lower() == message.bot.username.lower()):
+                        return False
+
                     if self.filters is None:
                         res = True
                     elif isinstance(self.filters, list):
@@ -147,8 +151,7 @@
                     else:
                         res = self.filters(message)
 
-                    return res and (command[0].lower() in self.command
-                                    and command[1].lower() == message.bot.username.lower())
+                    return res
 
         return False

{"golden_diff": "diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py\n--- a/telegram/ext/commandhandler.py\n+++ b/telegram/ext/commandhandler.py\n@@ -140,6 +140,10 @@\n                     command.append(\n                         message.bot.username)  # in case the command was sent without a username\n \n+                    if not (command[0].lower() in self.command\n+                            and command[1].lower() == message.bot.username.lower()):\n+                        return False\n+\n                     if self.filters is None:\n                         res = True\n                     elif isinstance(self.filters, list):\n@@ -147,8 +151,7 @@\n                     else:\n                         res = self.filters(message)\n \n-                    return res and (command[0].lower() in self.command\n-                                    and command[1].lower() == message.bot.username.lower())\n+                    return res\n \n         return False\n", "issue": "CommandHandler should not check filters if not listening to the command\nI have a filter to restrict some users from call some commands. I call `AdminFilter` and the relevant code can be seen below (actually, I check the admin users from a database).\r\n\r\n```python\r\nclass AdminFilter(BaseFilter):\r\n    def __init__(self, *admin_users):\r\n        self.admin_users = admin_users\r\n\r\n    def filter(self, message):\r\n        if message.from_user.username in self.admin_users:\r\n            return True\r\n        else:\r\n            message.reply_text(\"You're not an admin!\", quote=True)\r\n            return False\r\n```\r\n\r\nWith this filter applied, when an user that is not an admin calls the forbidden command, then receives a reply warning. And here is the issue.\r\n\r\n### Steps to reproduce\r\nThe following code illustrate the problem. In this scenario I have an administrative command `/jungle` and a normal command `/rain`.\r\n\r\nIf I am the admin, I call any command and see no issue, but If am not admin, I receive the warning for both commands.\r\n\r\n```python\r\ndef jungle(bot, update):\r\n    bot.send_message(update.message.chat_id, 'Welcome to the Jungle!')\r\n\r\ndef rain(bot, update):\r\n    bot.send_message(update.message.chat_id, 'November Rain...')\r\n\r\ndispatcher.add_handler(CommandHandler('jungle', jungle, AdminFilter('wagnermacedo')))\r\ndispatcher.add_handler(CommandHandler('rain', rain))\r\n```\r\n\r\n### Expected behaviour\r\nSuppose I'm not the bot administrator, then in a conversation with the bot, I expect the following:\r\n\r\n```\r\nme: /jungle\r\nbot: > reply /jungle\r\n       You're not an admin!\r\n```\r\n```\r\nme: /rain\r\nbot: November Rain...\r\n```\r\n\r\n### Actual behaviour\r\nWhat happens instead is that bot reply that I'm not an admin for both commands.\r\n\r\nFor `/jungle`, it's okay, it was expected\r\n```\r\nme: /jungle\r\nbot: > reply /jungle\r\n       You're not an admin!\r\n```\r\n\r\nBut `/rain` hasn't the admin filter, so it should not reply the warning.\r\n```\r\nme: /rain\r\nbot: > reply /rain\r\n       You're not an admin!\r\nbot: November Rain...\r\n```\r\n\r\n:point_up_2: Surprisingly the command still works, even replying I'm not admin...\r\n\r\n### Configuration\r\n**Version of Python, python-telegram-bot & dependencies:**\r\n\r\nI tested with the last version from master (59659ea).\r\n\r\n```\r\n$ python -m telegram\r\npython-telegram-bot 10.0.1\r\ncertifi 2018.01.18\r\nfuture 0.16.0\r\nPython 3.4.8 (default, Apr 13 2018, 16:18:01)  [GCC 5.4.0 20160609]\r\n```\r\n\r\n### Fix\r\nI have already fixed the issue in my machine, I'm going soon to create a pull request.\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2018\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains the CommandHandler class.\"\"\"\nimport warnings\n\nfrom future.utils import string_types\n\nfrom .handler import Handler\nfrom telegram import Update\n\n\nclass CommandHandler(Handler):\n    \"\"\"Handler class to handle Telegram commands.\n\n    Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the\n    bot's name and/or some additional text.\n\n    Attributes:\n        command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler\n            should listen for.\n        callback (:obj:`callable`): The callback function for this handler.\n        filters (:class:`telegram.ext.BaseFilter`): Optional. Only allow updates with these\n            Filters.\n        allow_edited (:obj:`bool`): Optional. Determines Whether the handler should also accept\n            edited messages.\n        pass_args (:obj:`bool`): Optional. Determines whether the handler should be passed\n            ``args``.\n        pass_update_queue (:obj:`bool`): Optional. Determines whether ``update_queue`` will be\n            passed to the callback function.\n        pass_job_queue (:obj:`bool`): Optional. Determines whether ``job_queue`` will be passed to\n            the callback function.\n        pass_user_data (:obj:`bool`): Optional. Determines whether ``user_data`` will be passed to\n            the callback function.\n        pass_chat_data (:obj:`bool`): Optional. Determines whether ``chat_data`` will be passed to\n            the callback function.\n\n    Note:\n        :attr:`pass_user_data` and :attr:`pass_chat_data` determine whether a ``dict`` you\n        can use to keep any data in will be sent to the :attr:`callback` function.. Related to\n        either the user or the chat that the update was sent in. For each update from the same user\n        or in the same chat, it will be the same ``dict``.\n\n    Args:\n        command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler\n            should listen for.\n        callback (:obj:`callable`): A function that takes ``bot, update`` as positional arguments.\n            It will be called when the :attr:`check_update` has determined that an update should be\n            processed by this handler.\n        filters (:class:`telegram.ext.BaseFilter`, optional): A filter inheriting from\n            :class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in\n            :class:`telegram.ext.filters.Filters`. Filters can be combined using bitwise\n            operators (& for and, | for or, ~ for not).\n        allow_edited (:obj:`bool`, optional): Determines whether the handler should also accept\n            edited messages. Default is ``False``.\n        pass_args (:obj:`bool`, optional): Determines whether the handler should be passed the\n            arguments passed to the command as a keyword argument called ``args``. It will contain\n            a list of strings, which is the text following the command split on single or\n            consecutive whitespace characters. Default is ``False``\n        pass_update_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``update_queue`` will be passed to the callback function. It will be the ``Queue``\n            instance used by the :class:`telegram.ext.Updater` and :class:`telegram.ext.Dispatcher`\n            that contains new updates which can be used to insert updates. Default is ``False``.\n        pass_job_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``job_queue`` will be passed to the callback function. It will be a\n            :class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`\n            which can be used to schedule new jobs. Default is ``False``.\n        pass_user_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``user_data`` will be passed to the callback function. Default is ``False``.\n        pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``chat_data`` will be passed to the callback function. Default is ``False``.\n\n    \"\"\"\n\n    def __init__(self,\n                 command,\n                 callback,\n                 filters=None,\n                 allow_edited=False,\n                 pass_args=False,\n                 pass_update_queue=False,\n                 pass_job_queue=False,\n                 pass_user_data=False,\n                 pass_chat_data=False):\n        super(CommandHandler, self).__init__(\n            callback,\n            pass_update_queue=pass_update_queue,\n            pass_job_queue=pass_job_queue,\n            pass_user_data=pass_user_data,\n            pass_chat_data=pass_chat_data)\n\n        if isinstance(command, string_types):\n            self.command = [command.lower()]\n        else:\n            self.command = [x.lower() for x in command]\n        self.filters = filters\n        self.allow_edited = allow_edited\n        self.pass_args = pass_args\n\n        # We put this up here instead of with the rest of checking code\n        # in check_update since we don't wanna spam a ton\n        if isinstance(self.filters, list):\n            warnings.warn('Using a list of filters in MessageHandler is getting '\n                          'deprecated, please use bitwise operators (& and |) '\n                          'instead. More info: https://git.io/vPTbc.')\n\n    def check_update(self, update):\n        \"\"\"Determines whether an update should be passed to this handlers :attr:`callback`.\n\n        Args:\n            update (:class:`telegram.Update`): Incoming telegram update.\n\n        Returns:\n            :obj:`bool`\n\n        \"\"\"\n        if (isinstance(update, Update)\n                and (update.message or update.edited_message and self.allow_edited)):\n            message = update.message or update.edited_message\n\n            if message.text and message.text.startswith('/') and len(message.text) > 1:\n                first_word = message.text_html.split(None, 1)[0]\n                if len(first_word) > 1 and first_word.startswith('/'):\n                    command = first_word[1:].split('@')\n                    command.append(\n                        message.bot.username)  # in case the command was sent without a username\n\n                    if self.filters is None:\n                        res = True\n                    elif isinstance(self.filters, list):\n                        res = any(func(message) for func in self.filters)\n                    else:\n                        res = self.filters(message)\n\n                    return res and (command[0].lower() in self.command\n                                    and command[1].lower() == message.bot.username.lower())\n\n        return False\n\n    def handle_update(self, update, dispatcher):\n        \"\"\"Send the update to the :attr:`callback`.\n\n        Args:\n            update (:class:`telegram.Update`): Incoming telegram update.\n            dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.\n\n        \"\"\"\n        optional_args = self.collect_optional_args(dispatcher, update)\n\n        message = update.message or update.edited_message\n\n        if self.pass_args:\n            optional_args['args'] = message.text.split()[1:]\n\n        return self.callback(dispatcher.bot, update, **optional_args)\n", "path": "telegram/ext/commandhandler.py"}], "after_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2018\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains the CommandHandler class.\"\"\"\nimport warnings\n\nfrom future.utils import string_types\n\nfrom .handler import Handler\nfrom telegram import Update\n\n\nclass CommandHandler(Handler):\n    \"\"\"Handler class to handle Telegram commands.\n\n    Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the\n    bot's name and/or some additional text.\n\n    Attributes:\n        command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler\n            should listen for.\n        callback (:obj:`callable`): The callback function for this handler.\n        filters (:class:`telegram.ext.BaseFilter`): Optional. Only allow updates with these\n            Filters.\n        allow_edited (:obj:`bool`): Optional. Determines Whether the handler should also accept\n            edited messages.\n        pass_args (:obj:`bool`): Optional. Determines whether the handler should be passed\n            ``args``.\n        pass_update_queue (:obj:`bool`): Optional. Determines whether ``update_queue`` will be\n            passed to the callback function.\n        pass_job_queue (:obj:`bool`): Optional. Determines whether ``job_queue`` will be passed to\n            the callback function.\n        pass_user_data (:obj:`bool`): Optional. Determines whether ``user_data`` will be passed to\n            the callback function.\n        pass_chat_data (:obj:`bool`): Optional. Determines whether ``chat_data`` will be passed to\n            the callback function.\n\n    Note:\n        :attr:`pass_user_data` and :attr:`pass_chat_data` determine whether a ``dict`` you\n        can use to keep any data in will be sent to the :attr:`callback` function.. Related to\n        either the user or the chat that the update was sent in. For each update from the same user\n        or in the same chat, it will be the same ``dict``.\n\n    Args:\n        command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler\n            should listen for.\n        callback (:obj:`callable`): A function that takes ``bot, update`` as positional arguments.\n            It will be called when the :attr:`check_update` has determined that an update should be\n            processed by this handler.\n        filters (:class:`telegram.ext.BaseFilter`, optional): A filter inheriting from\n            :class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in\n            :class:`telegram.ext.filters.Filters`. Filters can be combined using bitwise\n            operators (& for and, | for or, ~ for not).\n        allow_edited (:obj:`bool`, optional): Determines whether the handler should also accept\n            edited messages. Default is ``False``.\n        pass_args (:obj:`bool`, optional): Determines whether the handler should be passed the\n            arguments passed to the command as a keyword argument called ``args``. It will contain\n            a list of strings, which is the text following the command split on single or\n            consecutive whitespace characters. Default is ``False``\n        pass_update_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``update_queue`` will be passed to the callback function. It will be the ``Queue``\n            instance used by the :class:`telegram.ext.Updater` and :class:`telegram.ext.Dispatcher`\n            that contains new updates which can be used to insert updates. Default is ``False``.\n        pass_job_queue (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``job_queue`` will be passed to the callback function. It will be a\n            :class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`\n            which can be used to schedule new jobs. Default is ``False``.\n        pass_user_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``user_data`` will be passed to the callback function. Default is ``False``.\n        pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called\n            ``chat_data`` will be passed to the callback function. Default is ``False``.\n\n    \"\"\"\n\n    def __init__(self,\n                 command,\n                 callback,\n                 filters=None,\n                 allow_edited=False,\n                 pass_args=False,\n                 pass_update_queue=False,\n                 pass_job_queue=False,\n                 pass_user_data=False,\n                 pass_chat_data=False):\n        super(CommandHandler, self).__init__(\n            callback,\n            pass_update_queue=pass_update_queue,\n            pass_job_queue=pass_job_queue,\n            pass_user_data=pass_user_data,\n            pass_chat_data=pass_chat_data)\n\n        if isinstance(command, string_types):\n            self.command = [command.lower()]\n        else:\n            self.command = [x.lower() for x in command]\n        self.filters = filters\n        self.allow_edited = allow_edited\n        self.pass_args = pass_args\n\n        # We put this up here instead of with the rest of checking code\n        # in check_update since we don't wanna spam a ton\n        if isinstance(self.filters, list):\n            warnings.warn('Using a list of filters in MessageHandler is getting '\n                          'deprecated, please use bitwise operators (& and |) '\n                          'instead. More info: https://git.io/vPTbc.')\n\n    def check_update(self, update):\n        \"\"\"Determines whether an update should be passed to this handlers :attr:`callback`.\n\n        Args:\n            update (:class:`telegram.Update`): Incoming telegram update.\n\n        Returns:\n            :obj:`bool`\n\n        \"\"\"\n        if (isinstance(update, Update)\n                and (update.message or update.edited_message and self.allow_edited)):\n            message = update.message or update.edited_message\n\n            if message.text and message.text.startswith('/') and len(message.text) > 1:\n                first_word = message.text_html.split(None, 1)[0]\n                if len(first_word) > 1 and first_word.startswith('/'):\n                    command = first_word[1:].split('@')\n                    command.append(\n                        message.bot.username)  # in case the command was sent without a username\n\n                    if not (command[0].lower() in self.command\n                            and command[1].lower() == message.bot.username.lower()):\n                        return False\n\n                    if self.filters is None:\n                        res = True\n                    elif isinstance(self.filters, list):\n                        res = any(func(message) for func in self.filters)\n                    else:\n                        res = self.filters(message)\n\n                    return res\n\n        return False\n\n    def handle_update(self, update, dispatcher):\n        \"\"\"Send the update to the :attr:`callback`.\n\n        Args:\n            update (:class:`telegram.Update`): Incoming telegram update.\n            dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.\n\n        \"\"\"\n        optional_args = self.collect_optional_args(dispatcher, update)\n\n        message = update.message or update.edited_message\n\n        if self.pass_args:\n            optional_args['args'] = message.text.split()[1:]\n\n        return self.callback(dispatcher.bot, update, **optional_args)\n", "path": "telegram/ext/commandhandler.py"}]}