From 22adafea5978f71ac268f045cd0f27081f98d3c2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 9 Sep 2020 18:24:18 +0200 Subject: [PATCH] Remove access to missing worker.loc --- core.py | 10 +++++++++- strings/en.py | 4 ++++ strings/it.py | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core.py b/core.py index b5a98c4..3aa411f 100644 --- a/core.py +++ b/core.py @@ -154,13 +154,21 @@ def main(): # Otherwise, forward the update to the corresponding worker receiving_worker = chat_workers.get(update.message.chat.id) # Ensure a worker exists for the chat and is alive - if receiving_worker is None or not receiving_worker.is_ready(): + if receiving_worker is None: log.debug(f"Received a message in a chat without worker: {update.message.chat.id}") # Suggest that the user restarts the chat with /start bot.send_message(update.message.chat.id, default_loc.get("error_no_worker_for_chat"), reply_markup=telegram.ReplyKeyboardRemove()) # Skip the update continue + # If the worker is not ready... + if not receiving_worker.is_ready(): + log.debug(f"Received a message in a chat where the worker wasn't ready yet: {update.message.chat.id}") + # Suggest that the user restarts the chat with /start + bot.send_message(update.message.chat.id, default_loc.get("error_worker_not_ready"), + reply_markup=telegram.ReplyKeyboardRemove()) + # Skip the update + continue # If the message contains the "Cancel" string defined in the strings file... if update.message.text == receiving_worker.loc.get("menu_cancel"): log.debug(f"Forwarding CancelSignal to {receiving_worker}") diff --git a/strings/en.py b/strings/en.py index c83b171..da42923 100644 --- a/strings/en.py +++ b/strings/en.py @@ -395,6 +395,10 @@ error_nonprivate_chat = "⚠️ This bot only works in private chats." error_no_worker_for_chat = "⚠️ The conversation with the bot was interrupted.\n" \ "To restart it, send the /start command to the bot." +# Error: a message was sent in a chat, but the worker for that chat is not ready. +error_worker_not_ready = "🕒 The conversation with the bot is currently starting.\n" \ + "Please, wait a few moments before sending more commands!" + # Error: add funds amount over max error_payment_amount_over_max = "⚠️ The maximum amount that can be added in a single transaction is {max_amount}." diff --git a/strings/it.py b/strings/it.py index f8e9869..3e7f604 100644 --- a/strings/it.py +++ b/strings/it.py @@ -397,6 +397,10 @@ error_nonprivate_chat = "⚠️ Questo bot funziona solo in chat private." error_no_worker_for_chat = "⚠️ La conversazione con il bot è interrotta.\n" \ "Per riavviarla, manda il comando /start al bot." +# Error: a message was sent in a chat, but the worker for that chat is not ready. +error_worker_not_ready = "🕒 La conversazione con il bot è in fase di avvio.\n" \ + "Per piacere, attendi un attimo prima di inviare altri comandi!" + # Error: add funds amount over max error_payment_amount_over_max = "⚠️ Il massimo di fondi che possono essere aggiunti in una singola transazione è " \ "{max_amount}."