make commandhandler case insensitive

This commit is contained in:
Eldin 2017-06-08 23:00:47 +02:00 committed by Noam Meltzer
parent 7def2c53e1
commit bc3669fa4b
2 changed files with 16 additions and 3 deletions

View file

@ -86,9 +86,9 @@ class CommandHandler(Handler):
_str = str # Python 3
if isinstance(command, _str):
self.command = [command]
self.command = [command.lower()]
else:
self.command = command
self.command = [x.lower() for x in command]
self.filters = filters
self.allow_edited = allow_edited
self.pass_args = pass_args
@ -117,7 +117,7 @@ class CommandHandler(Handler):
else:
res = self.filters(message)
return res and (message.text.startswith('/') and command[0] in self.command
return res and (message.text.startswith('/') and command[0].lower() in self.command
and command[1].lower() == message.bot.username.lower())
else:
return False

View file

@ -271,6 +271,19 @@ class UpdaterTest(BaseTest, unittest.TestCase):
sleep(.1)
self.assertTrue(None is self.received_message)
# case insensitivity
self.reset()
message = Message(0, user, None, None, text="/Test", bot=bot)
queue.put(Update(update_id=0, message=message))
sleep(.1)
self.assertTrue(self.received_message, '/Test')
handler = CommandHandler('Test', self.telegramHandlerTest)
self.updater.dispatcher.add_handler(handler)
message = Message(0, user, None, None, text="/test", bot=bot)
queue.put(Update(update_id=0, message=message))
sleep(.1)
self.assertTrue(self.received_message, '/test')
# Remove handler
d.remove_handler(handler)
handler = CommandHandler('test', self.telegramHandlerEditedTest, allow_edited=False)