Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions telegram/ext/regexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ def check_update(self, update):
Returns:
:obj:`bool`
"""

if not isinstance(update, Update) and not update.effective_message:
return False
if any([(self.message_updates and update.message),
(self.edited_updates and update.edited_message),
(self.channel_post_updates and update.channel_post)]) and (
isinstance(update, Update)):
(self.channel_post_updates and update.channel_post)]) and \
update.effective_message.text:
match = re.match(self.pattern, update.effective_message.text)
return bool(match)
return False
Expand Down
36 changes: 25 additions & 11 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

from future.builtins import bytes

from telegram.utils.request import Request as Requester

try:
# python2
from urllib2 import urlopen, Request, HTTPError
Expand All @@ -47,12 +45,12 @@
sys.path.append('.')

from telegram import (Update, Message, TelegramError, User, Chat, Bot,
InlineQuery, CallbackQuery, ShippingQuery, PreCheckoutQuery)
InlineQuery, CallbackQuery)
from telegram.ext import *
from telegram.ext.dispatcher import run_async
from telegram.error import Unauthorized, InvalidToken
from tests.base import BaseTest
from threading import Lock, Thread, current_thread, Semaphore
from threading import Lock, Thread, current_thread

# Enable logging
root = logging.getLogger()
Expand Down Expand Up @@ -248,6 +246,23 @@ def test_addRemoveTelegramRegexHandler(self):
sleep(.1)
self.assertTrue(None is self.received_message)

def test_regex_handler_without_message(self):
self._setup_updater('Test3')
d = self.updater.dispatcher
handler = RegexHandler(r'Te.*', self.telegramHandlerTest)
d.add_handler(handler)

# message, no text
m = Message(1, User(1, "testuser"), None, Chat(2, "private"), video="My_vid",
caption="test ")
d.process_update(Update(1, message=m))
self.assertEqual(self.message_count, 0)

# no message
c = InlineQuery(2, User(1, "testuser"), "my_query", offset=15)
d.process_update(Update(2, inline_query=c))
self.assertEqual(self.message_count, 0)

def test_addRemoveTelegramCommandHandler(self):
self._setup_updater('', messages=0)
d = self.updater.dispatcher
Expand Down Expand Up @@ -926,7 +941,6 @@ def test_noTokenOrBot(self):


class MockBot(object):

def __init__(self,
text,
messages=1,
Expand Down Expand Up @@ -973,12 +987,12 @@ def delete_webhook(self):
raise self.bootstrap_err

def get_updates(self,
offset=None,
limit=100,
timeout=0,
network_delay=None,
read_latency=2.,
allowed_updates=None):
offset=None,
limit=100,
timeout=0,
network_delay=None,
read_latency=2.,
allowed_updates=None):

if self.raise_error:
raise TelegramError('Test Error 2')
Expand Down