Advertisement
4killU

Untitled

Mar 19th, 2022
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. import logging
  2. from aiogram import Bot, Dispatcher, executor, types
  3. from aiogram.dispatcher.filters import Text
  4. from aiogram.utils.exceptions import MessageNotModified
  5. from aiogram.utils.callback_data import CallbackData
  6. from aiogram.dispatcher.filters.state import State, StatesGroup
  7. from random import randint
  8. from contextlib import suppress
  9. from aiogram.dispatcher import FSMContext
  10. from aiogram.dispatcher.filters import Text
  11. from aiogram.contrib.fsm_storage.memory import MemoryStorage
  12.  
  13.  
  14. token = "СЮДА ТОКЕН"
  15.  
  16.  
  17. logging.basicConfig(level=logging.INFO)
  18.  
  19.  
  20. bot = Bot(token=token)
  21. dp = Dispatcher(bot)
  22. storage = MemoryStorage()
  23. dp = Dispatcher(bot, storage=storage)
  24.  
  25.  
  26. user_data = {}
  27.  
  28.  
  29. class test_state(StatesGroup):
  30.     q1 = State()
  31.     q2 = State()
  32.     q3 = State()
  33.     end = State()
  34.  
  35.  
  36. # ----------
  37.  
  38. @dp.message_handler(commands="start")
  39. async def cmd_start(message: types.Message):
  40.     keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
  41.     buttons = ["С пюрешкой", "Без пюрешки"]
  42.     keyboard.add(*buttons)
  43.     await message.answer("Как подавать котлеты?", reply_markup=keyboard)
  44.     await test_state.next()
  45.  
  46.  
  47. @dp.message_handler(state=test_state.q1)
  48. async def sex_hero(message: types.Message, state: FSMContext):
  49.     answer_for_q1 = message.text
  50.     await state.update_data(
  51.         {
  52.             'answer_for_q1' : f'{answer_for_q1}'
  53.         }
  54.     )
  55.     keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
  56.     buttons = ["Чай", "Кофе"]
  57.     keyboard.add(*buttons)
  58.     await message.answer('Что будете пить?',reply_markup=keyboard)
  59.     await test_state.next()
  60.  
  61.  
  62. @dp.message_handler(state=test_state.q2)
  63. async def nickname_hero(message: types.message, state: FSMContext):
  64.     answer_for_q2 = message.text
  65.     await state.update_data(
  66.         {
  67.             'answer_for_q2' : f'{answer_for_q2}'
  68.         }
  69.     )
  70.    
  71.     buttons = [
  72.         types.InlineKeyboardButton(text="Апельсин", callback_data="orange"),
  73.         types.InlineKeyboardButton(text="Лайм", callback_data="lime"),
  74.     ]
  75.     keyboard = types.InlineKeyboardMarkup(row_width=2)
  76.     keyboard.add(*buttons)
  77.     await message.answer(f"Апельсин или Лайм", reply_markup=keyboard)
  78.    
  79.     await test_state.next()
  80.  
  81.  
  82. @dp.message_handler()
  83. @dp.callback_query_handler(text=['orange', 'lime'], state=test_state.q3)
  84. async def callbacks_num(call: types.CallbackQuery, message: types.message, state: FSMContext):
  85.     print(call.data)
  86.  
  87.     if call.data == "orange":
  88.         user_data = "orange"
  89.     elif call.data == "lime":
  90.         user_data = "lime"
  91.  
  92.    
  93.     await state.update_data(
  94.         {
  95.             'answer_for_q3' : f'{user_data}'
  96.         }
  97.     )
  98.     await call.answer()
  99.     await call.message.edit_text('Ответ принят')
  100.    
  101.     await message.answer('Опрос окончен')
  102.     data = await state.get_data()
  103.     print(f'data -> {data}')
  104.     q1 = data.get('answer_for_q1')
  105.     q2 = data.get('answer_for_q2')
  106.     q3 = data.get('answer_for_q3')
  107.     await state.finish()
  108.     await message.answer(f'Вы выбрали : {q1}, {q2}, {q3}')
  109.  
  110.  
  111.  
  112. # @dp.message_handler(state=test_state.end)
  113. # async def sex_hero(message: types.Message, state: FSMContext):
  114. #     await message.answer('Опрос окончен')
  115. #     data = await state.get_data()
  116. #     print(f'data -> {data}')
  117. #     q1 = data.get('answer_for_q1')
  118. #     q2 = data.get('answer_for_q2')
  119. #     q3 = data.get('answer_for_q3')
  120. #     await state.finish()
  121. #     await message.answer(f'Вы выбрали : {q1}, {q2}, {q3}')
  122.  
  123.  
  124. # Запуск бота
  125. if __name__ == "__main__":
  126.     executor.start_polling(dp, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement