mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-03 09:49:21 +01:00
Explicitly check update.effective_chat in ConversationHandler.check_update (#959)
Fixes #927
This commit is contained in:
parent
62e76f1fba
commit
063704c0b9
2 changed files with 23 additions and 5 deletions
|
@ -206,10 +206,11 @@ class ConversationHandler(Handler):
|
|||
|
||||
"""
|
||||
# Ignore messages in channels
|
||||
if (not isinstance(update, Update) or update.channel_post or self.per_chat
|
||||
and (update.inline_query or update.chosen_inline_result) or self.per_message
|
||||
and not update.callback_query or update.callback_query and self.per_chat
|
||||
and not update.callback_query.message):
|
||||
if (not isinstance(update, Update) or
|
||||
update.channel_post or
|
||||
self.per_chat and not update.effective_chat or
|
||||
self.per_message and not update.callback_query or
|
||||
update.callback_query and self.per_chat and not update.callback_query.message):
|
||||
return False
|
||||
|
||||
key = self._get_key(update)
|
||||
|
|
|
@ -20,7 +20,8 @@ from time import sleep
|
|||
|
||||
import pytest
|
||||
|
||||
from telegram import Update, Message, User, Chat, CallbackQuery
|
||||
from telegram import (CallbackQuery, Chat, ChosenInlineResult, InlineQuery, Message,
|
||||
PreCheckoutQuery, ShippingQuery, Update, User)
|
||||
from telegram.ext import (ConversationHandler, CommandHandler, CallbackQueryHandler)
|
||||
|
||||
|
||||
|
@ -277,3 +278,19 @@ class TestConversationHandler(object):
|
|||
message = Message(0, None, None, Chat(0, Chat.CHANNEL, 'Misses Test'), bot=bot)
|
||||
update = Update(0, message=message)
|
||||
assert not handler.check_update(update)
|
||||
|
||||
def test_all_update_types(self, dp, bot, user1):
|
||||
handler = ConversationHandler(entry_points=[CommandHandler('start', self.start_end)],
|
||||
states={}, fallbacks=[])
|
||||
message = Message(0, user1, None, self.group, text='ignore', bot=bot)
|
||||
callback_query = CallbackQuery(0, user1, None, message=message, data='data', bot=bot)
|
||||
chosen_inline_result = ChosenInlineResult(0, user1, 'query', bot=bot)
|
||||
inline_query = InlineQuery(0, user1, 'query', 0, bot=bot)
|
||||
pre_checkout_query = PreCheckoutQuery(0, user1, 'USD', 100, [], bot=bot)
|
||||
shipping_query = ShippingQuery(0, user1, [], None, bot=bot)
|
||||
assert not handler.check_update(Update(0, callback_query=callback_query))
|
||||
assert not handler.check_update(Update(0, chosen_inline_result=chosen_inline_result))
|
||||
assert not handler.check_update(Update(0, inline_query=inline_query))
|
||||
assert not handler.check_update(Update(0, message=message))
|
||||
assert not handler.check_update(Update(0, pre_checkout_query=pre_checkout_query))
|
||||
assert not handler.check_update(Update(0, shipping_query=shipping_query))
|
||||
|
|
Loading…
Reference in a new issue