1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-21 21:44:19 +00:00

Might have fixed something

This commit is contained in:
Steffo 2018-04-16 21:20:02 +02:00
parent 13ca9c5391
commit 5ae466de13
3 changed files with 20 additions and 11 deletions

View file

@ -51,7 +51,7 @@ def main():
old_worker = chat_workers.get(update.message.chat.id) old_worker = chat_workers.get(update.message.chat.id)
# If it exists, gracefully stop the worker # If it exists, gracefully stop the worker
if old_worker: if old_worker:
old_worker.stop() old_worker.stop("request")
# Initialize a new worker for the chat # Initialize a new worker for the chat
new_worker = worker.ChatWorker(bot, update.message.chat) new_worker = worker.ChatWorker(bot, update.message.chat)
# Start the worker # Start the worker

View file

@ -35,7 +35,10 @@ order_format_string = "di {user}\n" \
# Conversation: the start command was sent and the bot should welcome the user # Conversation: the start command was sent and the bot should welcome the user
conversation_after_start = "Ciao!\n" \ 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: to send an inline keyboard you need to send a message with it
conversation_open_user_menu = "Cosa vorresti fare?\n" \ conversation_open_user_menu = "Cosa vorresti fare?\n" \
@ -91,7 +94,7 @@ menu_order_status = "🛍 Stato ordini"
menu_add_credit = "💵 Aggiungi fondi" menu_add_credit = "💵 Aggiungi fondi"
# User menu: bot info # User menu: bot info
menu_bot_info = " Informazioni sul bot" menu_bot_info = " Info sul bot"
# User menu: cash # User menu: cash
menu_cash = "💵 In contanti" menu_cash = "💵 In contanti"
@ -148,7 +151,7 @@ menu_add_to_cart = " Aggiungi"
menu_remove_from_cart = " Rimuovi" menu_remove_from_cart = " Rimuovi"
# Menu: help menu # Menu: help menu
menu_help = "❓ Aiuto, assistenza e informazioni" menu_help = "❓ Aiuto e assistenza"
# Menu: guide # Menu: guide
menu_guide = "📖 Guida" menu_guide = "📖 Guida"
@ -215,7 +218,10 @@ payment_cc_amount = "Quanti fondi vuoi aggiungere al tuo portafoglio?"
payment_invoice_title = "Aggiunta di fondi" payment_invoice_title = "Aggiunta di fondi"
# Payment: add funds invoice description # 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: label of the labeled price on the invoice
payment_invoice_label = "Ricarica" payment_invoice_label = "Ricarica"

View file

@ -109,11 +109,11 @@ class ChatWorker(threading.Thread):
data = self.queue.get(timeout=int(configloader.config["Telegram"]["conversation_timeout"])) data = self.queue.get(timeout=int(configloader.config["Telegram"]["conversation_timeout"]))
except queuem.Empty: except queuem.Empty:
# If the conversation times out, gracefully stop the thread # 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 # Check if the data is a stop signal instance
if isinstance(data, StopSignal): if isinstance(data, StopSignal):
# Gracefully stop the process # Gracefully stop the process
self.__graceful_stop() self.__graceful_stop(data)
# Return the received update # Return the received update
return data return data
@ -490,7 +490,6 @@ class ChatWorker(threading.Thread):
def __add_credit_menu(self): def __add_credit_menu(self):
"""Add more credit to the account.""" """Add more credit to the account."""
# TODO: a loop might be needed here
# Create a payment methods keyboard # Create a payment methods keyboard
keyboard = list() keyboard = list()
# Add the supported payment methods to the keyboard # 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)) 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 # 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.""" """Handle the graceful stop of the thread."""
# Notify the user that the session has expired and remove the keyboard # If the session has expired...
self.bot.send_message(self.chat.id, strings.conversation_expired, reply_markup=telegram.ReplyKeyboardRemove()) 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 # Close the database session
# End the process # End the process
sys.exit(0) sys.exit(0)