ShopBot/handlers/callback/admin/user.py
2022-06-05 15:02:41 +03:00

36 lines
1.3 KiB
Python

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()