from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram import types, Dispatcher
from create_bot import dp
class FSMAdmin(StatesGroup):
photo = State()
name = State()
description = State()
price = State()
async def cm_start(message : types.Message):
await FSMAdmin.photo.set()
await message.reply('Загрузи фото')
async def load_photo(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['photo'] = message.photo[0].file_id
await FSMAdmin.next()
await message.reply('Теперь введи название')
async def load_name(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['name'] = message.text
await FSMAdmin.next()
await message.reply('Введи описание')
async def load_description(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['description'] = message.text
await FSMAdmin.next()
await message.reply('Укажи цену')
async def load_price(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['price'] = float(message.text)
async with state.proxy() as data:
await message.reply(str(data))
await state.finish()
def register_handlers_admin(dp : Dispatcher):
dp.register_message_handler(cm_start, commands=['Загрузить'], state="*")
dp.register_message_handler(load_photo, content_types=['photo'], state=FSMAdmin.photo)
dp.register_message_handler(load_name, state=FSMAdmin.name)
dp.register_message_handler(load_description, state=FSMAdmin.description)
dp.register_message_handler(load_price, state=FSMAdmin.price)
главный и запускаемый файл
from aiogram.utils import executor
from create_bot import dp
async def on_startup(_):
print('Бот вышел в онлайн')
#await message.reply(message.text)
#await bot.send_message(message.from_user.id, message.text)
#await message.answer(message.text)
from handlers import client, admin, other
client.register_handlers_client(dp)
admin.register_handlers_admin(dp)
other.register_handlers_other(dp)
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)