@White_Bambie

Как продолжить работу бота?

Не вызывается функция SC_solvent, что не так?
Код
bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=['start'])

def new_patient(message):
    keyboardmain = types.InlineKeyboardMarkup(row_width=2)
    yes_btn = types.InlineKeyboardButton(text="ДА", callback_data="yes")
    no_btn = types.InlineKeyboardButton(text="НЕТ", callback_data="no")
    keyboardmain.add(yes_btn, no_btn)
    bot.send_message(message.chat.id, "Создать нового пациента?", reply_markup=keyboardmain)

@bot.callback_query_handler(func=lambda call:True)
def full_calc(call):
    if call.data == "yes":
        markup_sex = types.ReplyKeyboardMarkup(resize_keyboard=True)
        male_btn = types.KeyboardButton('Мужской')
        female_btn = types.KeyboardButton('Женский')

        markup_sex.add(male_btn, female_btn)
        bot.send_message(call.message.chat.id, 'Выберите пол пациента', reply_markup=markup_sex)
    elif call.data == "no":
        pass

@bot.message_handler(content_types=['text'])
def start_sex(message):
    global sex

    if message.text == 'Мужской':
        keyboard = types.ReplyKeyboardRemove()
        bot.send_message(message.chat.id, 'Пол пациента: мужской', reply_markup=keyboard)
        sex = 0
        start_age(message)
    elif message.text == 'Женский':     
        keyboard = types.ReplyKeyboardRemove()
        bot.send_message(message.chat.id, 'Пол пациента: женский', reply_markup=keyboard)
        sex = 1
        start_age(message)

def start_age(message):
    global age

    age = bot.send_message(message.chat.id, 'Укажите возраст пациента (лет)')
    bot.register_next_step_handler(age, save_weight)

def save_weight(message):    
    global age
    global weight
    age = float(message.text)

    weight = bot.send_message(message.chat.id, 'Укажите вес пациента (кг)')
    bot.register_next_step_handler(weight, save_growth)     

def save_growth(message):    
    global age
    global weight
    global growth
    weight = float(message.text)

    growth = bot.send_message(message.chat.id, 'Укажите рост пациента (см)')
    bot.register_next_step_handler(growth, calc_IMT)

def calc_IMT(message):  # Расчет ИМТ
    global sex
    global age
    global weight
    global growth
    growth = float(message.text)

    # Перевод роста в метр
    meter = round(growth / 100, 2)

    # Перевод роста в метр в квадрате
    quadro = pow(meter, 2)

    # Перевод роста в метр в кубе
    cube = pow(meter, 3)

    # Расчет Индекса массы тела
    IMT = round(weight / quadro, 2)

    if IMT <= 16:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Выраженный дефицит массы тела')
    elif IMT >= 16 and IMT <= 18.5:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Дефицит массы тела')
    elif IMT >= 18.5 and IMT <= 24.99:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Норма')
    elif IMT >= 25 and IMT <= 30:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Избыточная масса тела')
    elif IMT >= 30 and IMT <= 35:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Ожирение')
    elif IMT >= 35 and IMT <= 40:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Ожирение резкое')
    elif IMT >= 40:
        bot.send_message(message.chat.id, f'Индекс массы тела: {IMT} кг/м2: Очень резкое ожирение')
    else:
        bot.send_message(message.chat.id, 'Что-то пошло не так')   

    # Расчет физиологической потребности жидкости в сутки
    FP = round(weight * 35, 1)
    bot.send_message(message.chat.id, f'Физиологическая потребность жидкости в сутки: {FP} мл.')

    # Расчет объема циркулирующей крови
    if sex == 0:
        OCK = round(0.417 * cube + 0.045 * weight - 0.03, 1)
        bot.send_message(message.chat.id, f'Объем циркулирующей крови: {OCK} л.')
        # Расчет объема кровопотери
        Vol20 = round(((OCK * 20) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 20% ОЦК: {Vol20} мл.')
        Vol25 = round(((OCK * 25) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 25% ОЦК: {Vol25} мл.')
        Vol30 = round(((OCK * 30) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 30% ОЦК: {Vol30} мл.')    
    elif sex == 1:
        OCK = round(0.414 * cube + 0.0328 * weight - 0.03, 1)
        bot.send_message(message.chat.id, f'Объем циркулирующей крови: {OCK} л.')
        # Расчет объема кровопотери
        Vol20 = round(((OCK * 20) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 20% ОЦК: {Vol20} мл.')
        Vol25 = round(((OCK * 25) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 25% ОЦК: {Vol25} мл.')
        Vol30 = round(((OCK * 30) / 100) * 1000, 1)
        bot.send_message(message.chat.id, f'Кровопотеря 30% ОЦК: {Vol30} мл.')

    # Открытие меню 
    menu_msg(message)   

def menu_msg(message):
    keyboard_menu = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
    speed_btn = types.KeyboardButton('Скорость введения препаратов')
    food_btn = types.KeyboardButton('Расчет энтерального питания')
    infusio_btn = types.KeyboardButton('Расчет ИТТ')
    k_btn = types.KeyboardButton('Расчет калия')
    na_btn = types.KeyboardButton('Расчет натрия')
    abt_btn = types.KeyboardButton('Расчет АБТ')
    tlt_btn = types.KeyboardButton('Расчет ТЛТ')
    ivl_btn = types.KeyboardButton('Расчет параметров ИВЛ')
    tva_btn = types.KeyboardButton('Расчет ТВА')
    keyboard_menu.add(speed_btn, food_btn, infusio_btn, k_btn, na_btn, abt_btn, tlt_btn, ivl_btn, tva_btn)
    bot.send_message(message.chat.id, 'Выберите калькулятор', reply_markup=keyboard_menu)
    bot.register_next_step_handler(message, choice_calc)

# Выбор калькулятора
def choice_calc(message):
    if message.text == 'Скорость введения препаратов':
        keyboard_speed = types.ReplyKeyboardMarkup(resize_keyboard=True)
        start_btn = types.KeyboardButton('Начать')
        info_btn = types.KeyboardButton('Информация')
        back_btn = types.KeyboardButton('Назад')
        keyboard_speed.add(start_btn, info_btn, back_btn)
        bot.send_message(message.chat.id, 'Расчет скорости введения препаратов', reply_markup=keyboard_speed)
        bot.register_next_step_handler(message, SC)   
    elif message.text == 'Расчет энтерального питания':
        pass
    elif message.text == 'Расчет ИТТ':
        pass
    elif message.text == 'Расчет калия':
        pass                
    elif message.text == 'Расчет натрия':
        pass
    elif message.text == 'Расчет АБТ':
        pass
    elif message.text == 'Расчет ТЛТ':
        pass
    elif message.text == 'Расчет параметров ИВЛ':
        pass
    elif message.text == 'Расчет ТВА':
        pass

# Калькулятор "Расчет скорости введения препаратов"
def SC(message):
    if message.text == 'Начать':        
        con = bot.send_message(message.chat.id, 'Введите концентрацию исходного раствора (мг/мл)')
        bot.register_next_step_handler(con, SC_vol)
    elif message.text == 'Информация':
        pass
    elif message.text == 'Назад':
        pass

def SC_vol(message):
        vol1 = bot.send_message(message.chat.id, 'Введите объем препарата (мл)')
        bot.register_next_step_handler(vol1, SC_question)    

def SC_question(message):
    global vol1
    
    vol1 = float(message.text)    
    keyboard_question = types.InlineKeyboardMarkup(row_width=2)
    yes1_btn = types.InlineKeyboardButton(text="ДА", callback_data="yes1")
    no1_btn = types.InlineKeyboardButton(text="НЕТ", callback_data="no1")
    keyboard_question.add(yes1_btn, no1_btn)
    bot.send_message(message.chat.id, "растворить?", reply_markup=keyboard_question)

@bot.callback_query_handler(func=lambda call:True)
def SC_solvent(call):
    if call.data == "yes1":
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        first = types.KeyboardButton('1')
        second = types.KeyboardButton('2')

        markup.add(first, second)
        bot.send_message(call.message.chat.id, 'Выберите', reply_markup=markup)
    elif call.data == "no1":
        pass

# RUN
if __name__ == "__main__":
    bot.polling(none_stop=True)
  • Вопрос задан
  • 113 просмотров
Решения вопроса 2
Vindicar
@Vindicar
RTFM!
Потому что надо документацию читать, и понимать, за что отвечает параметр func в callback_query_handler(), а не перепечатывать с ютуба.
Для общего понимания можешь глянуть мой старый ответ.
Если коротко, ты сам сказал телеботу, что full_calc() должна обрабатывать ВСЕ нажатия на кнопки.
Ответ написан
@EugeneVKruglov
Запишите хэндлер так
yes1_btn = types.InlineKeyboardButton(text="ДА", callback_data="yes1")

@bot.callback_query_handler(func=lambda call: call.startswith('yes1'))
def SC_solvent(call):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        first = types.KeyboardButton('1')
        second = types.KeyboardButton('2')
        markup.add(first, second)
        bot.send_message(call.message.chat.id, 'Выберите', reply_markup=markup)

Аналогично для no1_btn
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы