From 78afd045d81b32bdc5b024e7eb6c8c2645650cd4 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 27 May 2018 23:24:37 +0300 Subject: [PATCH 1/2] _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. --- telebot/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 8f9b60b..2204bfa 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1155,10 +1155,11 @@ class TeleBot: chat_id = message.chat.id if chat_id in self.next_step_handlers.keys(): handlers = self.next_step_handlers[chat_id] - for handler in handlers: - self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) + if (handlers): + for handler in handlers: + self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) + new_messages.pop(i) # removing message that detects with next_step_handler self.next_step_handlers.pop(chat_id, None) - new_messages.pop(i) # removing message that detects with next_step_handler i += 1 @staticmethod From 776a699a8d78d621e8d2dcce9bac7e7041a36307 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Tue, 29 May 2018 18:55:41 +0300 Subject: [PATCH 2/2] _notify_next_handlers skips sequential messages Is there are several sequential messages and next_step_handlers are set, the _notify_next_handlers will process only every even message dew to execute both .pop(i) and i+=1 --- telebot/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 2204bfa..32ed84d 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1153,14 +1153,17 @@ class TeleBot: while i < len(new_messages): message = new_messages[i] chat_id = message.chat.id + was_poped = False if chat_id in self.next_step_handlers.keys(): handlers = self.next_step_handlers[chat_id] if (handlers): for handler in handlers: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) new_messages.pop(i) # removing message that detects with next_step_handler + was_poped = True self.next_step_handlers.pop(chat_id, None) - i += 1 + if (not was_poped): + i += 1 @staticmethod def _build_handler_dict(handler, **filters):