from aiogram import types from aiogram.dispatcher.filters import CommandStart, CommandHelp from load import dp, bot, messages from keyboard.default.main_menu import main_menu from utils.database.base import get_admins, get_operator from utils.database.user import Register from utils.database.market import Catalog @dp.message_handler(CommandStart()) async def start(message: types.Message): Register.register_user(message.from_user) is_bot_admin = message.from_user.id in get_admins() is_operator = message.from_user.id in get_operator() await bot.send_message( message.chat.id, messages.welcome.format(user=message.from_user.first_name), reply_markup=main_menu(admin=is_bot_admin, operator=is_operator) ) @dp.message_handler(lambda x: x.text == messages.back) async def back_to_menu(message: types.Message): is_bot_admin = message.from_user.id in get_admins() is_operator = message.from_user.id in get_operator() await bot.send_message( message.chat.id, "Главное меню", reply_markup=main_menu(admin=is_bot_admin, operator=is_operator) ) @dp.message_handler(commands='get') async def get_item(message: types.Message): args = message.get_args() if not args and not args.isdigit(): await bot.send_message(message.chat.id, "Неверные данные") return item = Catalog.get_catalog(args) if not item: await bot.send_message(message.chat.id, "Товар не найден!") return await bot.send_photo( chat_id=message.chat.id, photo=item["image"], caption=messages.product_message.format( name=item["name"], description=item["description"], price=item['price'] ), parse_mode="Markdown", ) @dp.message_handler(CommandHelp()) async def help_cmd(message: types.Message): await bot.send_message( message.chat.id, ("/sos - попросить помощь в оператора\n" "/get - получить товар по ID") ) @dp.message_handler(lambda x: x.text == messages.cancel_message, state="*") async def cancel(message: types.Message): state = dp.current_state(chat=message.chat.id, user=message.from_user.id) await state.finish() await back_to_menu(message) @dp.message_handler(lambda x: x.text == messages.info) async def userinfo(message: types.Message): await bot.send_message( message.chat.id, "User_id: {user_id}".format(user_id=message.from_user.id), parse_mode="HTML" )