From a426dd090588e8407410c9f099fd23ded1edc2dc Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 11:01:40 +0600 Subject: [PATCH 1/5] fix roles --- handlers/admin.py | 6 +++--- models.py | 9 +++++++++ user_list.json | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index 0f9dd8a..7b7a9d9 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -49,7 +49,7 @@ async def change_user_access(message: Message, state: FSMContext): @router.message(F.text == "/kill") async def kill_process(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/kill") - if models.Users.check_admin(message.from_user.id) is True: + if models.Users.check_owner(message.from_user.id) is True: await message.answer("Отключаюсь(..") sys.exit() else: @@ -59,7 +59,7 @@ async def kill_process(message: Message): @router.message(F.text == "/add_admin") async def add_admin(message: Message, state: FSMContext): models.LogBase.add(message.from_user.id, message.from_user.username, "/add_admin") - if models.Users.check_admin(message.from_user.id) is True: + if models.Users.check_owner(message.from_user.id) is True: await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.add_admin_id_state) else: @@ -80,7 +80,7 @@ async def add_admin_state(message: Message, state: FSMContext): @router.message(F.text == "/delete_admin") async def delete_admin(message: Message, state: FSMContext): models.LogBase.add(message.from_user.id, message.from_user.username, "delete_admin") - if models.Users.check_admin(message.from_user.id) is True: + if models.Users.check_owner(message.from_user.id) is True: await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.delete_admin_state) else: diff --git a/models.py b/models.py index a0cfb12..2e48b86 100644 --- a/models.py +++ b/models.py @@ -14,6 +14,7 @@ conn = engine.connect() +# Database user_group: {0: user, 1: vip, 2: admin, 3: owner} # noinspection PyTypeChecker,PyMethodParameters,PyShadowingNames class Users(Base): __tablename__ = "users" @@ -64,6 +65,14 @@ def check_vip(telegram_id: int) -> object: else: return False + def check_owner(telegram_id: int) -> object: + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + user_group = user.group_id + if user_group >= 3: + return True + else: + return False + def check_admin(telegram_id: int) -> object: user = session.query(Users).where(Users.telegram_id == telegram_id).first() user_group = user.group_id diff --git a/user_list.json b/user_list.json index 7c1a729..50680ff 100644 --- a/user_list.json +++ b/user_list.json @@ -12,5 +12,10 @@ "960622004": [ "Snakebite Case", "Revolution Case" + ], + "736491563": [ + "Clutch Case", + "Danger Zone Case", + "CS20 Case" ] } \ No newline at end of file From a88f91b40376cba3f931b9b72ae504627815c201 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 11:08:14 +0600 Subject: [PATCH 2/5] fix(logs) --- handlers/client.py | 1 + handlers/vip.py | 1 + 2 files changed, 2 insertions(+) diff --git a/handlers/client.py b/handlers/client.py index 488f268..5eeb2b9 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -35,6 +35,7 @@ async def item_list(message: Message): @router.callback_query() async def answer(callback: CallbackQuery): + models.LogBase.add(callback.from_user.id, callback.from_user.username, "add_callback") user_id = callback.message.chat.id user_id = f"{user_id}" case = case_translation.case_translation(callback.data) diff --git a/handlers/vip.py b/handlers/vip.py index 393ab8f..9a1723a 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -49,6 +49,7 @@ async def my_cases(message: Message): # noinspection PyTypeChecker @router.callback_query(F.data == "items_price") async def items_price(callback: CallbackQuery): + models.LogBase.add(callback.from_user.id, callback.from_user.username, "items_price") items = models.Items.user_items(callback.from_user.id) answer = 'Стоимость вашего инвентаря:\n\n' total = 0 From aad13acd9043cc0e8ee40850479673c16f885ed1 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 11:15:35 +0600 Subject: [PATCH 3/5] log time --- models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/models.py b/models.py index 2e48b86..842dfc3 100644 --- a/models.py +++ b/models.py @@ -136,6 +136,7 @@ class LogBase(Base): telegram_id = Column(BigInteger, index=True) username = Column(String(length=32)) function_name = Column(String(length=12)) + time_used = Column(DateTime, default=datetime.datetime.utcnow) def add(telegram_id: int, username: str, function_name: str): session = Session() From 32d6062be7ecea4d5794cad0b1ce7a958703a3a1 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 11:23:32 +0600 Subject: [PATCH 4/5] style --- handlers/admin.py | 6 ++---- handlers/client.py | 3 +-- handlers/vip.py | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index 7b7a9d9..627c037 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -26,8 +26,7 @@ async def admin_kb(message: Message): @router.message(F.text == "/give_vip") async def change_access(message: Message, state: FSMContext): models.LogBase.add(message.from_user.id, message.from_user.username, "/give_vip") - telegram_id = message.from_user.id - if models.Users.check_admin(telegram_id) is True: + if models.Users.check_admin(message.from_user.id) is True: await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.get_user_id_state) else: @@ -36,9 +35,8 @@ async def change_access(message: Message, state: FSMContext): @router.message(ChangeAccessState.get_user_id_state, F.text) async def change_user_access(message: Message, state: FSMContext): - telegram_id = message.text try: - telegram_id = int(telegram_id) + telegram_id = int(message.text) models.Users.change_access(telegram_id, 1) await message.answer("Вы успешно поменяли группу пользователя, на Vip.") await state.clear() diff --git a/handlers/client.py b/handlers/client.py index 5eeb2b9..a493be8 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -36,8 +36,7 @@ async def item_list(message: Message): @router.callback_query() async def answer(callback: CallbackQuery): models.LogBase.add(callback.from_user.id, callback.from_user.username, "add_callback") - user_id = callback.message.chat.id - user_id = f"{user_id}" + user_id = f"{callback.message.chat.id}" case = case_translation.case_translation(callback.data) await callback.message.answer(f"Вы добавили {case}.") data = json_support.read_inf(json_data) diff --git a/handlers/vip.py b/handlers/vip.py index 9a1723a..bf6dc60 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -76,7 +76,6 @@ async def add_item(message: Message, state: FSMContext): @router.message(AddInventory.add_item_state, F.text) async def add_item_bd(message: Message, state: FSMContext): mes = message.text.split(".") - print(mes) hash_name = mes[0] try: item_count = int(mes[1]) From 6dbcc6f283f0189e2de2a9085d2ff16c11d0e8d8 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 12:32:12 +0600 Subject: [PATCH 5/5] fix --- handlers/admin.py | 33 ++++++++++++++++++++++++--------- models.py | 5 ++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index 627c037..ecfb3c2 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -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") @@ -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") @@ -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") diff --git a/models.py b/models.py index 842dfc3..d07ef30 100644 --- a/models.py +++ b/models.py @@ -48,7 +48,7 @@ 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: @@ -56,6 +56,9 @@ def change_access(telegram_id: int, group_id: int): 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()