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

#4: Add help menu

This commit is contained in:
Steffo 2018-04-16 12:09:51 +02:00
parent c46f861de0
commit 9dd9ac9edd
3 changed files with 63 additions and 4 deletions

View file

@ -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!")

View file

@ -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 <a href="https://github.com/Steffo99/greed">gree
' <a href="https://github.com/Steffo99/greed/blob/master/LICENSE">Affero General Public License 3.0</a>.\n' \
'Il codice sorgente di questa versione è disponibile <i>qui</i>.\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!"

View file

@ -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