D
D
Daniel2020-02-21 15:06:47
Python
Daniel, 2020-02-21 15:06:47

How to make a layered menu from inline buttons in PyTelegramBotApi?

Hello. I ran into a problem while developing the bot. The matter is that I do not know how it is possible to interact with callback.data from two different menus.
I have one with font selection markup, and with action selection. After receiving data from the keyboards, they need to be applied once. How can this be done?keyboard('cypher')keyboard('action')

@bot.message_handler(content_types=['text'])
def aaa(message):
    mtext = message.text
    chatid = message.chat.id
    global user
    user = User(chatid, mtext)
    bot.send_message(chatid, mtext, reply_markup=keyboard('cypher'))

@bot.callback_query_handler(func=lambda call: True)
def callback(call):
    cypher = Cypher()
    if call.data in ('caesar', 'affine', 'base64', 'atbash'):
        cypher.set_cypher(call.data)
        print("set cypher " + cypher.get_cypher())
    else:
        cypher.set_action(call.data)
        print("set action " + cypher.get_action())

    try:
        bot.edit_message_reply_markup(user.chatid, call.message.message_id, reply_markup=keyboard('action'))
        print('changed')
    except:
        pass

    try:
        if cypher.get_cypher() == 'base64':
            text = base64.encrypt(user.mtext) if cypher.get_action() == 'encode' else base64.decrypt(user.mtext)
        elif cypher.get_cypher() == 'atbash' and (cypher.get_action() == 'encode' or cypher.get_action() == 'decode'):
            text = atbash.do_atbash(user.mtext)
        bot.edit_message_text(chat_id=user.chatid, message_id=call.message.message_id, text=text)
    except:
        pass


As you can see, I'm trying to use classes, but the problems have become even more.
Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question