diff --git a/telebot/__init__.py b/telebot/__init__.py index b347b20..1f7c106 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -372,7 +372,7 @@ class TeleBot: return TeleBot.extract_command(message.text) in message_handler['commands'] if 'regexp' in message_handler and message.content_type == 'text' and re.search(message_handler['regexp'], message.text): - return False + return True if 'lambda' in message_handler: return message_handler['lambda'](message) return False diff --git a/tests/test_telebot.py b/tests/test_telebot.py index 7fa9c32..0c2ba55 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -36,6 +36,27 @@ def test_message_handler(): time.sleep(1) assert msg.text == 'got' +def test_message_handler_reg(): + bot = telebot.TeleBot('') + msg = create_text_message(r'https://web.telegram.org/') + @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') + def command_url(message): + msg.text = 'got' + bot.process_new_messages([msg]) + time.sleep(1) + assert msg.text == 'got' + + +def test_message_handler_reg_fail(): + bot = telebot.TeleBot('') + msg = create_text_message(r'web.telegram.org/') + @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') + def command_url(message): + msg.text = 'got' + bot.process_new_messages([msg]) + time.sleep(1) + assert not msg.text == 'got' + def test_send_file_by_id(): file_id = 'BQADBQADjAIAAsYifgbvqwq1he9REAI' @@ -115,3 +136,4 @@ def test_is_string_string(): def test_not_string(): i1 = 10 assert not apihelper.is_string(i1) +