Проблемы с машиной состояний в aiogram [closed] ⇐ Python
Проблемы с машиной состояний в aiogram [closed]
Делаю телеграмм бота(разбитого на файлы) с машиной состояний, но при ее активации ничего не происходит:
###Импорты###
from aiogram import types, Dispatcher from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.dispatcher.filters import Text from aiogram.dispatcher.filters.state import StatesGroup, State from aiogram.dispatcher.storage import FSMContext from PrimeBot import dp, bot, api, storage ###класс с состояниями###
class Starter(StatesGroup): calc_gender = State() calc_weight = State() calc_height = State() calc_age = State() ###состояние 1 пол###
async def calc_gender1(message: types.Message, state: FSMContext): print("start") global gender gender = message.text.lower() print(gender) await message.reply(f'Твой вес в кг: ') return await Starter.calc_weight.set() await Starter.next() ###состояние 2 вес###
async def calc_weight2(message: types.Message, state: FSMContext): global weight weight = message.text await message.reply(text=f'Рост см: ') return await Starter.calc_height.set() await Starter.next() ###состояние 3 рост###
async def calc_height3(message: types.Message, state: FSMContext): global height height = message.text await message.reply(text=f'Возраст: ') return await Starter.calc_age.set() await Starter.next() ###состояние 4 возраст###
async def calc_age4(message: types.Message, state: FSMContext): global age age = message.text await message.reply(text=f'Пол {gender}, рост {height}, вес {weight}, Возраст: {age}') if gender == "м": result_ccal = (10.0 * float(weight)) + (6.25 * float(height)) - (5.0 * float(age)) + 5.0 await message.reply(text=result_ccal) await Starter.finish() elif gender == "ж": result_ccal = (10.0 * float(weight)) + (6.25 * float(height)) - (5.0 * float(age)) - 161.0 await message.reply(text=result_ccal) await Starter.finish() else: print('grr') await Starter.finish() ###вызов диалога###
def dilog(dp: Dispatcher): print("dilog started") dp.register_message_handler(calc_gender1,commands="calculator", state=Starter.calc_gender) print("1 attemp") dp.register_message_handler(calc_weight2, state=Starter.calc_weight) print("2 attemp") dp.register_message_handler(calc_height3, state=Starter.calc_height) print("3 attemp") dp.register_message_handler(calc_age4, state=Starter.calc_age) print("4 attemp") Пробовал после активации какого нибудь состояния принтить "1 attemp", "2 attemp" они пишутся, но сама машина не реагирует. Вызываю в другом файле не основном может это как-то влияет
Делаю телеграмм бота(разбитого на файлы) с машиной состояний, но при ее активации ничего не происходит:
###Импорты###
from aiogram import types, Dispatcher from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.dispatcher.filters import Text from aiogram.dispatcher.filters.state import StatesGroup, State from aiogram.dispatcher.storage import FSMContext from PrimeBot import dp, bot, api, storage ###класс с состояниями###
class Starter(StatesGroup): calc_gender = State() calc_weight = State() calc_height = State() calc_age = State() ###состояние 1 пол###
async def calc_gender1(message: types.Message, state: FSMContext): print("start") global gender gender = message.text.lower() print(gender) await message.reply(f'Твой вес в кг: ') return await Starter.calc_weight.set() await Starter.next() ###состояние 2 вес###
async def calc_weight2(message: types.Message, state: FSMContext): global weight weight = message.text await message.reply(text=f'Рост см: ') return await Starter.calc_height.set() await Starter.next() ###состояние 3 рост###
async def calc_height3(message: types.Message, state: FSMContext): global height height = message.text await message.reply(text=f'Возраст: ') return await Starter.calc_age.set() await Starter.next() ###состояние 4 возраст###
async def calc_age4(message: types.Message, state: FSMContext): global age age = message.text await message.reply(text=f'Пол {gender}, рост {height}, вес {weight}, Возраст: {age}') if gender == "м": result_ccal = (10.0 * float(weight)) + (6.25 * float(height)) - (5.0 * float(age)) + 5.0 await message.reply(text=result_ccal) await Starter.finish() elif gender == "ж": result_ccal = (10.0 * float(weight)) + (6.25 * float(height)) - (5.0 * float(age)) - 161.0 await message.reply(text=result_ccal) await Starter.finish() else: print('grr') await Starter.finish() ###вызов диалога###
def dilog(dp: Dispatcher): print("dilog started") dp.register_message_handler(calc_gender1,commands="calculator", state=Starter.calc_gender) print("1 attemp") dp.register_message_handler(calc_weight2, state=Starter.calc_weight) print("2 attemp") dp.register_message_handler(calc_height3, state=Starter.calc_height) print("3 attemp") dp.register_message_handler(calc_age4, state=Starter.calc_age) print("4 attemp") Пробовал после активации какого нибудь состояния принтить "1 attemp", "2 attemp" они пишутся, но сама машина не реагирует. Вызываю в другом файле не основном может это как-то влияет
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Процесс приложения Node.js завершается виртуальной машиной Linux [закрыто]
Anonymous » » в форуме Linux - 0 Ответы
- 27 Просмотры
-
Последнее сообщение Anonymous
-