X Tutup
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
15 changes: 11 additions & 4 deletions telegram/ext/conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def __init__(self,
if not any((self.per_user, self.per_chat, self.per_message)):
raise ValueError("'per_user', 'per_chat' and 'per_message' can't all be 'False'")

if self.per_message and not self.per_chat:
logging.warning("If 'per_message=True' is used, 'per_chat=True' should also be used, "
"since message IDs are not globally unique.")

all_handlers = list()
all_handlers.extend(entry_points)
all_handlers.extend(fallbacks)
Expand All @@ -132,17 +136,20 @@ def __init__(self,
if self.per_message:
for handler in all_handlers:
if not isinstance(handler, CallbackQueryHandler):
raise ValueError("If 'per_message=True', all entry points and state handlers"
" must be 'CallbackQueryHandler'")
logging.warning("If 'per_message=True', all entry points and state handlers"
" must be 'CallbackQueryHandler', since no other handlers "
"have a message context.")
else:
for handler in all_handlers:
if isinstance(handler, CallbackQueryHandler):
raise ValueError("If 'per_message=False', 'CallbackQueryHandler' doesn't work")
logging.warning("If 'per_message=False', 'CallbackQueryHandler' will not be "
"tracked for every message.")

if self.per_chat:
for handler in all_handlers:
if isinstance(handler, (InlineQueryHandler, ChosenInlineResultHandler)):
raise ValueError("If 'per_chat=True', 'InlineQueryHandler' doesn't work")
logging.warning("If 'per_chat=True', 'InlineQueryHandler' can not be used, "
"since inline queries have no chat context.")

def _get_key(self, update):
chat = update.effective_chat
Expand Down
22 changes: 0 additions & 22 deletions tests/test_conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,6 @@ def two(bot, update):
sleep(.1)
self.assertEquals(handler.conversations[(self.group.id, user.id, message.message_id)], 2)

def test_illegal_handlers(self):
with self.assertRaises(ValueError):
ConversationHandler(
entry_points=[CommandHandler('/test', lambda bot, update: None)],
states={},
fallbacks=[],
per_message=True)

with self.assertRaises(ValueError):
ConversationHandler(
entry_points=[CallbackQueryHandler(lambda bot, update: None)],
states={},
fallbacks=[],
per_message=False)

with self.assertRaises(ValueError):
ConversationHandler(
entry_points=[InlineQueryHandler(lambda bot, update: None)],
states={},
fallbacks=[],
per_chat=True)

def test_endOnFirstMessage(self):
self._setup_updater('', messages=0)
d = self.updater.dispatcher
Expand Down
X Tutup