In text message handler, make available both lowered and original text and inspect condition parameters
This commit is contained in:
parent
e29bb08b7b
commit
3e19ba4c81
@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "2.6.12"
|
__version__ = "2.6.13"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -807,7 +807,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
async def text_message_handler(self, update, user_record, language=None):
|
async def text_message_handler(self, update, user_record, language=None):
|
||||||
"""Handle `text` message update."""
|
"""Handle `text` message update."""
|
||||||
replier, reply = None, None
|
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
|
user_id = update['from']['id'] if 'from' in update else None
|
||||||
if user_id in self.individual_text_message_handlers:
|
if user_id in self.individual_text_message_handlers:
|
||||||
replier = self.individual_text_message_handlers[user_id]
|
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.
|
# Commands can use latin letters, numbers and underscores.
|
||||||
command = re.search(
|
command = re.search(
|
||||||
r"([A-z_1-9]){1,32}", # Command pattern (without leading `/`)
|
r"([A-z_1-9]){1,32}", # Command pattern (without leading `/`)
|
||||||
text
|
lowered_text
|
||||||
).group(0) # Get the first group of characters matching pattern
|
).group(0) # Get the first group of characters matching pattern
|
||||||
if command in self.commands:
|
if command in self.commands:
|
||||||
replier = self.commands[command]['handler']
|
replier = self.commands[command]['handler']
|
||||||
@ -840,18 +841,16 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
else: # Handle command aliases and text parsers
|
else: # Handle command aliases and text parsers
|
||||||
# Aliases are case insensitive: text and alias are both .lower()
|
# Aliases are case insensitive: text and alias are both .lower()
|
||||||
for alias, function in self.command_aliases.items():
|
for alias, function in self.command_aliases.items():
|
||||||
if text.startswith(alias.lower()):
|
if lowered_text.startswith(alias.lower()):
|
||||||
replier = function
|
replier = function
|
||||||
break
|
break
|
||||||
# Text message update parsers
|
# Text message update parsers
|
||||||
for check_function, parser in self.text_message_parsers.items():
|
for check_function, parser in self.text_message_parsers.items():
|
||||||
if (
|
if check_function(
|
||||||
parser['argument'] == 'text'
|
**{name: argument
|
||||||
and check_function(text)
|
for name, argument in locals().items()
|
||||||
) or (
|
if name in inspect.signature(
|
||||||
parser['argument'] == 'update'
|
check_function).parameters}):
|
||||||
and check_function(update)
|
|
||||||
):
|
|
||||||
replier = parser['handler']
|
replier = parser['handler']
|
||||||
break
|
break
|
||||||
if replier:
|
if replier:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user