ShopBot/handlers/callback/operator/user.py

36 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-06-16 00:32:17 +03:00
from aiogram import types
from load import dp, messages
from keyboard.inline.admin.user import item_list
from utils.database.base import get_full_operator, del_operator
@dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["operator_prev", "operator_next"], is_admin=True)
async def next_item_adm(callback: types.CallbackQuery):
data = callback.data.split("|")
count = int(data[1])
items = get_full_operator()
user = items[count]
await callback.message.edit_text(
messages.admin_user.format(**user),
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_operator")
async def delete_admin(callback: types.CallbackQuery):
data = callback.data.split("|")
count = int(data[1])
items = get_full_operator()
user = items[count]
if user["user_id"] == callback.from_user.id:
await dp.bot.send_message(callback.message.chat.id, "Вы не можете удалить сами себя")
await callback.answer()
return
del_operator(user["user_id"])
await dp.bot.send_message(callback.message.chat.id, f"Оператор {user['first_name']} удалён!")
await callback.answer()