mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 05:54:18 +00:00
Add menu functions
This commit is contained in:
parent
5f04a1ffe9
commit
b4137e7462
2 changed files with 52 additions and 25 deletions
11
strings.py
11
strings.py
|
@ -18,6 +18,9 @@ conversation_after_start = "Ciao!\n" \
|
|||
# Answer: to send an inline keyboard you need to send a message with it
|
||||
conversation_open_user_menu = "Allora, {username}, cosa vorresti fare?"
|
||||
|
||||
# Answer: the same message as above but when the first has already been sent
|
||||
conversation_open_user_menu_multiple = "Hai bisogno di qualcos'altro?"
|
||||
|
||||
# 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."
|
||||
|
@ -33,7 +36,13 @@ menu_order_status = "❓ Stato ordini"
|
|||
menu_add_credit = "💵 Ricarica"
|
||||
|
||||
# User menu: bot info
|
||||
menu_info = "ℹ️ Informazioni sul bot"
|
||||
menu_bot_info = "ℹ️ Informazioni sul bot"
|
||||
|
||||
# Info: informazioni sul bot
|
||||
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \
|
||||
' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \
|
||||
' <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'
|
||||
|
||||
# Error: message received not in a private chat
|
||||
error_nonprivate_chat = "⚠️ Questo bot funziona solo in chat private."
|
||||
|
|
66
worker.py
66
worker.py
|
@ -95,31 +95,49 @@ class ChatWorker(threading.Thread):
|
|||
def __user_menu(self):
|
||||
"""Function called from the run method when the user is not an administrator.
|
||||
Normal bot actions should be placed here."""
|
||||
# Create a keyboard with the user main menu
|
||||
keyboard = [[telegram.KeyboardButton(strings.menu_order)],
|
||||
[telegram.KeyboardButton(strings.menu_order_status)],
|
||||
[telegram.KeyboardButton(strings.menu_add_credit)],
|
||||
[telegram.KeyboardButton(strings.menu_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(username=str(self.user)),
|
||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
||||
# Wait for a reply from the user
|
||||
# TODO: change this
|
||||
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
|
||||
strings.menu_add_credit, strings.menu_info])
|
||||
# If the user has selected the Order option...
|
||||
if selection == strings.menu_order:
|
||||
...
|
||||
# If the user has selected the Order Status option...
|
||||
elif selection == strings.menu_order_status:
|
||||
...
|
||||
# If the user has selected the Add Credit option...
|
||||
elif selection == strings.menu_add_credit:
|
||||
...
|
||||
# If the user has selected the Bot Info option...
|
||||
elif selection == strings.menu_info:
|
||||
...
|
||||
# Loop used to returning to the menu after executing a command
|
||||
while True:
|
||||
# Create a keyboard with the user main menu
|
||||
keyboard = [[telegram.KeyboardButton(strings.menu_order)],
|
||||
[telegram.KeyboardButton(strings.menu_order_status)],
|
||||
[telegram.KeyboardButton(strings.menu_add_credit)],
|
||||
[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(username=str(self.user)),
|
||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
||||
# Wait for a reply from the user
|
||||
# TODO: change this
|
||||
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
|
||||
strings.menu_add_credit, strings.menu_bot_info])
|
||||
# If the user has selected the Order option...
|
||||
if selection == strings.menu_order:
|
||||
# Open the order menu
|
||||
self.__order_menu()
|
||||
# If the user has selected the Order Status option...
|
||||
elif selection == strings.menu_order_status:
|
||||
# Display the order(s) status
|
||||
self.__order_status()
|
||||
# If the user has selected the Add Credit option...
|
||||
elif selection == strings.menu_add_credit:
|
||||
# Display the add credit menu
|
||||
self.__add_credit_menu()
|
||||
# If the user has selected the Bot Info option...
|
||||
elif selection == strings.menu_bot_info:
|
||||
# Display information about the bot
|
||||
self.__bot_info()
|
||||
|
||||
def __order_menu(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __order_status(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __add_credit_menu(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __bot_info(self):
|
||||
"""Send information about the bot."""
|
||||
self.bot.send_message(self.chat.id, strings.bot_info, parse_mode="HTML")
|
||||
|
||||
def __admin_menu(self):
|
||||
"""Function called from the run method when the user is an administrator.
|
||||
|
|
Loading…
Reference in a new issue