A
A
antihrust2020-02-09 19:06:40
Python
antihrust, 2020-02-09 19:06:40

Is it possible to change the callback?

@bot.callback_query_handler(lambda call: call.data == 'osh')
def callback_inline(call):
    
    if call.data == 'osh':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите регион:',
                              reply_markup=markups.osh())
    if call.data == 'msk':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите регион:',
                              reply_markup=markups.msk())
        
    if call.data == 'moblast':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите год:',
                              reply_markup=markups.moblast())
    if call.data == 'god1':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите этап:',
                              reply_markup=markups.god1())

    if call.data == 'nap1':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите предмет:',
                              reply_markup=markups.nap1())


I decided to split my multi-line bot into separate files, and ran into a callback problem. I would like to understand if it is possible to include the call catcher @bot.callback_query_handler(func=lambda call: True) in two files? In practice, I found out that no, but this is inaccurate. The code consists of more than 1000 lines of the same type of inlines, which were previously combined by one catcher. Is it possible not to put instead of if @bot.callback_query_handler(lambda call: call.data == 'osh') ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-02-09
@bacon

The problem is that all "bot writers" do not regret learning the basics. All your ifs are formatted, for example, in a dictionary and replaced with one line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question