Skip to content

Commit 78afd04

Browse files
committed
_notify_next_handlers drops messages if empty handler list
After calling clear_step_handler(...) code: self.next_step_handlers[chat_id] = [] left the key in next_step_handlers. When a next message arrives, the old handler executes nothing (no handlers), but still remove message from message queue: new_messages.pop(i). Updated to pop message only when there are real handlers in the list.
1 parent 9c79ba2 commit 78afd04

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎telebot/__init__.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,11 @@ def _notify_next_handlers(self, new_messages):
11551155
chat_id = message.chat.id
11561156
if chat_id in self.next_step_handlers.keys():
11571157
handlers = self.next_step_handlers[chat_id]
1158-
for handler in handlers:
1159-
self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"])
1158+
if (handlers):
1159+
for handler in handlers:
1160+
self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"])
1161+
new_messages.pop(i) # removing message that detects with next_step_handler
11601162
self.next_step_handlers.pop(chat_id, None)
1161-
new_messages.pop(i) # removing message that detects with next_step_handler
11621163
i += 1
11631164

11641165
@staticmethod

0 commit comments

Comments
 (0)