Repository: python-telegram-bot/python-telegram-bot

Issue:
CommandHandler - Check if update meant to be sent to the bot - Case-sensitivity
<!--
Thanks for reporting issues of python-telegram-bot!
To make it easier for us to help you please enter detailed information below.

Please note, we only support the latest version of python-telegram-bot and
master branch. Please make sure to upgrade & recreate the issue on the latest
version prior to opening an issue.
-->
When the bot registered its username as `@ThisIsMyBot`, it should be case insensitive in any usage.
But now when commands meant to be sent to the bot with different cases of that from `getMe()`, it gets omitted.

Reference: #515 

### Steps to reproduce
1. Put multiple bots in a group, here for example `@NotMyBot` and `@ThisIsMyBot` (assume all bots have access to all messages)

2. Then use different kinds of command patterns:

- (a) `/command`
- (b) `/command@NotMyBot`
- (c) `/command@ThisIsMyBot`
- (d) `/command@thisismybot`

### Expected behaviour
- (a) Both bots should receive `/command`
- (b) The command was not meant for my bot, so omitted.
- (c) The command was meant for my bot, so receiving the update.
- (d) The command was meant for my bot (even with different cases), so receiving the update.

### Actual behaviour
- (a) Received, correct
- (b) Omiited, correct
- (c) Received, correct
- (d) **The command got omitted**

### Configuration
**Operating System:**
Ubuntu 16.04 LTS

**Version of Python, python-telegram-bot & dependencies:**

```
python-telegram-bot 5.3.0
urllib3 1.20
certifi 2017.01.23
future 0.16.0
Python 3.5.2 (default, Nov 17 2016, 17:05:23)  [GCC 5.4.0 20160609]
```

### Logs




Discussion:

Resolving patch:
diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py
--- a/telegram/ext/commandhandler.py
+++ b/telegram/ext/commandhandler.py
@@ -110,7 +110,7 @@ def check_update(self, update):
                     res = self.filters(message)
 
                 return res and (message.text.startswith('/') and command[0] == self.command
-                                and command[1] == update.message.bot.username)
+                                and command[1].lower() == update.message.bot.username.lower())
             else:
                 return False
 
diff --git a/telegram/ext/messagequeue.py b/telegram/ext/messagequeue.py
--- a/telegram/ext/messagequeue.py
+++ b/telegram/ext/messagequeue.py
@@ -38,7 +38,7 @@
 #  on Windows, the best available is time.clock while time.time is on
 #  another platforms (M. Lutz, "Learning Python," 4ed, p.630-634)
 if sys.version_info.major == 3 and sys.version_info.minor >= 3:
-    curtime = time.perf_counter
+    curtime = time.perf_counter  # pylint: disable=E1101
 else:
     curtime = time.clock if sys.platform[:3] == 'win' else time.time
 


Test patch:
diff --git a/tests/test_updater.py b/tests/test_updater.py
--- a/tests/test_updater.py
+++ b/tests/test_updater.py
@@ -250,6 +250,10 @@ def test_addRemoveTelegramCommandHandler(self):
         queue.put(Update(update_id=0, message=message))
         sleep(.1)
         self.assertEqual(self.received_message, '/test@MockBot')
+        message.text = "/test@mockbot"
+        queue.put(Update(update_id=0, message=message))
+        sleep(.1)
+        self.assertEqual(self.received_message, '/test@mockbot')
 
         # directed at other bot
         self.reset()