Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from aiogram import Bot, Dispatcher, executor, types
- from aiogram.dispatcher.filters import Text
- from aiogram.utils.exceptions import MessageNotModified
- from aiogram.utils.callback_data import CallbackData
- from aiogram.dispatcher.filters.state import State, StatesGroup
- from random import randint
- from contextlib import suppress
- from aiogram.dispatcher import FSMContext
- from aiogram.dispatcher.filters import Text
- from aiogram.contrib.fsm_storage.memory import MemoryStorage
- token = "СЮДА ТОКЕН"
- logging.basicConfig(level=logging.INFO)
- bot = Bot(token=token)
- dp = Dispatcher(bot)
- storage = MemoryStorage()
- dp = Dispatcher(bot, storage=storage)
- user_data = {}
- class test_state(StatesGroup):
- q1 = State()
- q2 = State()
- q3 = State()
- end = State()
- # ----------
- @dp.message_handler(commands="start")
- async def cmd_start(message: types.Message):
- keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
- buttons = ["С пюрешкой", "Без пюрешки"]
- keyboard.add(*buttons)
- await message.answer("Как подавать котлеты?", reply_markup=keyboard)
- await test_state.next()
- @dp.message_handler(state=test_state.q1)
- async def sex_hero(message: types.Message, state: FSMContext):
- answer_for_q1 = message.text
- await state.update_data(
- {
- 'answer_for_q1' : f'{answer_for_q1}'
- }
- )
- keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
- buttons = ["Чай", "Кофе"]
- keyboard.add(*buttons)
- await message.answer('Что будете пить?',reply_markup=keyboard)
- await test_state.next()
- @dp.message_handler(state=test_state.q2)
- async def nickname_hero(message: types.message, state: FSMContext):
- answer_for_q2 = message.text
- await state.update_data(
- {
- 'answer_for_q2' : f'{answer_for_q2}'
- }
- )
- buttons = [
- types.InlineKeyboardButton(text="Апельсин", callback_data="orange"),
- types.InlineKeyboardButton(text="Лайм", callback_data="lime"),
- ]
- keyboard = types.InlineKeyboardMarkup(row_width=2)
- keyboard.add(*buttons)
- await message.answer(f"Апельсин или Лайм", reply_markup=keyboard)
- await test_state.next()
- @dp.message_handler()
- @dp.callback_query_handler(text=['orange', 'lime'], state=test_state.q3)
- async def callbacks_num(call: types.CallbackQuery, message: types.message, state: FSMContext):
- print(call.data)
- if call.data == "orange":
- user_data = "orange"
- elif call.data == "lime":
- user_data = "lime"
- await state.update_data(
- {
- 'answer_for_q3' : f'{user_data}'
- }
- )
- await call.answer()
- await call.message.edit_text('Ответ принят')
- await message.answer('Опрос окончен')
- data = await state.get_data()
- print(f'data -> {data}')
- q1 = data.get('answer_for_q1')
- q2 = data.get('answer_for_q2')
- q3 = data.get('answer_for_q3')
- await state.finish()
- await message.answer(f'Вы выбрали : {q1}, {q2}, {q3}')
- # @dp.message_handler(state=test_state.end)
- # async def sex_hero(message: types.Message, state: FSMContext):
- # await message.answer('Опрос окончен')
- # data = await state.get_data()
- # print(f'data -> {data}')
- # q1 = data.get('answer_for_q1')
- # q2 = data.get('answer_for_q2')
- # q3 = data.get('answer_for_q3')
- # await state.finish()
- # await message.answer(f'Вы выбрали : {q1}, {q2}, {q3}')
- # Запуск бота
- if __name__ == "__main__":
- executor.start_polling(dp, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement