diff --git a/database.py b/database.py index e0ee891..e0a031f 100644 --- a/database.py +++ b/database.py @@ -206,6 +206,8 @@ class Admin(TableDeclarativeBase): edit_products = Column(Boolean, default=True) receive_orders = Column(Boolean, default=True) create_transactions = Column(Boolean, default=True) + display_on_help = Column(Boolean, default=False) + is_owner = Column(Boolean, default=False) # Live mode enabled live_mode = Column(Boolean, default=False) @@ -290,4 +292,6 @@ class OrderItem(TableDeclarativeBase): # If this script is ran as main, try to create all the tables in the database if __name__ == "__main__": + print("Creating tables...") TableDeclarativeBase.metadata.create_all() + print("Done!") diff --git a/strings.py b/strings.py index a97a02a..d4df8c1 100644 --- a/strings.py +++ b/strings.py @@ -74,15 +74,18 @@ conversation_confirm_cart = "Il tuo carrello contiene questi prodotti:\n" \ conversation_live_orders_start = "Hai avviato la modalitΓ  Ordini Live!\n" \ "Per interrompere il flusso di ordini, manda un qualsiasi messaggio in chat." +# Conversation: help menu has been opened +conversation_open_help_menu = "Che tipo di assistenza desideri ricevere?" + # Notification: the conversation has expired conversation_expired = "πŸ• Il bot non ha ricevuto messaggi per un po' di tempo, quindi ha chiuso la conversazione.\n" \ "Per riavviarne una nuova, invia il comando /start." # User menu: order -menu_order = "πŸ› Ordina" +menu_order = "πŸ›’ Ordina" # User menu: order status -menu_order_status = "❓ Stato ordini" +menu_order_status = "πŸ› Stato ordini" # User menu: add credit menu_add_credit = "πŸ’΅ Aggiungi fondi" @@ -144,6 +147,15 @@ menu_add_to_cart = "βž• Aggiungi" # Menu: remove from cart menu_remove_from_cart = "βž– Rimuovi" +# Menu: help menu +menu_help = "❓ Aiuto, assistenza e informazioni" + +# Menu: guide +menu_guide = "πŸ“– Guida" + +# Menu: contact the shopkeeper +menu_contact_shopkeeper = "πŸ‘¨β€πŸ’Ό Contatta il negozio" + # Emoji: unprocessed order emoji_not_processed = "*️⃣" @@ -237,6 +249,15 @@ bot_info = 'Questo bot utilizza gree ' Affero General Public License 3.0.\n' \ 'Il codice sorgente di questa versione Γ¨ disponibile qui.\n' +# Help: guide +help_msg = "La guida del bot non Γ¨ ancora disponibile.\n" \ + "Riprova piΓΉ avanti!" + +# Help: contact shopkeeper +contact_shopkeeper = "Attualmente, il personale disponibile ad offrire assistenza agli utenti Γ¨ composto da:\n" \ + "{shopkeepers}\n" \ + "Tocca sul nome di uno di loro per contattarli in una chat di Telegram." + # Success: product has been added/edited to the database success_product_edited = "βœ… Il prodotto Γ¨ stato aggiunto/modificato con successo!" diff --git a/worker.py b/worker.py index ec7bfe7..628a53d 100644 --- a/worker.py +++ b/worker.py @@ -243,7 +243,7 @@ class ChatWorker(threading.Thread): keyboard = [[telegram.KeyboardButton(strings.menu_order)], [telegram.KeyboardButton(strings.menu_order_status)], [telegram.KeyboardButton(strings.menu_add_credit)], - [telegram.KeyboardButton(strings.menu_bot_info)]] + [telegram.KeyboardButton(strings.menu_help), telegram.KeyboardButton(strings.menu_bot_info)]] # Send the previously created keyboard to the user (ensuring it can be clicked only 1 time) self.bot.send_message(self.chat.id, strings.conversation_open_user_menu.format(credit=utils.Price(self.user.credit)), @@ -251,7 +251,8 @@ class ChatWorker(threading.Thread): parse_mode="HTML") # Wait for a reply from the user selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status, - strings.menu_add_credit, strings.menu_bot_info]) + strings.menu_add_credit, strings.menu_bot_info, + strings.menu_help]) # If the user has selected the Order option... if selection == strings.menu_order: # Open the order menu @@ -268,6 +269,10 @@ class ChatWorker(threading.Thread): elif selection == strings.menu_bot_info: # Display information about the bot self.__bot_info() + # If the user has selected the Help option... + elif selection == strings.menu_help: + # Go to the Help menu + self.__help_menu() def __order_menu(self): """User menu to order products from the shop.""" @@ -953,6 +958,35 @@ class ChatWorker(threading.Thread): # Notify the admin of the success self.bot.send_message(self.chat.id, strings.success_transaction_created) + def __help_menu(self): + """Help menu. Allows the user to ask for assistance, get a guide or see some info about the bot.""" + # Create a keyboard with the user help menu + keyboard = [[telegram.KeyboardButton(strings.menu_guide)], + [telegram.KeyboardButton(strings.menu_contact_shopkeeper)], + [telegram.KeyboardButton(strings.menu_bot_info)], + [telegram.KeyboardButton(strings.menu_cancel)]] + # Send the previously created keyboard to the user (ensuring it can be clicked only 1 time) + self.bot.send_message(self.chat.id, + strings.conversation_open_help_menu, + reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True), + parse_mode="HTML") + # Wait for a reply from the user + selection = self.__wait_for_specific_message([strings.menu_guide, strings.menu_contact_shopkeeper, + strings.menu_cancel]) + # If the user has selected the Guide option... + if selection == strings.menu_guide: + # Send them the bot guide + self.bot.send_message(self.chat.id, strings.help_msg) + # If the user has selected the Order Status option... + elif selection == strings.menu_contact_shopkeeper: + # Find the list of available shopkeepers + shopkeepers = self.session.query(db.Admin).filter_by(display_on_help=True).join(db.User).all() + # Create the string + shopkeepers_string = "\n".join([admin.user.mention() for admin in shopkeepers]) + # Send the message to the user + 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 immediatly + def __graceful_stop(self): """Handle the graceful stop of the thread.""" # Notify the user that the session has expired and remove the keyboard