class Example(StatesGroup):
state = State()
state = State()
@dp.message_handler(state=Choice.choice2)
async def ch2_save(msg: types.Message, state=FSMContext):
await state.update_data(choice2 = msg.text)
sl_btns = ['Добавить ➕', 'Готово ✅', 'Список ']
data = await state.get_data()
choice2 = data['choice2']
ch_sl = data["ch_sl"]
ch_sl_list = []
for listw in ch_sl:
ch_sl_list.append(listw)
choice_result = random.choice(ch_sl_list)
if choice2 == sl_btns[1]:
await msg.answer(f'Случайное слово из списка:\n\n{choice_result}')
await state.finish()
elif choice2 == sl_btns[0]:
await msg.answer('Введите значение: ')
await Choice.ch_sl.set()
elif choice2 == sl_btns[2]:
await msg.answer(f'Список слов:\n\n{ch_sl_list}')
@dp.message_handler(text='Случайность ')
async def choice1_start(msg: types.Message):
sl = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
sl_button1 = ['Добавить ➕']
sl.add(*sl_button1)
sl_button2 = ['Готово ✅']
sl.add(*sl_button2)
sl_button3 = ['Отмена']
sl.add(*sl_button3)
await msg.answer('Выберите пункт: ', reply_markup=sl)
await Choice.choice.set()
@dp.message_handler(state=Choice.choice)
async def ch_save(msg: types.Message, state=FSMContext):
await state.update_data(choice = msg.text)
data = await state.get_data()
choice = data["choice"]
sl_btns = ['Добавить ➕', 'Готово ✅', 'Список ']
if choice == sl_btns[0]:
await msg.answer('Введите значение: ')
await Choice.ch_sl.set()
@dp.message_handler(state=Choice.ch_sl)
async def ch_sl_add(msg: types.Message, state=FSMContext):
sl = types.ReplyKeyboardMarkup(resize_keyboard=True)
sl_button1 = ['Добавить ➕']
sl.add(*sl_button1)
sl_button2 = ['Готово ✅']
sl.add(*sl_button2)
sl_button3 = ['Список ']
sl.add(*sl_button3)
sl_button4 = ['Отмена']
sl.add(*sl_button4)
await state.update_data(ch_sl = msg.text)
await msg.answer('Добавлено', reply_markup=sl)
await Choice.choice2.set()
@dp.message_handler(state=Choice.choice2)
async def ch2_save(msg: types.Message, state=FSMContext):
await state.update_data(choice2 = msg.text)
sl_btns = ['Добавить ➕', 'Готово ✅', 'Список ']
data = await state.get_data()
choice2 = data['choice2']
ch_sl = data["ch_sl"]
ch_sl_list = []
ch_sl_list.append(ch_sl)
choice_result = random.choice(ch_sl_list)
if choice2 == sl_btns[1]:
await msg.answer(f'Случайное слово из списка:\n\n{choice_result}')
await state.finish()
elif choice2 == sl_btns[0]:
await msg.answer('Введите значение: ')
await Choice.ch_sl.set()
elif choice2 == sl_btns[2]:
await msg.answer(f'Список слов:\n\n{ch_sl_list}')