Func callback it is not overwritten

26 views Asked by At

Callback it is not overwritten in the block def handle_topol Each time the function is called after selecting the mode

callback_data=f'topol_{rezim}_{data[i][j]}

it should create a link to a specific block, for example, to topol_normal_32( which will lead to if function_call.data == 'topol_normal_32': и т.д)

The bottom line is that if you enter the width of the material 1 time, the next time the function is called, the width value will be saved and even if you use the buttons to select a different width, it will still be the one that you selected the first time

@botTimeWeb.callback_query_handler(func=lambda call: True)
def response1(function_call):
    user_name = get_user_name(str(function_call.from_user.id))
    markup = types.InlineKeyboardMarkup()

    def handle_calc(message, thickness, data, poroda):
        initial_humidity_requested = False

        @botTimeWeb.message_handler(func=lambda message: True)
        def handle_calc_inner(message):
            nonlocal initial_humidity_requested
            if not initial_humidity_requested:
                global wDr
                wDr = int(message.text)
                initial_humidity_requested = True
                botTimeWeb.send_message(message.chat.id, "Введите конечную влажность(Транспортная - 20, 12, 8):")
            else:
                wKon = int(message.text)
                df = pd.DataFrame(data, index=["20", "12", "8"], columns=["60", "50", "40"])
                if str(wKon) in df.index and str(wDr) in df.columns:
                    value = df.loc[str(wKon), str(wDr)]
                    final_mess = f"Сушка при значениях:\nМатериал-{poroda}\nТолщина - {thickness}мм\nW(нач.влажность)={wDr}%\nW(кон. влажность)={wKon}%\nБудет примерно равна : {value} час."

                    markup = types.InlineKeyboardMarkup()
                    button_main = types.InlineKeyboardButton(text='Вернуться в главное меню', callback_data='main_menu')
                    button_calc = types.InlineKeyboardButton(text='Вернуться в калькулятор продолжительности сушки',
                                                             callback_data='calc')
                    markup.add(button_calc)
                    markup.add(button_main)

                    botTimeWeb.send_message(message.chat.id, final_mess, parse_mode='html', reply_markup=markup)
                else:
                    final_mess = "Вы ввели недопустимые значения для W(нач.влажность) и/или W(кон.влажность).\nПопробуйте снова ввести значения начальной влажности(60,50,40):"
                    initial_humidity_requested = False

        botTimeWeb.send_message(function_call.message.chat.id, f"Введите начальную влажность (60,50,40):")
        botTimeWeb.answer_callback_query(function_call.id)

        if function_call.data == "main_menu":
            first_mess = f"{user_name},Ты попал в главное меню\nКуда отправимся?"
            button_yes = types.InlineKeyboardButton(text='Справочная информация', callback_data='yes')
            button_no = types.InlineKeyboardButton(text='Связаться со специалистом', callback_data='no')
            button_calc = types.InlineKeyboardButton(text='Калькулятор продолжительности сушки', callback_data='calc')
            markup.row(button_yes, button_no)
            markup.add(button_calc)
            botTimeWeb.send_message(function_call.message.chat.id, first_mess, parse_mode='html', reply_markup=markup)
            botTimeWeb.answer_callback_query(function_call.id)

        if function_call.data == 'calc':
            first_mess = "Вы попали в меню калькулятора продолжительности сушки!\nПодскажите породу,которую собираетесь сушить?"
            button_back = types.InlineKeyboardButton(text='Вернуться в главное меню', callback_data='main_menu')
            button_razdel2 = types.InlineKeyboardButton(text='Вернуться в информационный раздел',
                                                        callback_data='razdel2')
            button_topol = types.InlineKeyboardButton(text='Тополь,Липа,Осина', callback_data='topol')
            button_bereza = types.InlineKeyboardButton(text='Берёза,Ольха', callback_data='bereza')
            button_listve = types.InlineKeyboardButton(text='Лиственица', callback_data='listve')
            button_klen = types.InlineKeyboardButton(text='Клён,Бук', callback_data='klen')
            button_dyb = types.InlineKeyboardButton(text='Дуб', callback_data='dyb')
            button_kedr = types.InlineKeyboardButton(text='Кедр,Пихта,Ель,Сосна', callback_data='kedr')

            markup.row(button_topol, button_bereza)
            markup.row(button_listve, button_klen)
            markup.row(button_dyb, button_kedr)

            markup.row(button_razdel2, button_back)
            # topol bereza listve klen dyb kedr
            botTimeWeb.send_message(function_call.message.chat.id, first_mess, parse_mode='html', reply_markup=markup)
            botTimeWeb.answer_callback_query(function_call.id)

        if function_call.data == 'topol':
            topol_mess = 'Выберbте режим сушки:'
            button_topol_normal = types.InlineKeyboardButton(text='Нормальный Режим', callback_data='topol_normal')
            button_topol_modifi = types.InlineKeyboardButton(text='Модифицированный Режим(приближенный к реальности)',
                                                             callback_data='topol_modifi')
            markup.row(button_topol_normal, button_topol_modifi)
            botTimeWeb.send_message(function_call.message.chat.id, topol_mess, parse_mode='html', reply_markup=markup)


        def handle_topol(function_call, thickness, data, material,rezim):
            topol_mess = f"Выбранный материал - {material}\nВыберите нужную толщину материала"
            markup = types.InlineKeyboardMarkup()
#topol_normal_20
            for i in range(len(data)):
                row_buttons = [
                    types.InlineKeyboardButton(text=f'{data[i][j]} мм', callback_data=f'topol_{rezim}_{data[i][j]}')
                    for j in range(len(data[i]))]
                markup.row(*row_buttons)

            botTimeWeb.send_message(function_call.message.chat.id, topol_mess, parse_mode='html', reply_markup=markup)

        if function_call.data == 'topol_normal':
            handle_topol(function_call, 20, [[20, 25, 32], [40, 44, 50], [60,75]], "Тополь,Липа,Осина",'normal')

        if function_call.data == 'topol_modifi':
            handle_topol(function_call, 20, [[20, 25, 32], [40, 44, 50], [60,75]], "Тополь,Липа,Осина",'modifi')
# ----------------Тополь,Липа,Осина----------------
        if function_call.data == 'topol_normal_20':
            handle_calc(function_call, 20, [[33, 28, 27], [42, 37, 36], [52, 47, 45]], "Тополь,Липа,Осина")

        if function_call.data == 'topol_normal_25':
            handle_calc(function_call, 25, [[46, 39, 36], [57, 51, 47], [70, 64, 60]], "Тополь,Липа,Осина")

        if function_call.data == 'topol_normal_32':
            handle_calc(function_call, 32, [[59, 50, 46], [73, 64, 60], [91, 82, 77]], "Тополь,Липа,Осина")
# ----------------Тополь,Липа,Осина[Модифицированный режим]----------------
        if function_call.data == 'topol_modifi_20':
            handle_calc(function_call, 20, [[1, 1, 1], [1,1,1], [1, 1, 1]], "Тополь,Липа,Осина")

        if function_call.data == 'topol_modifi_25':
            handle_calc(function_call, 25, [[46, 39, 36], [57, 51, 47], [70, 64, 60]], "Тополь,Липа,Осина")

        if function_call.data == 'topol_modifi_32':
            handle_calc(function_call, 32, [[59, 50, 46], [73, 64, 60], [91, 82, 77]], "Тополь,Липа,Осина")

        if function_call.data == 'topol_modifi_40':
            handle_calc(function_call, 40, [[71, 60, 55], [101, 90, 85], [129, 118, 113]], "Тополь,Липа,Осина")

I tried to just shove the def handle_topol function into

if function_call.data == 'topol_normal':

I tried to manually create width buttons, everything is the same

0

There are 0 answers