diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 0d7d22b..f7c6a86 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -11,7 +11,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.6.12" +__version__ = "2.6.13" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/bot.py b/davtelepot/bot.py index 235eb49..6e8e423 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -807,7 +807,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): async def text_message_handler(self, update, user_record, language=None): """Handle `text` message update.""" replier, reply = None, None - text = update['text'].lower() + text = update['text'] + lowered_text = text.lower() user_id = update['from']['id'] if 'from' in update else None if user_id in self.individual_text_message_handlers: replier = self.individual_text_message_handlers[user_id] @@ -818,7 +819,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): # Commands can use latin letters, numbers and underscores. command = re.search( r"([A-z_1-9]){1,32}", # Command pattern (without leading `/`) - text + lowered_text ).group(0) # Get the first group of characters matching pattern if command in self.commands: replier = self.commands[command]['handler'] @@ -840,18 +841,16 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): else: # Handle command aliases and text parsers # Aliases are case insensitive: text and alias are both .lower() for alias, function in self.command_aliases.items(): - if text.startswith(alias.lower()): + if lowered_text.startswith(alias.lower()): replier = function break # Text message update parsers for check_function, parser in self.text_message_parsers.items(): - if ( - parser['argument'] == 'text' - and check_function(text) - ) or ( - parser['argument'] == 'update' - and check_function(update) - ): + if check_function( + **{name: argument + for name, argument in locals().items() + if name in inspect.signature( + check_function).parameters}): replier = parser['handler'] break if replier: