storage = MemoryStorage()
bot = Bot('')
dp = Dispatcher(bot=bot, storage=storage)
ADMIN_ID =
async def on_startup(_):
await db.db_start()
print('Бот успешно запущен!')
class NewOrder(StatesGroup):
type = State()
item = State()
rayon = State()
tip = State()
buttons_order = State()
sendmoney = State()
task = State()
class NewOrderMakeevka(StatesGroup):
type = State()
item = State()
rayon = State()
tip = State()
buttons_order = State()
sendmoney = State()
task = State()
main_inline_markup = InlineKeyboardMarkup(row_width=2)
@dp.message_handler(commands=['start'])
async def cmd_start(message: types.Message):
await db.cmd_start_db(message.from_user.id)
await message.answer_sticker('CAACAgIAAxkBAAMpZBAAAfUO9xqQuhom1S8wBMW98ausAAI4CwACTuSZSzKxR9LZT4zQLwQ')
await message.answer(f'{message.from_user.first_name}, добро пожаловать в магазин кроссовок!',
reply_markup=inline_markup)
if message.from_user.id == ADMIN_ID:
await message.answer('Вы авторизовались как администратор!', reply_markup=main_admin)
@dp.message_handler(commands=['id'])
async def cmd_id(message: types.Message):
await message.answer(f'{message.from_user.id}')
@dp.message_handler(text='Каталог')
async def catalog(message: types.Message):
await message.answer('Выберите категорию', reply_markup=inline_markup)
@dp.message_handler(text='Корзина')
async def cart(message: types.Message):
await message.answer('Корзина пуста!')
@dp.message_handler(text='Контакты')
async def contacts(message: types.Message):
await message.answer('Покупать товар у него: @mesudoteach')
@dp.message_handler(text='Админ-панель')
async def contacts(message: types.Message):
if message.from_user.id == ADMIN_ID:
await message.answer('Вы вошли в админ-панель', reply_markup=admin_panel)
else:
await message.reply('Я тебя не понимаю.')
@dp.message_handler(text='Отмена', state=NewOrder)
async def back(message: types.Message, state: FSMContext):
if message.text == 'Отмена':
await state.finish()
await message.answer(text='Добро пожаловать!', reply_markup=inline_markup)
if message.from_user.id == ADMIN_ID:
await message.answer(text='Админ панель возвращена', reply_markup=main_admin)
@dp.message_handler(text='Добавить товар')
async def item_add(message: types.Message):
if message.from_user.id == ADMIN_ID:
await NewOrder.type.set()
await message.answer('Выберите город', reply_markup=inline_markup)
else:
await message.reply('Я тебя не понимаю.')
@dp.callback_query_handler(state=NewOrder.type)
async def type(callback: types.CallbackQuery, state: FSMContext):
async with state.proxy() as data:
data['type'] = callback.data
await callback.message.answer(text='Напишите название товара', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.item)
async def iteM(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['item'] = message.text
await message.answer(text='Напишите название района', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.rayon)
async def Rayon(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['rayon'] = message.text
await message.answer(text='Введите тип', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.tip)
async def tip(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['tip'] = message.text
await message.answer(text='Введите значение', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.buttons_order)
async def buttons_order(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['buttons_order'] = message.text
await message.answer(text='Введите кнопки для подтверждения', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.sendmoney)
async def sendmoney(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['sendmoney'] = message.text
await message.answer(text='Деньги слать сюда', reply_markup=cancel)
await NewOrder.next()
@dp.message_handler(state=NewOrder.task)
async def task(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['task'] = message.text
async with state.proxy() as data:
city = data.get('type')
if city == 'doneck':
await db.add_item_don(state)
elif city == 'makeevka':
await db.add_item_makeevka(state)
# Получаем имя товара из базы данных
item_name = data.get('item')
i_id = data.get('i_id')
rayon = data.get('rayon')
# Создаем подкнопку для инлайн-клавиатуры
new_item_inline_button = InlineKeyboardButton(item_name, callback_data=f"{item_name}")
print(new_item_inline_button)
# Добавляем подкнопку к глобальной инлайн-клавиатуре
if city == 'doneck':
Doneck_Menu.insert(new_item_inline_button)
elif city == 'makeevka':
Makeevka_Menu.insert(new_item_inline_button)
# Обновляем клаzвиатуру у кнопки "Донецк"
await bot.send_message(
chat_id=message.chat.id,
text=f'Товар {item_name} создан в городе {city}, с районом {rayon}',
reply_markup=main_admin)
@dp.callback_query_handler()
async def citys(callback: types.CallbackQuery, state: FSMContext):
async with state.proxy() as data:
if callback.data == 'doneck':
await callback.message.answer(text='Вы выбрали Донецк', reply_markup=Doneck_Menu)
elif callback.data == 'makeevka':
await callback.message.answer(text='Вы выбрали Макеевку', reply_markup=Makeevka_Menu)
elif callback.data == f'{item_name}':
await callback.message.answer(text='Вы выбрали предмет')
if __name__ == '__main__':
executor.start_polling(dp, on_startup=on_startup, skip_updates=True)