How to make submenus?

103 views Asked by At

I would like a help to make submenus, from the menu number "1". I tried using the code below but it did not work.

Here is my code:

@signals.message_received.connect
def handle(message):
    # Main menu
    if message.command == "Olá":
        menuPrincipal(message)
    # 1 - Budgeting
    elif message.command == "1":
        orcamentos(message)
    # 2 - Track an order already in progress
    elif message.command == "2":
        pedidoAndamento(message)
    # 3 - Change the date, time or location of the event
    elif message.command == "3":
        alterarPedido(message)
    # 4 - Special Offers
    elif message.command == "4":
        promocoes(message)
    # 5 - Speak to a representative
    elif message.command == "5":
        chamarRepresentante(message)

Below is the orcamentos() function that I would like to put as a submenu:

def orcamentos(message):
    mac.send_message(txtOrcamentos, message.conversation)
        # 1 Party kit
    if message.command == "1":
        partyKit(message)
        # 2 Confectionery cake
    elif message.command == "2":
        confCake(message)
        # 3 Salty pie
    elif message.command == "3":
        saltPie(message)
        # 4 Cupcakes
    elif message.command == "4":
        cupcakes(message)
        # 5 Sweets
    elif message.command == "5":
        sweets(message)
        # 6 Salty
    elif message.command == "6":
        salty(message)
1

There are 1 answers

0
Arnab Biswas On

you can use regex or 'in' keyword, ex : if "1" in message.command: but i will prefer using regex so it will be more specified that what user types is a command or not.

also if you like to compress your files(because i am having like 30+menu in my bot) you will probably like to keep them in seperate file, so you can use this interface file 'yowsup.layers.interface' which contains 'YowInterfaceLayer, ProtocolEntityCallback'.

"^fun$" this regex will detect the word fun and "^wiki (?P[^$]+)$" will detect the word after the keyword wiki so it have far more control over commands.