From 49aee14fcaeb2fa17f6e58c7ae9ee3d993bdb8c7 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 19 May 2018 00:42:06 +0300 Subject: [PATCH 01/23] Make _test_filter method static and a bit clear doc strings --- telebot/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 8f9b60b..511cb73 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -984,7 +984,6 @@ class TeleBot: def get_sticker_set(self, name): """ Use this method to get a sticker set. On success, a StickerSet object is returned. - :param token: :param name: :return: """ @@ -1135,7 +1134,7 @@ class TeleBot: """ Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id(). - :param message_id: The message for which we want to clear reply handlers + :param message: The message for which we want to clear reply handlers """ message_id = message.message_id self.clear_reply_handlers_by_message_id(message_id) @@ -1328,7 +1327,8 @@ class TeleBot: return True - def _test_filter(self, filter, filter_value, message): + @staticmethod + def _test_filter(filter, filter_value, message): test_cases = { 'content_types': lambda msg: msg.content_type in filter_value, 'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text, re.IGNORECASE), From e99fb8f84ffc5e0af98819b89b517f7f55336e1d Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 20 May 2018 23:40:25 +0300 Subject: [PATCH 02/23] Add methods to save (reply|next step) handlers [WIP] --- telebot/__init__.py | 85 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index 8f9b60b..9b33dbc 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -7,6 +7,9 @@ import re import sys import six +import os +import json + import logging logger = logging.getLogger('TeleBot') @@ -85,6 +88,16 @@ class TeleBot: # key: chat_id, value: handler list self.next_step_handlers = {} + self.save_reply_handlers = False + self.reply_handlers_save_file = None + self.reply_save_delay = None + self.save_reply_timer = None + + self.save_step_handlers = False + self.step_handlers_save_file = None + self.step_save_delay = None + self.save_step_timer = None + self.message_handlers = [] self.edited_message_handlers = [] self.channel_post_handlers = [] @@ -99,6 +112,67 @@ class TeleBot: if self.threaded: self.worker_pool = util.ThreadPool(num_threads=num_threads) + @staticmethod + def dump_handlers(handlers, filename="./handler-saves/step.save", file_mode="w"): + dirs = filename.rsplit('/', maxsplit=1)[0] + os.makedirs(dirs, exist_ok=True) + with open(filename + ".tmp", file_mode) as file: + for mid, handler in handlers.items(): + name = handler['callback'].__name__ + module = handler['callback'].__module__ + + tmp = {str(mid): {"callback": {"module": module, "name": name}, "args": handler["args"], + "kwargs": handler["kwargs"]}} + + json.dump(tmp, file) + + if os.path.isfile(filename): + os.remove(filename) + + os.rename(filename + ".tmp", filename) + + def save_next_step_handlers(self): + self.dump_handlers(self.next_step_handlers, self.step_handlers_save_file) + + def save_reply_handlers_method(self): + self.dump_handlers(self.next_step_handlers, self.step_handlers_save_file) + + def start_save_next_step_timer(self): + if self.save_step_timer.is_alive(): return + + self.save_step_timer.start() + + def start_save_reply_timer(self): + if self.save_reply_timer.is_alive(): return + + self.save_reply_timer.start() + + def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): + self.save_step_handlers = True + self.step_handlers_save_file = filename + self.step_save_delay = delay + self.save_step_timer = threading.Timer(self.step_save_delay, self.save_next_step_handlers) + + def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): + self.save_reply_handlers = True + self.reply_handlers_save_file = filename + self.reply_save_delay = delay + self.save_reply_timer = threading.Timer(self.reply_save_delay, self.save_reply_handlers_method) + + @staticmethod + def load_handlers(filename): + if os.path.isfile(filename) and os.path.getsize(filename) > 0: + with open(filename, "r") as file: + handlers = json.load(file) + + return handlers + + def load_next_step_handlers(self, filename="./handler-saves/step.save"): + self.next_step_handlers.update(self.load_handlers(filename)) + + def load_reply_handlers(self, filename="./handler-saves/reply.save"): + self.reply_handlers.update(self.load_handlers(filename)) + def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates) @@ -1078,6 +1152,8 @@ class TeleBot: else: self.reply_handlers[message_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] + self.start_save_reply_timer() + def _notify_reply_handlers(self, new_messages): for message in new_messages: if hasattr(message, "reply_to_message") and message.reply_to_message is not None: @@ -1087,6 +1163,7 @@ class TeleBot: for handler in handlers: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.reply_handlers.pop(reply_msg_id) + self.start_save_reply_timer() def register_next_step_handler(self, message, callback, *args, **kwargs): """ @@ -1114,6 +1191,8 @@ class TeleBot: else: self.next_step_handlers[chat_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] + self.start_save_next_step_timer() + def clear_step_handler(self, message): """ Clears all callback functions registered by register_next_step_handler(). @@ -1131,6 +1210,8 @@ class TeleBot: """ self.next_step_handlers[chat_id] = [] + self.start_save_next_step_timer() + def clear_reply_handlers(self, message): """ Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id(). @@ -1148,6 +1229,8 @@ class TeleBot: """ self.reply_handlers[message_id] = [] + self.start_save_next_step_timer() + def _notify_next_handlers(self, new_messages): i = 0 while i < len(new_messages): @@ -1161,6 +1244,8 @@ class TeleBot: new_messages.pop(i) # removing message that detects with next_step_handler i += 1 + self.start_save_next_step_timer() + @staticmethod def _build_handler_dict(handler, **filters): return { From ed7e33b4c65a6a0d73edb56861cd7b742aae289d Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 02:48:46 +0300 Subject: [PATCH 03/23] Fix loadings funcs --- telebot/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 9b33dbc..a877b69 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -113,7 +113,7 @@ class TeleBot: self.worker_pool = util.ThreadPool(num_threads=num_threads) @staticmethod - def dump_handlers(handlers, filename="./handler-saves/step.save", file_mode="w"): + def dump_handlers(handlers, filename, file_mode="w"): dirs = filename.rsplit('/', maxsplit=1)[0] os.makedirs(dirs, exist_ok=True) with open(filename + ".tmp", file_mode) as file: @@ -165,6 +165,12 @@ class TeleBot: with open(filename, "r") as file: handlers = json.load(file) + for handler in handlers: + name = handler["callback"]["name"] + module = handler["callback"]["module"] + + handler = getattr(sys.modules[module], name) + return handlers def load_next_step_handlers(self, filename="./handler-saves/step.save"): From 00c8dcc19b966d842a4e6437e7460832820492ac Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 03:10:40 +0300 Subject: [PATCH 04/23] Add async methods --- telebot/__init__.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index a877b69..541a844 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1441,6 +1441,48 @@ class AsyncTeleBot(TeleBot): def __init__(self, *args, **kwargs): TeleBot.__init__(self, *args, **kwargs) + @staticmethod + @util.async() + def dump_handlers(handlers, filename, file_mode="w"): + return TeleBot.dump_handlers(handlers, filename, file_mode) + + @util.async() + def save_next_step_handlers(self): + return TeleBot.save_next_step_handlers(self) + + @util.async() + def save_reply_handlers_method(self): + return TeleBot.save_reply_handlers_method(self) + + @util.async() + def start_save_next_step_timer(self): + return TeleBot.start_save_next_step_timer(self) + + @util.async() + def start_save_reply_timer(self): + return TeleBot.start_save_reply_timer(self) + + @util.async() + def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): + return TeleBot.enable_save_next_step_handlers(self, delay, filename) + + @util.async() + def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): + return TeleBot.enable_save_reply_handlers(self, delay, filename) + + @staticmethod + @util.async() + def load_handlers(filename): + return TeleBot.load_handlers(filename) + + @util.async() + def load_next_step_handlers(self, filename="./handler-saves/step.save"): + return TeleBot.load_next_step_handlers(self, filename) + + @util.async() + def load_reply_handlers(self, filename="./handler-saves/reply.save"): + return TeleBot.load_reply_handlers(self, filename) + @util.async() def get_me(self): return TeleBot.get_me(self) From b1d5cb2129d8b44838ab8ce3984e6320b71157ad Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 08:56:31 +0300 Subject: [PATCH 05/23] Rewrite. Add class 'Saver' that provides methods for saving (next step|reply) handlers. Add methods enable_save_next_step_handlers, enable_save_reply_handlers, disable_save_next_step_handlers, disable_save_reply_handlers, load_next_step_handlers, load_reply_handlers to Telebot and AsyncTelebot. update telebot/__init__.py --- telebot/__init__.py | 196 ++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 96 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 541a844..73ab328 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -30,6 +30,84 @@ Module : telebot """ +class Saver: + def __init__(self, handlers, filename, delay): + self.handlers = handlers + self.filename = filename + self.delay = delay + self.timer = threading.Timer(delay, self.save_handlers) + + def start_save_timer(self): + if not self.timer.is_alive(): + self.timer = threading.Timer(self.delay, self.save_handlers) + self.timer.start() + + def save_handlers(self): + self.dump_handlers(self.handlers, self.filename) + + def load_handlers(self, filename): + tmp = self.return_load_handlers(filename) + if tmp is not None: + self.handlers.update(tmp) + + @staticmethod + def dump_handlers(handlers, filename, file_mode="w"): + dirs = filename.rsplit('/', maxsplit=1)[0] + os.makedirs(dirs, exist_ok=True) + to_dump = {} + with open(filename + ".tmp", file_mode) as file: + for id_, handlers_ in handlers.items(): + for handler in handlers_: + name = handler['callback'].__name__ + module = handler['callback'].__module__ + + tmp = {"callback": {"module": module, "name": name}, "args": handler["args"], + "kwargs": handler["kwargs"]} + if id_ in to_dump.keys(): + to_dump[id_].append(tmp) + else: + to_dump[id_] = [tmp] + + json.dump(to_dump, file) + + if os.path.isfile(filename): + os.remove(filename) + + os.rename(filename + ".tmp", filename) + + @staticmethod + def return_load_handlers(filename): + if os.path.isfile(filename) and os.path.getsize(filename) > 0: + with open(filename, "r") as file: + handlers = json.load(file) + + result = {} + for id_, handlers_ in handlers.items(): + for handler in handlers_: + name = handler['callback']["name"] + module = handler['callback']["module"] + callback = getattr(sys.modules[module], name) + + tmp = {"callback": callback, "args": handler["args"], "kwargs": handler["kwargs"]} + + if int(id_) in result.keys(): + result[int(id_)].append(tmp) + else: + result[int(id_)] = [tmp] + + a = """ for key, handlers_ in handlers.items(): + for handler in handlers_: + name = handler["callback"]["name"] + module = handler["callback"]["module"] + + callback = getattr(sys.modules["__main__"], "next_") + handler["callback"] = callback""" + + return result + + + + class TeleBot: """ This is TeleBot Class Methods: @@ -88,15 +166,8 @@ class TeleBot: # key: chat_id, value: handler list self.next_step_handlers = {} - self.save_reply_handlers = False - self.reply_handlers_save_file = None - self.reply_save_delay = None - self.save_reply_timer = None - - self.save_step_handlers = False - self.step_handlers_save_file = None - self.step_save_delay = None - self.save_step_timer = None + self.next_step_saver = None + self.reply_saver = None self.message_handlers = [] self.edited_message_handlers = [] @@ -112,72 +183,23 @@ class TeleBot: if self.threaded: self.worker_pool = util.ThreadPool(num_threads=num_threads) - @staticmethod - def dump_handlers(handlers, filename, file_mode="w"): - dirs = filename.rsplit('/', maxsplit=1)[0] - os.makedirs(dirs, exist_ok=True) - with open(filename + ".tmp", file_mode) as file: - for mid, handler in handlers.items(): - name = handler['callback'].__name__ - module = handler['callback'].__module__ - - tmp = {str(mid): {"callback": {"module": module, "name": name}, "args": handler["args"], - "kwargs": handler["kwargs"]}} - - json.dump(tmp, file) - - if os.path.isfile(filename): - os.remove(filename) - - os.rename(filename + ".tmp", filename) - - def save_next_step_handlers(self): - self.dump_handlers(self.next_step_handlers, self.step_handlers_save_file) - - def save_reply_handlers_method(self): - self.dump_handlers(self.next_step_handlers, self.step_handlers_save_file) - - def start_save_next_step_timer(self): - if self.save_step_timer.is_alive(): return - - self.save_step_timer.start() - - def start_save_reply_timer(self): - if self.save_reply_timer.is_alive(): return - - self.save_reply_timer.start() - def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): - self.save_step_handlers = True - self.step_handlers_save_file = filename - self.step_save_delay = delay - self.save_step_timer = threading.Timer(self.step_save_delay, self.save_next_step_handlers) + self.next_step_saver = Saver(self.next_step_handlers, filename, delay) def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): - self.save_reply_handlers = True - self.reply_handlers_save_file = filename - self.reply_save_delay = delay - self.save_reply_timer = threading.Timer(self.reply_save_delay, self.save_reply_handlers_method) + self.reply_saver = Saver(self.reply_handlers, filename, delay) - @staticmethod - def load_handlers(filename): - if os.path.isfile(filename) and os.path.getsize(filename) > 0: - with open(filename, "r") as file: - handlers = json.load(file) + def disable_save_next_step_handlers(self): + self.next_step_saver = None - for handler in handlers: - name = handler["callback"]["name"] - module = handler["callback"]["module"] - - handler = getattr(sys.modules[module], name) - - return handlers + def disable_save_reply_handlers(self): + self.reply_saver = None def load_next_step_handlers(self, filename="./handler-saves/step.save"): - self.next_step_handlers.update(self.load_handlers(filename)) + self.next_step_saver.load_handlers(filename) def load_reply_handlers(self, filename="./handler-saves/reply.save"): - self.reply_handlers.update(self.load_handlers(filename)) + self.reply_saver.load_handlers(filename) def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates) @@ -1158,7 +1180,7 @@ class TeleBot: else: self.reply_handlers[message_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] - self.start_save_reply_timer() + self.reply_saver.start_save_timer() def _notify_reply_handlers(self, new_messages): for message in new_messages: @@ -1169,7 +1191,7 @@ class TeleBot: for handler in handlers: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.reply_handlers.pop(reply_msg_id) - self.start_save_reply_timer() + self.reply_saver.start_save_timer() def register_next_step_handler(self, message, callback, *args, **kwargs): """ @@ -1197,7 +1219,7 @@ class TeleBot: else: self.next_step_handlers[chat_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] - self.start_save_next_step_timer() + self.next_step_saver.start_save_timer() def clear_step_handler(self, message): """ @@ -1216,7 +1238,7 @@ class TeleBot: """ self.next_step_handlers[chat_id] = [] - self.start_save_next_step_timer() + self.next_step_saver.start_save_timer() def clear_reply_handlers(self, message): """ @@ -1235,7 +1257,7 @@ class TeleBot: """ self.reply_handlers[message_id] = [] - self.start_save_next_step_timer() + self.reply_saver.start_save_timer() def _notify_next_handlers(self, new_messages): i = 0 @@ -1250,7 +1272,7 @@ class TeleBot: new_messages.pop(i) # removing message that detects with next_step_handler i += 1 - self.start_save_next_step_timer() + self.next_step_saver.start_save_timer() @staticmethod def _build_handler_dict(handler, **filters): @@ -1441,27 +1463,6 @@ class AsyncTeleBot(TeleBot): def __init__(self, *args, **kwargs): TeleBot.__init__(self, *args, **kwargs) - @staticmethod - @util.async() - def dump_handlers(handlers, filename, file_mode="w"): - return TeleBot.dump_handlers(handlers, filename, file_mode) - - @util.async() - def save_next_step_handlers(self): - return TeleBot.save_next_step_handlers(self) - - @util.async() - def save_reply_handlers_method(self): - return TeleBot.save_reply_handlers_method(self) - - @util.async() - def start_save_next_step_timer(self): - return TeleBot.start_save_next_step_timer(self) - - @util.async() - def start_save_reply_timer(self): - return TeleBot.start_save_reply_timer(self) - @util.async() def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): return TeleBot.enable_save_next_step_handlers(self, delay, filename) @@ -1470,10 +1471,13 @@ class AsyncTeleBot(TeleBot): def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): return TeleBot.enable_save_reply_handlers(self, delay, filename) - @staticmethod @util.async() - def load_handlers(filename): - return TeleBot.load_handlers(filename) + def disable_save_next_step_handlers(self): + return TeleBot.disable_save_next_step_handlers(self) + + @util.async() + def disable_save_reply_handlers(self): + return TeleBot.enable_save_reply_handlers(self) @util.async() def load_next_step_handlers(self, filename="./handler-saves/step.save"): From 4bcfc34a50f2096d1729711e71c0eba2aabb7734 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 09:07:59 +0300 Subject: [PATCH 06/23] Update _notify_next_handlers and _notify_reply_handlers methods: Now if there wasn't any handler updates, timer willn't start. --- telebot/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 73ab328..f08ebb4 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1191,7 +1191,7 @@ class TeleBot: for handler in handlers: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.reply_handlers.pop(reply_msg_id) - self.reply_saver.start_save_timer() + self.reply_saver.start_save_timer() def register_next_step_handler(self, message, callback, *args, **kwargs): """ @@ -1270,9 +1270,9 @@ class TeleBot: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.next_step_handlers.pop(chat_id, None) new_messages.pop(i) # removing message that detects with next_step_handler + self.next_step_saver.start_save_timer() i += 1 - self.next_step_saver.start_save_timer() @staticmethod def _build_handler_dict(handler, **filters): From 4facc5f7d736e42e52e5bb532e1cbad028205004 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 09:30:10 +0300 Subject: [PATCH 07/23] fix unenabled saving handlers. Updated telebot/__init__.py --- telebot/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f08ebb4..ab87189 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1179,8 +1179,8 @@ class TeleBot: self.reply_handlers[message_id].append({"callback": callback, "args": args, "kwargs": kwargs}) else: self.reply_handlers[message_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] - - self.reply_saver.start_save_timer() + if self.reply_saver is not None: + self.reply_saver.start_save_timer() def _notify_reply_handlers(self, new_messages): for message in new_messages: @@ -1191,7 +1191,8 @@ class TeleBot: for handler in handlers: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.reply_handlers.pop(reply_msg_id) - self.reply_saver.start_save_timer() + if self.reply_saver is not None: + self.reply_saver.start_save_timer() def register_next_step_handler(self, message, callback, *args, **kwargs): """ @@ -1219,7 +1220,8 @@ class TeleBot: else: self.next_step_handlers[chat_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] - self.next_step_saver.start_save_timer() + if self.next_step_saver is not None: + self.next_step_saver.start_save_timer() def clear_step_handler(self, message): """ @@ -1238,7 +1240,8 @@ class TeleBot: """ self.next_step_handlers[chat_id] = [] - self.next_step_saver.start_save_timer() + if self.next_step_saver is not None: + self.next_step_saver.start_save_timer() def clear_reply_handlers(self, message): """ @@ -1257,7 +1260,8 @@ class TeleBot: """ self.reply_handlers[message_id] = [] - self.reply_saver.start_save_timer() + if self.reply_saver is not None: + self.reply_saver.start_save_timer() def _notify_next_handlers(self, new_messages): i = 0 @@ -1270,7 +1274,8 @@ class TeleBot: self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"]) self.next_step_handlers.pop(chat_id, None) new_messages.pop(i) # removing message that detects with next_step_handler - self.next_step_saver.start_save_timer() + if self.next_step_saver is not None: + self.next_step_saver.start_save_timer() i += 1 From 7df6b3d4c98167cbed95bf6cfe2cdff88481dd9f Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 09:35:39 +0300 Subject: [PATCH 08/23] Fix situation where delay <= 0. Update telebot/__init__.py --- telebot/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index ab87189..59ae6ff 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -39,8 +39,11 @@ class Saver: def start_save_timer(self): if not self.timer.is_alive(): - self.timer = threading.Timer(self.delay, self.save_handlers) - self.timer.start() + if self.delay <= 0: + self.save_handlers() + else: + self.timer = threading.Timer(self.delay, self.save_handlers) + self.timer.start() def save_handlers(self): self.dump_handlers(self.handlers, self.filename) From 018e4597a2d6b6e777c19d475b90186fa1bc07f2 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 09:40:29 +0300 Subject: [PATCH 09/23] Add del_file_after_loading param to Saver.return_load_handlers and Saver.load_handlers methods. Update telebot/__init__.py --- telebot/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 59ae6ff..f89c339 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -48,8 +48,8 @@ class Saver: def save_handlers(self): self.dump_handlers(self.handlers, self.filename) - def load_handlers(self, filename): - tmp = self.return_load_handlers(filename) + def load_handlers(self, filename, del_file_after_loading=True): + tmp = self.return_load_handlers(filename, del_file_after_loading=del_file_after_loading) if tmp is not None: self.handlers.update(tmp) @@ -79,7 +79,7 @@ class Saver: os.rename(filename + ".tmp", filename) @staticmethod - def return_load_handlers(filename): + def return_load_handlers(filename, del_file_after_loading=True): if os.path.isfile(filename) and os.path.getsize(filename) > 0: with open(filename, "r") as file: handlers = json.load(file) @@ -105,7 +105,8 @@ class Saver: callback = getattr(sys.modules["__main__"], "next_") handler["callback"] = callback""" - + if del_file_after_loading: + os.remove(filename) return result From 7e5f51e4ab6436c8f989b04ad7d16d5f2e175c77 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 09:44:43 +0300 Subject: [PATCH 10/23] Remove old thing. Update telebot/__init__.py --- telebot/__init__.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f89c339..06bbe30 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -98,13 +98,6 @@ class Saver: else: result[int(id_)] = [tmp] - a = """ for key, handlers_ in handlers.items(): - for handler in handlers_: - name = handler["callback"]["name"] - module = handler["callback"]["module"] - - callback = getattr(sys.modules["__main__"], "next_") - handler["callback"] = callback""" if del_file_after_loading: os.remove(filename) return result From b989b7601b9f53c3ad630072d971a92865cb3831 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 May 2018 20:57:22 +0300 Subject: [PATCH 11/23] Add new class: Handler Change type of (next step|reply) handlers from dict to Handler [WIP] update: telebot/__init__.py --- telebot/__init__.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index ca830e5..f15d8d7 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -30,6 +30,25 @@ Module : telebot """ +class Handler: + def __init__(self, callback: {dict, function}, *args, **kwargs): + if type(callback) == dict: + self.callback = getattr(sys.modules[callback["module"]], callback["name"]) + else: + self.callback = callback + + self.args = args + self.kwargs = kwargs + + def __getitem__(self, item): + return getattr(self, item) + + def copy_to_dump(self): + module_ = self.callback.__module__ + name = self.callback.__name__ + return Handler({"module": module_, "name": name}, *self.args, **self.kwargs) + + class Saver: def __init__(self, handlers, filename, delay): self.handlers = handlers @@ -61,15 +80,10 @@ class Saver: with open(filename + ".tmp", file_mode) as file: for id_, handlers_ in handlers.items(): for handler in handlers_: - name = handler['callback'].__name__ - module = handler['callback'].__module__ - - tmp = {"callback": {"module": module, "name": name}, "args": handler["args"], - "kwargs": handler["kwargs"]} if id_ in to_dump.keys(): - to_dump[id_].append(tmp) + to_dump[id_].append(handler.copy_to_dump()) else: - to_dump[id_] = [tmp] + to_dump[id_] = [handler.copy_to_dump()] json.dump(to_dump, file) @@ -87,11 +101,8 @@ class Saver: result = {} for id_, handlers_ in handlers.items(): for handler in handlers_: - name = handler['callback']["name"] - module = handler['callback']["module"] - callback = getattr(sys.modules[module], name) - tmp = {"callback": callback, "args": handler["args"], "kwargs": handler["kwargs"]} + tmp = Handler(handler['callback'], handler["args"], handler["kwargs"]) if int(id_) in result.keys(): result[int(id_)].append(tmp) @@ -1172,9 +1183,9 @@ class TeleBot: parameter, which will contain the replied message. """ if message_id in self.reply_handlers.keys(): - self.reply_handlers[message_id].append({"callback": callback, "args": args, "kwargs": kwargs}) + self.reply_handlers[message_id].append(Handler(callback, *args, **kwargs)) else: - self.reply_handlers[message_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] + self.reply_handlers[message_id] = [Handler(callback, *args, **kwargs)] if self.reply_saver is not None: self.reply_saver.start_save_timer() @@ -1212,9 +1223,9 @@ class TeleBot: :param kwargs: Args to pass in callback func """ if chat_id in self.next_step_handlers.keys(): - self.next_step_handlers[chat_id].append({"callback": callback, "args": args, "kwargs": kwargs}) + self.next_step_handlers[chat_id].append(Handler(callback, *args, **kwargs)) else: - self.next_step_handlers[chat_id] = [{"callback": callback, "args": args, "kwargs": kwargs}] + self.next_step_handlers[chat_id] = [Handler(callback, *args, **kwargs)] if self.next_step_saver is not None: self.next_step_saver.start_save_timer() From 17971ff48b39f2a4695829bc9c776c0a711d57bc Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 26 May 2018 12:19:01 +0300 Subject: [PATCH 12/23] Move from json to pickle. Update: relebot/__init__.py --- telebot/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f15d8d7..838bbd1 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -9,6 +9,7 @@ import six import os import json +import pickle import logging @@ -31,7 +32,7 @@ Module : telebot class Handler: - def __init__(self, callback: {dict, function}, *args, **kwargs): + def __init__(self, callback: {dict, 'function'}, *args, **kwargs): if type(callback) == dict: self.callback = getattr(sys.modules[callback["module"]], callback["name"]) else: @@ -73,7 +74,7 @@ class Saver: self.handlers.update(tmp) @staticmethod - def dump_handlers(handlers, filename, file_mode="w"): + def dump_handlers(handlers, filename, file_mode="wb"): dirs = filename.rsplit('/', maxsplit=1)[0] os.makedirs(dirs, exist_ok=True) to_dump = {} @@ -85,7 +86,8 @@ class Saver: else: to_dump[id_] = [handler.copy_to_dump()] - json.dump(to_dump, file) + # json.dump(to_dump, file) + pickle.dump(to_dump, file) if os.path.isfile(filename): os.remove(filename) @@ -95,14 +97,14 @@ class Saver: @staticmethod def return_load_handlers(filename, del_file_after_loading=True): if os.path.isfile(filename) and os.path.getsize(filename) > 0: - with open(filename, "r") as file: - handlers = json.load(file) - + with open(filename, "rb") as file: + # handlers = json.load(file) + handlers = pickle.load(file) result = {} for id_, handlers_ in handlers.items(): for handler in handlers_: - tmp = Handler(handler['callback'], handler["args"], handler["kwargs"]) + tmp = Handler(handler['callback'], *handler["args"], **handler["kwargs"]) if int(id_) in result.keys(): result[int(id_)].append(tmp) From 3c890a7846abbd7113f9eef92e8d9e6ecde12a73 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 26 May 2018 16:37:25 +0300 Subject: [PATCH 13/23] Remove 2 spaces up to TeleBot class. Update: telebot/__init__.py --- telebot/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 838bbd1..14cfe3f 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -116,8 +116,6 @@ class Saver: return result - - class TeleBot: """ This is TeleBot Class Methods: From 47e6dfd6bce65d5ee8dbbc6930107cfcc203ca99 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 26 May 2018 16:52:30 +0300 Subject: [PATCH 14/23] Remove rudiment json things Update: telebot/__init__.py --- telebot/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 14cfe3f..2f9d1c9 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -8,7 +8,6 @@ import sys import six import os -import json import pickle import logging @@ -86,7 +85,6 @@ class Saver: else: to_dump[id_] = [handler.copy_to_dump()] - # json.dump(to_dump, file) pickle.dump(to_dump, file) if os.path.isfile(filename): @@ -98,7 +96,6 @@ class Saver: def return_load_handlers(filename, del_file_after_loading=True): if os.path.isfile(filename) and os.path.getsize(filename) > 0: with open(filename, "rb") as file: - # handlers = json.load(file) handlers = pickle.load(file) result = {} for id_, handlers_ in handlers.items(): @@ -106,10 +103,10 @@ class Saver: tmp = Handler(handler['callback'], *handler["args"], **handler["kwargs"]) - if int(id_) in result.keys(): - result[int(id_)].append(tmp) + if id_ in result.keys(): + result[id_].append(tmp) else: - result[int(id_)] = [tmp] + result[id_] = [tmp] if del_file_after_loading: os.remove(filename) From 1de356dcc337751d0ae25a3dbf82aaec401d8a08 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 26 May 2018 17:10:00 +0300 Subject: [PATCH 15/23] Change default save directory to "./.handler-saves/". Add del_file_after_loading param to load methods. Update: telebot/__init__.py --- telebot/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 2f9d1c9..ce3963e 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -188,10 +188,10 @@ class TeleBot: if self.threaded: self.worker_pool = util.ThreadPool(num_threads=num_threads) - def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): + def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save", del_file_after_loading=True): self.next_step_saver = Saver(self.next_step_handlers, filename, delay) - def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): + def enable_save_reply_handlers(self, delay=120, filename="./.handler-saves/reply.save", del_file_after_loading=True): self.reply_saver = Saver(self.reply_handlers, filename, delay) def disable_save_next_step_handlers(self): @@ -200,10 +200,10 @@ class TeleBot: def disable_save_reply_handlers(self): self.reply_saver = None - def load_next_step_handlers(self, filename="./handler-saves/step.save"): + def load_next_step_handlers(self, filename="./.handler-saves/step.save"): self.next_step_saver.load_handlers(filename) - def load_reply_handlers(self, filename="./handler-saves/reply.save"): + def load_reply_handlers(self, filename="./.handler-saves/reply.save"): self.reply_saver.load_handlers(filename) def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): @@ -1474,12 +1474,12 @@ class AsyncTeleBot(TeleBot): TeleBot.__init__(self, *args, **kwargs) @util.async() - def enable_save_next_step_handlers(self, delay=120, filename="./handler-saves/step.save"): - return TeleBot.enable_save_next_step_handlers(self, delay, filename) + def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save", del_file_after_loading=True): + return TeleBot.enable_save_next_step_handlers(self, delay, filename, del_file_after_loading) @util.async() - def enable_save_reply_handlers(self, delay=120, filename="./handler-saves/reply.save"): - return TeleBot.enable_save_reply_handlers(self, delay, filename) + def enable_save_reply_handlers(self, delay=120, filename="./.handler-saves/reply.save", del_file_after_loading=True): + return TeleBot.enable_save_reply_handlers(self, delay, filename, del_file_after_loading) @util.async() def disable_save_next_step_handlers(self): @@ -1490,11 +1490,11 @@ class AsyncTeleBot(TeleBot): return TeleBot.enable_save_reply_handlers(self) @util.async() - def load_next_step_handlers(self, filename="./handler-saves/step.save"): + def load_next_step_handlers(self, filename="./.handler-saves/step.save"): return TeleBot.load_next_step_handlers(self, filename) @util.async() - def load_reply_handlers(self, filename="./handler-saves/reply.save"): + def load_reply_handlers(self, filename="./.handler-saves/reply.save"): return TeleBot.load_reply_handlers(self, filename) @util.async() From 13df7b59081411bd7f9e5ce05ee9357e35e4845c Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 26 May 2018 17:21:39 +0300 Subject: [PATCH 16/23] Add enable_save_next_step_handlers and load_next_step_handlers methods to step_example/ Update: examples/step_example.py --- examples/step_example.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/step_example.py b/examples/step_example.py index fd8d07d..0fc0ef1 100644 --- a/examples/step_example.py +++ b/examples/step_example.py @@ -75,4 +75,14 @@ def process_sex_step(message): bot.reply_to(message, 'oooops') +# Enable saving next step handlers to file "./.handlers-saves/step.save". +# Delay=2 means that after any change in next step handlers (e.g. calling register_next_step_handler()) +# saving will hapen after delay 2 seconds. +bot.enable_save_next_step_handlers(delay=2) + +# Load next_step_handlers from save file (default "./.handlers-saves/step.save") +# WARNING It will work only if enable_save_next_step_handlers was called! +bot.load_next_step_handlers() + + bot.polling() From d61de35a32272e31843d8bad3b3f37dba073907e Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 01:23:20 +0300 Subject: [PATCH 17/23] Remove rudiment json things, again! Update: telebot/__init__.py --- telebot/__init__.py | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index ce3963e..9669d87 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -31,23 +31,17 @@ Module : telebot class Handler: - def __init__(self, callback: {dict, 'function'}, *args, **kwargs): - if type(callback) == dict: - self.callback = getattr(sys.modules[callback["module"]], callback["name"]) - else: - self.callback = callback - + """ + Class for (next step|reply) handlers + """ + def __init__(self, callback: 'function', *args, **kwargs): + self.callback = callback self.args = args self.kwargs = kwargs def __getitem__(self, item): return getattr(self, item) - def copy_to_dump(self): - module_ = self.callback.__module__ - name = self.callback.__name__ - return Handler({"module": module_, "name": name}, *self.args, **self.kwargs) - class Saver: def __init__(self, handlers, filename, delay): @@ -76,16 +70,9 @@ class Saver: def dump_handlers(handlers, filename, file_mode="wb"): dirs = filename.rsplit('/', maxsplit=1)[0] os.makedirs(dirs, exist_ok=True) - to_dump = {} - with open(filename + ".tmp", file_mode) as file: - for id_, handlers_ in handlers.items(): - for handler in handlers_: - if id_ in to_dump.keys(): - to_dump[id_].append(handler.copy_to_dump()) - else: - to_dump[id_] = [handler.copy_to_dump()] - pickle.dump(to_dump, file) + with open(filename + ".tmp", file_mode) as file: + pickle.dump(handlers, file) if os.path.isfile(filename): os.remove(filename) @@ -97,20 +84,11 @@ class Saver: if os.path.isfile(filename) and os.path.getsize(filename) > 0: with open(filename, "rb") as file: handlers = pickle.load(file) - result = {} - for id_, handlers_ in handlers.items(): - for handler in handlers_: - - tmp = Handler(handler['callback'], *handler["args"], **handler["kwargs"]) - - if id_ in result.keys(): - result[id_].append(tmp) - else: - result[id_] = [tmp] if del_file_after_loading: os.remove(filename) - return result + + return handlers class TeleBot: From fa038c2e4286fdeefcc1678de8f26dab9ee32942 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 01:30:14 +0300 Subject: [PATCH 18/23] Move del_file_after_loading param to right methods :face_palm: Update: telebot/__init__.py --- telebot/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 9669d87..c06b977 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -166,10 +166,10 @@ class TeleBot: if self.threaded: self.worker_pool = util.ThreadPool(num_threads=num_threads) - def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save", del_file_after_loading=True): + def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save"): self.next_step_saver = Saver(self.next_step_handlers, filename, delay) - def enable_save_reply_handlers(self, delay=120, filename="./.handler-saves/reply.save", del_file_after_loading=True): + def enable_save_reply_handlers(self, delay=120, filename="./.handler-saves/reply.save"): self.reply_saver = Saver(self.reply_handlers, filename, delay) def disable_save_next_step_handlers(self): @@ -178,10 +178,10 @@ class TeleBot: def disable_save_reply_handlers(self): self.reply_saver = None - def load_next_step_handlers(self, filename="./.handler-saves/step.save"): - self.next_step_saver.load_handlers(filename) + def load_next_step_handlers(self, filename="./.handler-saves/step.save", del_file_after_loading=True): + self.next_step_saver.load_handlers(filename, del_file_after_loading) - def load_reply_handlers(self, filename="./.handler-saves/reply.save"): + def load_reply_handlers(self, filename="./.handler-saves/reply.save", del_file_after_loading=True): self.reply_saver.load_handlers(filename) def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): From 333949683f51018c21bc957a46d144d108cf888f Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 01:37:06 +0300 Subject: [PATCH 19/23] Add doc strings to new TeleBot methods Update telebot/__init__.py --- telebot/__init__.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index c06b977..422ac36 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -44,6 +44,9 @@ class Handler: class Saver: + """ + Class for saving (next step|reply) handlers + """ def __init__(self, handlers, filename, delay): self.handlers = handlers self.filename = filename @@ -167,21 +170,51 @@ class TeleBot: self.worker_pool = util.ThreadPool(num_threads=num_threads) def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save"): + """ + Enable saving next step handlers (by default saving disable) + + :param delay: Delay between changes in handlers and saving + :param filename: Filename of save file + """ self.next_step_saver = Saver(self.next_step_handlers, filename, delay) def enable_save_reply_handlers(self, delay=120, filename="./.handler-saves/reply.save"): + """ + Enable saving reply handlers (by default saving disable) + + :param delay: Delay between changes in handlers and saving + :param filename: Filename of save file + """ self.reply_saver = Saver(self.reply_handlers, filename, delay) def disable_save_next_step_handlers(self): + """ + Disable saving next step handlers (by default saving disable) + """ self.next_step_saver = None def disable_save_reply_handlers(self): + """ + Disable saving next step handlers (by default saving disable) + """ self.reply_saver = None def load_next_step_handlers(self, filename="./.handler-saves/step.save", del_file_after_loading=True): + """ + Load next step handlers from save file + + :param filename: Filename of the file where handlers was saved + :param del_file_after_loading: Is passed True, after loading save file will be deleted + """ self.next_step_saver.load_handlers(filename, del_file_after_loading) def load_reply_handlers(self, filename="./.handler-saves/reply.save", del_file_after_loading=True): + """ + Load reply handlers from save file + + :param filename: Filename of the file where handlers was saved + :param del_file_after_loading: Is passed True, after loading save file will be deleted + """ self.reply_saver.load_handlers(filename) def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): From 424c77fd2c1077c538c1d032b11fbd87b1c8332a Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 16:54:56 +0300 Subject: [PATCH 20/23] Remove type hint for 2.x and PyPy python compatibility --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 422ac36..ca7e92f 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -34,7 +34,7 @@ class Handler: """ Class for (next step|reply) handlers """ - def __init__(self, callback: 'function', *args, **kwargs): + def __init__(self, callback, *args, **kwargs): self.callback = callback self.args = args self.kwargs = kwargs From 909d570dca83baf40e4734db218596ca02341744 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 17:01:07 +0300 Subject: [PATCH 21/23] Add warning about lambda functions in callbacks --- telebot/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index ca7e92f..e52711a 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1172,6 +1172,8 @@ class TeleBot: Warning: `message` must be sent with reply_markup=types.ForceReply(), otherwise TeleBot will not be able to see the difference between a reply to `message` and an ordinary message. + Warning: In case `callback` as lambda function, saving reply handlers will not work. + :param message: The message for which we are awaiting a reply. :param callback: The callback function to be called when a reply arrives. Must accept one `message` parameter, which will contain the replied message. @@ -1186,6 +1188,8 @@ class TeleBot: Warning: `message` must be sent with reply_markup=types.ForceReply(), otherwise TeleBot will not be able to see the difference between a reply to `message` and an ordinary message. + Warning: In case `callback` as lambda function, saving reply handlers will not work. + :param message: The message for which we are awaiting a reply. :param callback: The callback function to be called when a reply arrives. Must accept one `message` parameter, which will contain the replied message. @@ -1213,6 +1217,8 @@ class TeleBot: """ Registers a callback function to be notified when new message arrives after `message`. + Warning: In case `callback` as lambda function, saving next step handlers will not work. + :param message: The message for which we want to handle new message in the same chat. :param callback: The callback function which next new message arrives. :param args: Args to pass in callback func @@ -1225,6 +1231,8 @@ class TeleBot: """ Registers a callback function to be notified when new message arrives after `message`. + Warning: In case `callback` as lambda function, saving next step handlers will not work. + :param chat_id: The chat for which we want to handle new message. :param callback: The callback function which next new message arrives. :param args: Args to pass in callback func From 893d5386c5721e18b310e118ddee87fd81d4d19e Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 17:02:04 +0300 Subject: [PATCH 22/23] Fix register_for_reply_by_message_id doc strings. --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index e52711a..2545f5f 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1190,7 +1190,7 @@ class TeleBot: Warning: In case `callback` as lambda function, saving reply handlers will not work. - :param message: The message for which we are awaiting a reply. + :param message_id: The id of the message for which we are awaiting a reply. :param callback: The callback function to be called when a reply arrives. Must accept one `message` parameter, which will contain the replied message. """ From bc855f7610e777691d5e68bc38badc4324684843 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sun, 27 May 2018 17:05:01 +0300 Subject: [PATCH 23/23] Fix register_for_reply_by_message_id and register_for_reply doc strings. --- telebot/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 2545f5f..4c4996a 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1169,9 +1169,6 @@ class TeleBot: """ Registers a callback function to be notified when a reply to `message` arrives. - Warning: `message` must be sent with reply_markup=types.ForceReply(), otherwise TeleBot will not be able to see - the difference between a reply to `message` and an ordinary message. - Warning: In case `callback` as lambda function, saving reply handlers will not work. :param message: The message for which we are awaiting a reply. @@ -1185,9 +1182,6 @@ class TeleBot: """ Registers a callback function to be notified when a reply to `message` arrives. - Warning: `message` must be sent with reply_markup=types.ForceReply(), otherwise TeleBot will not be able to see - the difference between a reply to `message` and an ordinary message. - Warning: In case `callback` as lambda function, saving reply handlers will not work. :param message_id: The id of the message for which we are awaiting a reply.