Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuchkaTriplesix committed Oct 25, 2023
1 parent 32d6062 commit 6dbcc6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
33 changes: 24 additions & 9 deletions handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ async def change_access(message: Message, state: FSMContext):
async def change_user_access(message: Message, state: FSMContext):
try:
telegram_id = int(message.text)
models.Users.change_access(telegram_id, 1)
await message.answer("Вы успешно поменяли группу пользователя, на Vip.")
await state.clear()
user = models.Users.change_access(telegram_id, 1)
if user is True:
await message.answer("Вы успешно поменяли группу пользователя, на Vip.")
await state.clear()
else:
await message.answer("Неверный телеграм айди.")
await state.clear()
except ValueError:
await message.answer("Неверный телеграм айди.")
await state.clear()


@router.message(F.text == "/kill")
Expand All @@ -68,11 +73,16 @@ async def add_admin(message: Message, state: FSMContext):
async def add_admin_state(message: Message, state: FSMContext):
try:
telegram_id = int(message.text)
models.Users.change_access(telegram_id, 2)
await message.answer("Вы выдали админ доступ пользователю.")
await state.clear()
user = models.Users.change_access(telegram_id, 2)
if user is True:
await message.answer("Вы выдали админ доступ пользователю.")
await state.clear()
else:
await message.answer("Неверный телеграм айди.")
await state.clear()
except ValueError:
await message.answer("Неверный телеграм айди.")
await state.clear()


@router.message(F.text == "/delete_admin")
Expand All @@ -89,11 +99,16 @@ async def delete_admin(message: Message, state: FSMContext):
async def delete_admin_state(message: Message, state: FSMContext):
try:
telegram_id = int(message.text)
models.Users.change_access(telegram_id, 0)
await message.answer("Вы удалили админ доступ у пользователя.")
await state.clear()
user = models.Users.change_access(telegram_id, 0)
if user is True:
await message.answer("Вы удалили админ доступ у пользователя.")
await state.clear()
else:
await message.answer("Неверный телеграм айди")
await state.clear()
except ValueError:
await message.answer("Неверный телеграм айди.")
await state.clear()


@router.message(F.text == "/admin_list")
Expand Down
5 changes: 4 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ def add_admin(telegram_id: int, username: str):
user = Users(username=username, telegram_id=telegram_id, group_id=2)
Users.add_close(user, session)

def change_access(telegram_id: int, group_id: int):
def change_access(telegram_id: int, group_id: int) -> object:
session = Session()
user = session.query(Users).where(Users.telegram_id == telegram_id).first()
if user is not None:
user.group_id = group_id
user.updated_at = datetime.datetime.utcnow()
session.commit()
session.close()
return True
else:
return False

def check_vip(telegram_id: int) -> object:
user = session.query(Users).where(Users.telegram_id == telegram_id).first()
Expand Down

0 comments on commit 6dbcc6f

Please sign in to comment.