2022-06-04 22:02:51 +03:00
|
|
|
from aiogram import types
|
2022-06-16 00:32:17 +03:00
|
|
|
from aiogram.dispatcher.filters import CommandStart, CommandHelp
|
2022-06-04 22:02:51 +03:00
|
|
|
|
2022-06-05 15:02:41 +03:00
|
|
|
from load import dp, bot, messages
|
2022-06-04 22:02:51 +03:00
|
|
|
from keyboard.default.main_menu import main_menu
|
|
|
|
from utils.database.base import get_admins, get_operator
|
|
|
|
from utils.database.user import Register
|
2022-06-16 00:32:17 +03:00
|
|
|
from utils.database.market import Catalog
|
2022-06-04 22:02:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
@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)
|
|
|
|
)
|
|
|
|
|
2022-06-05 15:02:41 +03:00
|
|
|
|
2022-06-04 22:02:51 +03:00
|
|
|
@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)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-16 00:32:17 +03:00
|
|
|
@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> - получить товар по ID")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-04 22:02:51 +03:00
|
|
|
@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)
|
|
|
|
|
|
|
|
|
2022-06-05 15:02:41 +03:00
|
|
|
@dp.message_handler(lambda x: x.text == messages.info)
|
2022-06-04 22:02:51 +03:00
|
|
|
async def userinfo(message: types.Message):
|
|
|
|
await bot.send_message(
|
2022-06-05 15:02:41 +03:00
|
|
|
message.chat.id,
|
|
|
|
"User_id: <code>{user_id}</code>".format(user_id=message.from_user.id),
|
2022-06-04 22:02:51 +03:00
|
|
|
parse_mode="HTML"
|
|
|
|
)
|