Init commit
This commit is contained in:
3
handlers/__init__.py
Normal file
3
handlers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import user
|
||||
from . import admin
|
||||
from . import callback
|
4
handlers/admin/__init__.py
Normal file
4
handlers/admin/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import panel
|
||||
from . import add_post
|
||||
from . import delete_post
|
||||
from . import user_control
|
85
handlers/admin/add_post.py
Normal file
85
handlers/admin/add_post.py
Normal file
@@ -0,0 +1,85 @@
|
||||
import io
|
||||
|
||||
from aiogram import types
|
||||
from aiogram.types import ContentType
|
||||
from aiogram.dispatcher import FSMContext
|
||||
|
||||
from load import bot, dp, messages
|
||||
from utils.helper import download_file
|
||||
from keyboard.default.admin.main_menu import base_menu, continue_btn, all_right
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
from state.post import Post
|
||||
from utils.database.market import add_item
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.add_post, is_admin=True)
|
||||
async def cmd_add_post(message: types.Message):
|
||||
await bot.send_message(message.chat.id, "Укажите имя товара", reply_markup=base_menu())
|
||||
await Post.name.set()
|
||||
|
||||
|
||||
@dp.message_handler(is_admin=True, state=Post.name)
|
||||
async def admin_form_name(message: types.Message, state: FSMContext):
|
||||
await state.update_data(name=message.text)
|
||||
await bot.send_message(message.chat.id, "Укажите описание товара", reply_markup=base_menu(skip=True))
|
||||
await Post.description.set()
|
||||
|
||||
|
||||
@dp.message_handler(is_admin=True, state=Post.description)
|
||||
async def admin_form_desk(message: types.Message, state: FSMContext):
|
||||
if message.text == messages.skip_message:
|
||||
await state.update_data(description="")
|
||||
else:
|
||||
await state.update_data(description=message.text)
|
||||
await bot.send_message(message.chat.id, "Укажите цену", reply_markup=base_menu())
|
||||
await Post.price.set()
|
||||
|
||||
|
||||
@dp.message_handler(is_admin=True, state=Post.price)
|
||||
async def admin_form_price(message: types.message, state: FSMContext):
|
||||
if not message.text.replace('.','').replace(',', '').isdigit():
|
||||
await Post.price.set()
|
||||
await state.update_data(price=float(message.text.replace(",", ".")))
|
||||
await bot.send_message(message.chat.id, "Отправьте фото товара")
|
||||
await Post.image.set()
|
||||
|
||||
|
||||
@dp.message_handler(is_admin=True, state=Post.image, content_types=[ContentType.PHOTO])
|
||||
async def admin_form_image(message:types.Message, state: FSMContext):
|
||||
file_id = message.photo[-1].file_id
|
||||
file_info = await bot.get_file(file_id)
|
||||
photo = await download_file(file_info.file_path)
|
||||
await state.update_data(image=photo.read())
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Все данные для поста были заполнены",
|
||||
reply_markup=continue_btn
|
||||
)
|
||||
await Post.finish.set()
|
||||
|
||||
|
||||
@dp.message_handler(lambda x:x.text == messages.continue_, state=Post.finish, is_admin=True)
|
||||
async def finish(message: types.Message, state: FSMContext):
|
||||
data = await state.get_data()
|
||||
await bot.send_photo(
|
||||
message.chat.id,
|
||||
caption=messages.product_message.format(
|
||||
name=data["name"],
|
||||
description=data["description"],
|
||||
price=data["price"]
|
||||
),
|
||||
photo=data["image"],
|
||||
reply_markup=all_right,
|
||||
parse_mode='Markdown'
|
||||
)
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message, is_admin=True, state=Post.finish)
|
||||
async def write_on_db(message: types.Message, state: FSMContext):
|
||||
data = await state.get_data()
|
||||
add_item(**data)
|
||||
await state.finish()
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Товар был добавлен",
|
||||
reply_markup=back_to_main_menu
|
||||
)
|
27
handlers/admin/delete_post.py
Normal file
27
handlers/admin/delete_post.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import bot, dp, messages
|
||||
from utils.database.market import Catalog
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
from keyboard.inline.admin.catalog import item_list
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.delete_post, is_admin=True)
|
||||
async def delete_post(message: types.Message):
|
||||
items = Catalog.get_catalog()
|
||||
if not items:
|
||||
await bot.send_message(message.chat.id, "Каталог пуст:(")
|
||||
return
|
||||
item = items[0]
|
||||
await bot.send_message(message.chat.id, messages.catalog, reply_markup=back_to_main_menu)
|
||||
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",
|
||||
reply_markup=item_list(items=len(items)-1)
|
||||
)
|
10
handlers/admin/panel.py
Normal file
10
handlers/admin/panel.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.default.admin.main_menu import main_menu
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.admin_panel, is_admin=True)
|
||||
async def cmd_menu(message: types.Message):
|
||||
await bot.send_message(message.chat.id, "Admin panel", reply_markup=main_menu())
|
||||
|
6
handlers/admin/user_control/__init__.py
Normal file
6
handlers/admin/user_control/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from utils.json import permission
|
||||
|
||||
if permission.can_admin_add_admins:
|
||||
from . import adding
|
||||
if permission.can_admin_del_admins:
|
||||
from . import delete
|
37
handlers/admin/user_control/adding.py
Normal file
37
handlers/admin/user_control/adding.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from state.state import AddUser
|
||||
from utils.database.user import Register, User
|
||||
from keyboard.default.admin.main_menu import base_menu
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.add_admin, is_admin=True)
|
||||
async def add_admin(message: types.Message):
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
("Отправьте user_id пользователя\n"
|
||||
"Его можно узнать зайдя в информацию о пользователе"),
|
||||
reply_markup=base_menu()
|
||||
)
|
||||
await AddUser.user_id.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=AddUser.user_id)
|
||||
async def add_admin1(message: types.Message, state):
|
||||
await state.finish()
|
||||
user_id = message.text
|
||||
if not user_id.isdigit() or "-100" in user_id:
|
||||
await bot.send_message(message.chat.id, "Данные не правильные!", reply_markup=back_to_main_menu)
|
||||
return
|
||||
|
||||
user_id = int(user_id)
|
||||
user = User.get_user(user_id)
|
||||
if not user:
|
||||
await bot.send_message(message.chat.id, "Пользователь не существует!", reply_markup=back_to_main_menu)
|
||||
return
|
||||
Register.register_admin(user)
|
||||
await bot.send_message(message.chat.id, "Администратор добавлен!", reply_markup=back_to_main_menu)
|
||||
|
17
handlers/admin/user_control/delete.py
Normal file
17
handlers/admin/user_control/delete.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.inline.admin.user import item_list
|
||||
from utils.database.base import get_full_admin
|
||||
|
||||
@dp.message_handler(lambda x: x.text==messages.del_admin, is_admin=True)
|
||||
async def del_admin(message: types.Message):
|
||||
admins = get_full_admin()
|
||||
admin = admins[0]
|
||||
result = messages.admin_user.format(**admin)
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
result,
|
||||
parse_mode="Markdown",
|
||||
reply_markup=item_list(items=len(admins)-1)
|
||||
)
|
4
handlers/callback/__init__.py
Normal file
4
handlers/callback/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import null
|
||||
from . import catalog
|
||||
from . import cart
|
||||
from . import admin
|
2
handlers/callback/admin/__init__.py
Normal file
2
handlers/callback/admin/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import catalog
|
||||
from . import user
|
60
handlers/callback/admin/catalog.py
Normal file
60
handlers/callback/admin/catalog.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import io
|
||||
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, messages
|
||||
from utils.database.market import Catalog
|
||||
from keyboard.inline.admin.catalog import item_list
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["adm_prev", "adm_next"], is_admin=True)
|
||||
async def next_item_adm(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
count = int(data[1])
|
||||
items = Catalog.get_catalog()
|
||||
item = items[count]
|
||||
|
||||
await callback.message.edit_media(
|
||||
media=types.InputMediaPhoto(
|
||||
media=io.BytesIO(item["image"]),
|
||||
caption=messages.product_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
price=item['price']
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
),
|
||||
reply_markup=item_list(count, len(items)-1, int(data[2]))
|
||||
)
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0] == 'delete_post', is_admin=True)
|
||||
async def delete_post_adm(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
item_id = Catalog.get_catalog()[int(data[1])]["id"]
|
||||
Catalog.delete_post(item_id)
|
||||
|
||||
items = Catalog.get_catalog()
|
||||
if items:
|
||||
item = items[0]
|
||||
await callback.message.edit_media(
|
||||
media=types.InputMediaPhoto(
|
||||
media=io.BytesIO(item["image"]),
|
||||
caption=messages.product_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
price=item['price']
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
),
|
||||
reply_markup=item_list(items=len(items)-1)
|
||||
)
|
||||
else:
|
||||
await callback.message.delete()
|
||||
await dp.bot.send_message(
|
||||
callback.message.chat.id,
|
||||
messages.catalog + " пуст!",
|
||||
reply_markup=back_to_main_menu
|
||||
)
|
||||
await callback.answer("Товар удалён!")
|
||||
await callback.answer()
|
35
handlers/callback/admin/user.py
Normal file
35
handlers/callback/admin/user.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from subprocess import call
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, messages
|
||||
from keyboard.inline.admin.user import item_list
|
||||
from utils.database.base import get_full_admin, del_admin
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["admin_prev", "admin_next"], is_admin=True)
|
||||
async def next_item_adm(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
count = int(data[1])
|
||||
items = get_full_admin()
|
||||
admin = items[count]
|
||||
|
||||
await callback.message.edit_text(
|
||||
messages.admin_user.format(**admin),
|
||||
reply_markup=item_list(count, len(items)-1, int(data[2])),
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
await callback.answer()
|
||||
|
||||
@dp.callback_query_handler(lambda x: x.data.split("|")[0] == "delete_admin")
|
||||
async def delete_admin(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
count = int(data[1])
|
||||
items = get_full_admin()
|
||||
admin = items[count]
|
||||
if admin["user_id"] == callback.from_user.id:
|
||||
await dp.bot.send_message(callback.message.chat.id, "Вы не можете удалить сами себя")
|
||||
await callback.answer()
|
||||
return
|
||||
del_admin(admin["user_id"])
|
||||
await dp.bot.send_message(callback.message.chat.id, f"Админ {admin['first_name']} удалён!")
|
||||
await callback.answer()
|
74
handlers/callback/cart.py
Normal file
74
handlers/callback/cart.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import io
|
||||
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, messages
|
||||
from utils.database.cart import add_to_cart, get_user_cart, del_from_cart
|
||||
from utils.database.market import Catalog
|
||||
from keyboard.inline.cart import cart_list
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0]=="add_to_cart")
|
||||
async def add_cart(callback: types.CallbackQuery):
|
||||
item_id = callback.data.split("|")[1]
|
||||
add_to_cart(callback.from_user.id, item_id)
|
||||
await callback.answer("Товар добавлен!")
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0]=="del_from_cart")
|
||||
async def del_cart(callback: types.CallbackQuery):
|
||||
c = callback.data.split("|")[1]
|
||||
item_id = get_user_cart(callback.from_user.id)[int(c)][0]
|
||||
|
||||
del_from_cart(callback.from_user.id, item_id)
|
||||
|
||||
items = get_user_cart(callback.from_user.id)
|
||||
|
||||
if items:
|
||||
index, count =items[0]
|
||||
item = Catalog.get_catalog(index)
|
||||
await callback.message.edit_media(
|
||||
media=types.InputMediaPhoto(
|
||||
media=io.BytesIO(item["image"]),
|
||||
caption=messages.cart_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
count=count,
|
||||
price=item['price']*count
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
),
|
||||
reply_markup=cart_list(items=len(items)-1)
|
||||
)
|
||||
else:
|
||||
await callback.message.delete()
|
||||
await dp.bot.send_message(
|
||||
callback.message.chat.id,
|
||||
messages.cart + " пустая!",
|
||||
reply_markup=back_to_main_menu
|
||||
)
|
||||
await callback.answer("Товар удалён!")
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["cart_prev", "cart_next"])
|
||||
async def next_item(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
c = int(data[1])
|
||||
items = get_user_cart(callback.from_user.id)
|
||||
index, count = items[c]
|
||||
item = Catalog.get_catalog(index)
|
||||
|
||||
await callback.message.edit_media(
|
||||
media=types.InputMediaPhoto(
|
||||
media=io.BytesIO(item["image"]),
|
||||
caption=messages.cart_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
count=count,
|
||||
price=item['price']*count
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
),
|
||||
reply_markup=cart_list(c, len(items)-1)
|
||||
)
|
29
handlers/callback/catalog.py
Normal file
29
handlers/callback/catalog.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import io
|
||||
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, messages
|
||||
from utils.database.market import Catalog
|
||||
from keyboard.inline.catalog import item_list
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["prev", "next"])
|
||||
async def next_item(callback: types.CallbackQuery):
|
||||
data = callback.data.split("|")
|
||||
count = int(data[1])
|
||||
items = Catalog.get_catalog()
|
||||
item = items[count]
|
||||
|
||||
await callback.message.edit_media(
|
||||
media=types.InputMediaPhoto(
|
||||
media=io.BytesIO(item["image"]),
|
||||
caption=messages.product_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
price=item['price']
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
),
|
||||
reply_markup=item_list(count, len(items)-1, int(data[2]))
|
||||
)
|
||||
|
7
handlers/callback/null.py
Normal file
7
handlers/callback/null.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from aiogram.types import CallbackQuery
|
||||
|
||||
from load import dp
|
||||
|
||||
@dp.callback_query_handler(lambda c: c.data == "null")
|
||||
async def null(callback: CallbackQuery):
|
||||
await callback.answer()
|
5
handlers/user/__init__.py
Normal file
5
handlers/user/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from . import start
|
||||
from . import catalog
|
||||
from . import cart
|
||||
from . import checkout
|
||||
from . import ordering
|
40
handlers/user/cart.py
Normal file
40
handlers/user/cart.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.default.main_menu import cart_btn
|
||||
from keyboard.inline.cart import cart_list
|
||||
from utils.database.cart import get_user_cart, clean_cart
|
||||
from utils.database.market import Catalog
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.cart)
|
||||
async def cmd_cart(message: types.Message):
|
||||
items = get_user_cart(message.from_user.id)
|
||||
|
||||
if not items:
|
||||
await bot.send_message(message.chat.id, messages.cart + " пустая!", reply_markup=cart_btn())
|
||||
return
|
||||
|
||||
index, count = items[0]
|
||||
item = Catalog.get_catalog(index)
|
||||
|
||||
await bot.send_message(message.chat.id, messages.cart, reply_markup=cart_btn(False))
|
||||
|
||||
await bot.send_photo(
|
||||
chat_id=message.chat.id,
|
||||
photo=item["image"],
|
||||
caption=messages.cart_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
count=count,
|
||||
price=item['price']*count
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
reply_markup=cart_list(items=len(items)-1)
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.clean_cart)
|
||||
async def cmd_clean_cart(message: types.Message):
|
||||
clean_cart(message.from_user.id)
|
||||
await bot.send_message(message.chat.id, messages.cart + " очищена", reply_markup=cart_btn())
|
27
handlers/user/catalog.py
Normal file
27
handlers/user/catalog.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from utils.database.market import Catalog
|
||||
from keyboard.inline.catalog import item_list
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.catalog)
|
||||
async def catalog(message: types.Message):
|
||||
items = Catalog.get_catalog()
|
||||
if not items:
|
||||
await bot.send_message(message.chat.id, "Каталог пуст:(")
|
||||
return
|
||||
item = items[0]
|
||||
await bot.send_message(message.chat.id, messages.catalog, reply_markup=back_to_main_menu)
|
||||
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",
|
||||
reply_markup=item_list(items=len(items))
|
||||
)
|
35
handlers/user/checkout.py
Normal file
35
handlers/user/checkout.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from utils.database.cart import get_user_cart
|
||||
from utils.database.market import Catalog
|
||||
from utils.database.ordering import save_info
|
||||
from keyboard.default.checkout import checkout_btn
|
||||
from state.state import UserState
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.checkout)
|
||||
async def checkout(message:types.Message):
|
||||
items = get_user_cart(message.from_user.id)
|
||||
output: str = ""
|
||||
cost = 0
|
||||
for index, count in items:
|
||||
i = Catalog.get_catalog(index)
|
||||
output += f'Имя: {i["name"]} цена: {i["price"]} - {count}шт.\n'
|
||||
cost += i["price"] * count
|
||||
output += f"Общая сумма: {cost}\nВсё верно? Следующий этап: заполнение заявки"
|
||||
await bot.send_message(message.chat.id, output, reply_markup=checkout_btn())
|
||||
await UserState.confirm.set()
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message)
|
||||
async def continue_user_form(message: types.Message):
|
||||
pass
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.save_and_continue, state="*")
|
||||
async def save_user_info(message: types.Message):
|
||||
state = dp.current_state(chat=message.chat.id, user=message.from_user.id)
|
||||
info = await state.get_data()
|
||||
save_info(user_id=message.from_user.id, **info)
|
||||
await continue_user_form(message)
|
108
handlers/user/ordering.py
Normal file
108
handlers/user/ordering.py
Normal file
@@ -0,0 +1,108 @@
|
||||
from aiogram import types
|
||||
from aiogram.dispatcher import FSMContext
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.default.checkout import confirm_all_info
|
||||
from keyboard.default.main_menu import cancel_btn, get_phone_number, continue_btn
|
||||
from keyboard.default.ordering import load_info
|
||||
from state.state import UserState
|
||||
from state.checkout import Checkout
|
||||
from utils.database.ordering import get_info
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message, state=UserState.confirm)
|
||||
async def confirm(message: types.Message, state: FSMContext):
|
||||
await state.finish()
|
||||
info = get_info(message.from_user.id)
|
||||
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Может у вас есть сохраненные данные?",
|
||||
reply_markup=load_info(bool(info))
|
||||
)
|
||||
await Checkout.loaded.set()
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.load_data, state=Checkout.loaded)
|
||||
async def load_form(message: types.message, state: FSMContext):
|
||||
info = get_info(message.from_user.id)
|
||||
await state.update_data(
|
||||
loaded=True,
|
||||
first_name = info["first_name"],
|
||||
last_name = info["last_name"],
|
||||
phone_number = info["phone_number"],
|
||||
address = info["address"]
|
||||
)
|
||||
await bot.send_message(message.chat.id, "Ваши данные загружены!", reply_markup=continue_btn)
|
||||
await Checkout.finish.set()
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.rewrite_data, state=Checkout.loaded)
|
||||
async def new_form(message: types.Message, state: FSMContext = None):
|
||||
await state.update_data(loaded=False)
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Напишите вашу фамилию",
|
||||
reply_markup=cancel_btn
|
||||
)
|
||||
await Checkout.last_name.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=Checkout.last_name)
|
||||
async def form_last_name(message: types.Message, state: FSMContext):
|
||||
await state.update_data(last_name=message.text)
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Ваше имя",
|
||||
reply_markup=cancel_btn
|
||||
)
|
||||
await Checkout.first_name.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=Checkout.first_name)
|
||||
async def form_first_name(message: types.Message, state: FSMContext):
|
||||
await state.update_data(first_name=message.text)
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
("Номер телефона\n\n"
|
||||
"Можете написать номер телефона вручную"),
|
||||
reply_markup=get_phone_number
|
||||
)
|
||||
await Checkout.phone_number.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=Checkout.phone_number, content_types=[types.ContentType.CONTACT, types.ContentType.TEXT])
|
||||
async def form_phone(message: types.Message, state: FSMContext):
|
||||
if message.contact is not None:
|
||||
phone=message.contact.phone_number
|
||||
else: phone=message.text
|
||||
if len(phone) in [10,12,13]:
|
||||
await state.update_data(phone_number=phone)
|
||||
await bot.send_message(message.chat.id, "Отправте адрес доставки", reply_markup=cancel_btn)
|
||||
await Checkout.address.set()
|
||||
else:
|
||||
await bot.send_message(message.chat.id, "Номер телефона не правильный!")
|
||||
await Checkout.phone_number.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=Checkout.address)
|
||||
async def form_address(message: types.Message, state: FSMContext):
|
||||
await state.update_data(address=message.text)
|
||||
await bot.send_message(message.chat.id, "Отлично заявка заполнена!", reply_markup=continue_btn)
|
||||
await Checkout.finish.set()
|
||||
|
||||
|
||||
@dp.message_handler(state=Checkout.finish)
|
||||
async def finish_form(message: types.Message, state: FSMContext):
|
||||
data = await state.get_data()
|
||||
|
||||
text = (f"Имя: {data['first_name']}\n"
|
||||
f"Фамилия: {data['last_name']}\n"
|
||||
f"Номер телефона: {data['phone_number']}\n"
|
||||
f"Адрес: {data['address']}\n"
|
||||
)
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
text,
|
||||
reply_markup=confirm_all_info()
|
||||
)
|
50
handlers/user/start.py
Normal file
50
handlers/user/start.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from aiogram import types
|
||||
from aiogram.dispatcher.filters import CommandStart
|
||||
|
||||
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
|
||||
|
||||
|
||||
@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(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: <code>{user_id}</code>").format(user_id=message.from_user.id),
|
||||
parse_mode="HTML"
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(commands=['test'])
|
||||
async def test(message: types.Message):
|
||||
Register.register_admin(message.from_user)
|
Reference in New Issue
Block a user