diff options
| -rw-r--r-- | taulubot.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/taulubot.py b/taulubot.py index fad1a68..cc52c77 100644 --- a/taulubot.py +++ b/taulubot.py @@ -65,7 +65,6 @@ TOKEN = sys.argv[1] bot = telepot.Bot(TOKEN) logging.warning("Connected with token {}".format(TOKEN)) - last_user_by_chat_id = {} done_list = [] @@ -82,12 +81,19 @@ def handle(msg): if is_taulu_command(msg_text): logging.warning("Taulu command found!") - try: - taulu_id = last_user_by_chat_id[chat_id] - logging.warning("Running taulu for user id {}".format(taulu_id)) - run_taulu(chat_id, taulu_id) - except KeyError: - logging.error("No chat id found in chat dict. Maybe no previous messages in the chat?") + attempt, ATTEMPTS = 0, 3 + while attempt < ATTEMPTS: + try: + taulu_id = last_user_by_chat_id[chat_id] + logging.warning("Running taulu for user id {}".format(taulu_id)) + run_taulu(chat_id, taulu_id) + break + except KeyError: + logging.error("No chat id found in chat dict. Maybe no previous messages in the chat?") + break + except: + logging.error("Error occured during process. Retrying... (attempt {})".format(attempt)) + attempt += 1 last_user_by_chat_id[chat_id] = user_id |
