From 22cef8511791fa4eb020ba26dfc08a9b7e4bf1af Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Wed, 25 Oct 2023 15:36:01 +0600 Subject: [PATCH 1/3] feat(admin delete item) --- handlers/admin.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/handlers/admin.py b/handlers/admin.py index ecfb3c2..5979efd 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -14,6 +14,7 @@ class ChangeAccessState(StatesGroup): get_user_id_state = State() add_admin_id_state = State() delete_admin_state = State() + del_item_state = State() @router.message(F.text == "/admin") @@ -124,3 +125,26 @@ async def admin_list(message: Message): x = f"@{admin.username}: {admin.telegram_id} Admin\n" bot_message += x await message.answer(bot_message) + + +@router.message(F.text == "/del_item") +async def del_item(message: Message, state: FSMContext): + if models.Users.check_admin(message.from_user.id) is True: + await message.answer("Введите айди.хешнейм") + await state.set_state(ChangeAccessState.del_item_state) + else: + await message.answer("У вас нет доступа.") + + +@router.message(ChangeAccessState.del_item_state, F.text) +async def del_item_state(message: Message, state: FSMContext): + mes = message.text.split(".") + hash_name = mes[1] + try: + telegram_id = int(mes[0]) + models.Items.delete_item(telegram_id, hash_name) + await message.answer("Вы удалили предмет у пользователя.") + await state.clear() + except ValueError: + await message.answer("Неверный ввод.") + await state.clear() From 11683df9e90defefcb716cacb0b45f3f8152db61 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Fri, 3 Nov 2023 16:32:16 +0600 Subject: [PATCH 2/3] fix --- models.py | 3 ++- user_list.json | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/models.py b/models.py index d07ef30..7db887e 100644 --- a/models.py +++ b/models.py @@ -95,7 +95,7 @@ class Items(Base): __tablename__ = "items" id = Column(Integer, primary_key=True) user_id = Column(Integer) - hash_name = Column(String(length=30)) + hash_name = Column(String(length=60)) item_count = Column(Integer) def add_item(telegram_id: int, hash_name: str, item_count: int): @@ -130,6 +130,7 @@ def delete_item(telegram_id: int, hash_name: str): item = session.query(Items).filter(Items.hash_name == hash_name).where(Items.user_id == user_id).first() session.delete(item) session.commit() + session.close() # noinspection PyShadowingNames,PyMethodParameters diff --git a/user_list.json b/user_list.json index 50680ff..57d54d7 100644 --- a/user_list.json +++ b/user_list.json @@ -17,5 +17,36 @@ "Clutch Case", "Danger Zone Case", "CS20 Case" + ], + "1312583149": [ + "CS:GO Weapon Case", + "eSports 2013 Case", + "Operation Bravo Case", + "CS:GO Weapon Case 2", + "eSports 2013 Winter Case", + "Winter Offensive Weapon Case", + "Operation Phoenix Weapon Case", + "Huntsman Weapon Case", + "Operation Breakout Weapon Case", + "CS:GO Weapon Case 3", + "eSports 2014 Summer Case", + "Shadow Case", + "Revolver Case", + "Chroma 3 Case", + "Operation Wildfire Case", + "Gamma Case", + "Operation Hydra Case", + "Spectrum 2 Case", + "Clutch Case", + "Spectrum Case", + "Glove Case", + "Horizon Case", + "Prisma Case", + "Danger Zone Case", + "CS20 Case", + "Shattered Web Case", + "Dreams & Nightmares Case", + "Recoil Case", + "Revolution Case" ] } \ No newline at end of file From 1ff9da0546845e447bff78e3fc1faec2e340c7c8 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 7 Nov 2023 16:31:04 +0600 Subject: [PATCH 3/3] test --- handlers/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/handlers/admin.py b/handlers/admin.py index 5979efd..7fe98b2 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -10,6 +10,8 @@ router = Router() +# test commit + class ChangeAccessState(StatesGroup): get_user_id_state = State() add_admin_id_state = State()