mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-18 15:20:42 +01:00
Make MessageHandler filter for Filters.update first (#2085)
* Tweak MessageHandlers filters * Improve test
This commit is contained in:
parent
bb34c79909
commit
49c0c9e4d1
2 changed files with 21 additions and 4 deletions
|
@ -126,9 +126,8 @@ class MessageHandler(Handler):
|
|||
if message_updates is False and channel_post_updates is False and edited_updates is False:
|
||||
raise ValueError(
|
||||
'message_updates, channel_post_updates and edited_updates are all False')
|
||||
self.filters = filters
|
||||
if self.filters is not None:
|
||||
self.filters &= Filters.update
|
||||
if filters is not None:
|
||||
self.filters = Filters.update & filters
|
||||
else:
|
||||
self.filters = Filters.update
|
||||
if message_updates is not None:
|
||||
|
|
|
@ -24,7 +24,7 @@ from telegram.utils.deprecate import TelegramDeprecationWarning
|
|||
|
||||
from telegram import (Message, Update, Chat, Bot, User, CallbackQuery, InlineQuery,
|
||||
ChosenInlineResult, ShippingQuery, PreCheckoutQuery)
|
||||
from telegram.ext import Filters, MessageHandler, CallbackContext, JobQueue
|
||||
from telegram.ext import Filters, MessageHandler, CallbackContext, JobQueue, BaseFilter
|
||||
|
||||
message = Message(1, User(1, '', False), None, Chat(1, ''), text='Text')
|
||||
|
||||
|
@ -161,6 +161,24 @@ class TestMessageHandler:
|
|||
message.chat.type = 'private'
|
||||
assert not handler.check_update(Update(0, message))
|
||||
|
||||
def test_callback_query_with_filter(self, message):
|
||||
|
||||
class TestFilter(BaseFilter):
|
||||
update_filter = True
|
||||
flag = False
|
||||
|
||||
def filter(self, u):
|
||||
self.flag = True
|
||||
|
||||
test_filter = TestFilter()
|
||||
handler = MessageHandler(test_filter, self.callback_basic)
|
||||
|
||||
update = Update(1, callback_query=CallbackQuery(1, None, None, message=message))
|
||||
|
||||
assert update.effective_message
|
||||
assert not handler.check_update(update)
|
||||
assert not test_filter.flag
|
||||
|
||||
def test_specific_filters(self, message):
|
||||
f = (~Filters.update.messages
|
||||
& ~Filters.update.channel_post
|
||||
|
|
Loading…
Reference in a new issue