Separate staff roles and protect message delivery with operator guides
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -51,60 +51,11 @@ async def list_admins():
|
||||
|
||||
|
||||
async def add_admin(telegram_id: int):
|
||||
"""Добавить администратора"""
|
||||
async with async_session_maker() as session:
|
||||
# Проверяем, существует ли пользователь
|
||||
user = await UserService.get_user_by_telegram_id(session, telegram_id)
|
||||
|
||||
if not user:
|
||||
print(f"❌ Пользователь с ID {telegram_id} не найден")
|
||||
return
|
||||
|
||||
if telegram_id in ADMIN_IDS:
|
||||
print(f"❌ ID {telegram_id} - это главный администратор (.env)")
|
||||
return
|
||||
|
||||
if user.is_admin:
|
||||
print(f"❌ Пользователь {user.first_name or user.username} уже администратор")
|
||||
return
|
||||
|
||||
# Назначаем админа
|
||||
success = await UserService.set_admin(session, telegram_id, is_admin=True)
|
||||
|
||||
if success:
|
||||
name = user.first_name or user.username or f"@ID_{telegram_id}"
|
||||
print(f"✅ {name} назначен администратором")
|
||||
else:
|
||||
print(f"❌ Ошибка при назначении администратора")
|
||||
print(f"Use /add_admin {telegram_id} in the bot as a system administrator and confirm the change.")
|
||||
|
||||
|
||||
async def remove_admin(telegram_id: int):
|
||||
"""Удалить администратора"""
|
||||
async with async_session_maker() as session:
|
||||
if telegram_id in ADMIN_IDS:
|
||||
print(f"❌ Нельзя удалить главного администратора (.env)")
|
||||
print(f" Для изменения отредактируйте .env")
|
||||
return
|
||||
|
||||
# Проверяем, существует ли пользователь
|
||||
user = await UserService.get_user_by_telegram_id(session, telegram_id)
|
||||
|
||||
if not user:
|
||||
print(f"❌ Пользователь с ID {telegram_id} не найден")
|
||||
return
|
||||
|
||||
if not user.is_admin:
|
||||
print(f"❌ Пользователь {user.first_name or user.username} не является администратором")
|
||||
return
|
||||
|
||||
# Удаляем админа
|
||||
success = await UserService.set_admin(session, telegram_id, is_admin=False)
|
||||
|
||||
if success:
|
||||
name = user.first_name or user.username or f"@ID_{telegram_id}"
|
||||
print(f"✅ Права администратора удалены у {name}")
|
||||
else:
|
||||
print(f"❌ Ошибка при удалении прав администратора")
|
||||
print(f"Use /remove_admin {telegram_id} in the bot as a system administrator and confirm the change.")
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
Reference in New Issue
Block a user