1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00
This commit is contained in:
eternnoir 2015-07-22 14:02:16 +08:00
parent f7168770ab
commit ba1693dcf0
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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)