diff --git a/core.py b/core.py index 18034b5..5c3e912 100644 --- a/core.py +++ b/core.py @@ -51,7 +51,7 @@ def main(): old_worker = chat_workers.get(update.message.chat.id) # If it exists, gracefully stop the worker if old_worker: - old_worker.stop() + old_worker.stop("request") # Initialize a new worker for the chat new_worker = worker.ChatWorker(bot, update.message.chat) # Start the worker diff --git a/strings.py b/strings.py index d4df8c1..6087071 100644 --- a/strings.py +++ b/strings.py @@ -35,7 +35,10 @@ order_format_string = "di {user}\n" \ # Conversation: the start command was sent and the bot should welcome the user conversation_after_start = "Ciao!\n" \ - "Benvenuto su greed!" + "Benvenuto su greed!\n" \ + "Quella che vedi qui รจ la versione Alpha del software.\n" \ + "Pertanto, funzioni potranno essere aggiunte o rimosse in qualsiasi momento," \ + " e l'interfaccia utente potrebbe risultare incompleta." # Conversation: to send an inline keyboard you need to send a message with it conversation_open_user_menu = "Cosa vorresti fare?\n" \ @@ -91,7 +94,7 @@ menu_order_status = "๐Ÿ› Stato ordini" menu_add_credit = "๐Ÿ’ต Aggiungi fondi" # User menu: bot info -menu_bot_info = "โ„น๏ธ Informazioni sul bot" +menu_bot_info = "โ„น๏ธ Info sul bot" # User menu: cash menu_cash = "๐Ÿ’ต In contanti" @@ -148,7 +151,7 @@ menu_add_to_cart = "โž• Aggiungi" menu_remove_from_cart = "โž– Rimuovi" # Menu: help menu -menu_help = "โ“ Aiuto, assistenza e informazioni" +menu_help = "โ“ Aiuto e assistenza" # Menu: guide menu_guide = "๐Ÿ“– Guida" @@ -215,7 +218,10 @@ payment_cc_amount = "Quanti fondi vuoi aggiungere al tuo portafoglio?" payment_invoice_title = "Aggiunta di fondi" # Payment: add funds invoice description -payment_invoice_description = "Pagando questa ricevuta verranno aggiunti {amount} al portafoglio." +payment_invoice_description = "Pagando questa ricevuta verranno aggiunti {amount} al portafoglio.\n\n" \ + "Visto che sei nella versione Alpha del software, puoi effettuare pagamenti con la " \ + "carta di credito di prova `4242 4242 4242 4242`, con qualsiasi CVV e una data di " \ + "scadenza valida." # Payment: label of the labeled price on the invoice payment_invoice_label = "Ricarica" diff --git a/worker.py b/worker.py index 8d02150..6344fad 100644 --- a/worker.py +++ b/worker.py @@ -109,11 +109,11 @@ class ChatWorker(threading.Thread): data = self.queue.get(timeout=int(configloader.config["Telegram"]["conversation_timeout"])) except queuem.Empty: # If the conversation times out, gracefully stop the thread - self.__graceful_stop() + self.__graceful_stop(StopSignal("timeout")) # Check if the data is a stop signal instance if isinstance(data, StopSignal): # Gracefully stop the process - self.__graceful_stop() + self.__graceful_stop(data) # Return the received update return data @@ -490,7 +490,6 @@ class ChatWorker(threading.Thread): def __add_credit_menu(self): """Add more credit to the account.""" - # TODO: a loop might be needed here # Create a payment methods keyboard keyboard = list() # Add the supported payment methods to the keyboard @@ -991,10 +990,14 @@ class ChatWorker(threading.Thread): self.bot.send_message(self.chat.id, strings.contact_shopkeeper.format(shopkeepers=shopkeepers_string)) # If the user has selected the Cancel option the function will return immediately - def __graceful_stop(self): + def __graceful_stop(self, stop_trigger: StopSignal): """Handle the graceful stop of the thread.""" - # Notify the user that the session has expired and remove the keyboard - self.bot.send_message(self.chat.id, strings.conversation_expired, reply_markup=telegram.ReplyKeyboardRemove()) + # If the session has expired... + if stop_trigger.reason == "timeout": + # Notify the user that the session has expired and remove the keyboard + self.bot.send_message(self.chat.id, strings.conversation_expired, reply_markup=telegram.ReplyKeyboardRemove()) + # If a restart has been requested... + # Do nothing. # Close the database session # End the process sys.exit(0)