diff --git a/handlers/admin.py b/handlers/admin.py index b2f7cd1..0f9dd8a 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -28,7 +28,7 @@ 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: - await message.answer("Введите айди пользователя") + await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.get_user_id_state) else: await message.answer("У вас нет доступа к этой команде.") @@ -37,10 +37,13 @@ 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 - telegram_id = int(telegram_id) - models.Users.change_access(telegram_id, 1) - await message.answer("Вы успешно поменяли группу пользователя, на Vip") - await state.clear() + try: + telegram_id = int(telegram_id) + models.Users.change_access(telegram_id, 1) + await message.answer("Вы успешно поменяли группу пользователя, на Vip.") + await state.clear() + except ValueError: + await message.answer("Неверный телеграм айди.") @router.message(F.text == "/kill") @@ -50,43 +53,49 @@ async def kill_process(message: Message): await message.answer("Отключаюсь(..") sys.exit() else: - await message.answer("У вас нет доступа к этой команде") + await message.answer("У вас нет доступа к этой команде.") @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: - await message.answer("Введите айди пользователя") + await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.add_admin_id_state) else: - await message.answer("У вас нет доступа к этой команде") + await message.answer("У вас нет доступа к этой команде.") @router.message(ChangeAccessState.add_admin_id_state, F.text) async def add_admin_state(message: Message, state: FSMContext): - telegram_id = int(message.text) - models.Users.change_access(telegram_id, 2) - await message.answer("Вы выдали админ доступ пользователю") - await state.clear() + try: + telegram_id = int(message.text) + models.Users.change_access(telegram_id, 2) + await message.answer("Вы выдали админ доступ пользователю.") + await state.clear() + except ValueError: + await message.answer("Неверный телеграм айди.") @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: - await message.answer("Введите айди пользователя") + await message.answer("Введите айди пользователя.") await state.set_state(ChangeAccessState.delete_admin_state) else: - await message.answer("У вас нет доступа к этой команде") + await message.answer("У вас нет доступа к этой команде.") @router.message(ChangeAccessState.delete_admin_state, F.text) async def delete_admin_state(message: Message, state: FSMContext): - telegram_id = int(message.text) - models.Users.change_access(telegram_id, 0) - await message.answer("Вы удалили админ доступ у пользователя") - await state.clear() + try: + telegram_id = int(message.text) + models.Users.change_access(telegram_id, 0) + await message.answer("Вы удалили админ доступ у пользователя.") + await state.clear() + except ValueError: + await message.answer("Неверный телеграм айди.") @router.message(F.text == "/admin_list") diff --git a/handlers/client.py b/handlers/client.py index 64cd5f7..488f268 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -10,7 +10,7 @@ json_data = "user_list.json" -@router.message(F.text == '/cases') +@router.message(F.text == '💵CASES💵') async def cases(message: Message): x = '' user_id = f"{message.from_user.id}" @@ -27,7 +27,7 @@ async def cases(message: Message): await message.answer("Вы не добавили кейсы.") -@router.message(F.text == "/add_case") +@router.message(F.text == "➕ADD CASE➕") async def item_list(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/add_case") await message.answer("Какой кейс вы хотите добавить?:", reply_markup=kb.cases) @@ -55,7 +55,7 @@ async def answer(callback: CallbackQuery): pass -@router.message(F.text == '/clear') +@router.message(F.text == '🗑CLEAR🗑') async def clear(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/clear") data = json_support.read_inf(json_data) @@ -75,10 +75,10 @@ async def start(message: Message): @router.message(F.text == "/help") async def help_func(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/help") - await message.answer("Помогите...") + await message.answer("А кнопки я зачем называл?") -@router.message(F.text == "/vip") +@router.message(F.text == "💎VIP💎") async def get_vip(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/vip") if models.Users.check_vip(message.from_user.id) is True: diff --git a/handlers/vip.py b/handlers/vip.py index c0ce687..393ab8f 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -13,9 +13,10 @@ class AddInventory(StatesGroup): add_item_state = State() + delete_item_state = State() -@router.message(F.text == "/support") +@router.message(F.text == "⁉️SUPPORT⁉️") async def support(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/support") if models.Users.check_vip(message.from_user.id) is True: @@ -24,7 +25,7 @@ async def support(message: Message): await message.answer("У вас нет доступа к этой команде") -@router.message(F.text == "/vip_help") +@router.message(F.text == "❓VIP HELP❓") async def vip_help(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/vip_help") await message.answer( @@ -32,7 +33,7 @@ async def vip_help(message: Message): # noinspection PyTypeChecker -@router.message(F.text == "/my_items") +@router.message(F.text == "📈MY ITEMS📈") async def my_cases(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/my_items") if models.Users.check_vip(message.from_user.id) is True: @@ -63,7 +64,7 @@ async def items_price(callback: CallbackQuery): await callback.message.answer(answer) -@router.message(F.text == "/add_item") +@router.message(F.text == "➕ADD ITEM➕") async def add_item(message: Message, state: FSMContext): models.LogBase.add(message.from_user.id, message.from_user.username, "/add_item") await message.answer( @@ -76,8 +77,29 @@ async def add_item_bd(message: Message, state: FSMContext): mes = message.text.split(".") print(mes) hash_name = mes[0] - item_count = int(mes[1]) - telegram_id = message.from_user.id - models.Items.add_item(telegram_id, hash_name, item_count) - await message.answer(f"Вы добавили {hash_name}") + try: + item_count = int(mes[1]) + telegram_id = message.from_user.id + models.Items.add_item(telegram_id, hash_name, item_count) + await message.answer(f"Вы добавили {hash_name}") + await state.clear() + except ValueError: + await message.answer("Ошибка ввода") + await state.clear() + + +@router.message(F.text == "❌DELETE❌") +async def delete_item(message: Message, state: FSMContext): + models.LogBase.add(message.from_user.id, message.from_user.username, "/delete") + if models.Users.check_vip(message.from_user.id) is True: + await message.answer("Введите название предмета.") + await state.set_state(AddInventory.delete_item_state) + else: + await message.answer("У вас недостаточно прав.") + + +@router.message(AddInventory.delete_item_state, F.text) +async def delete_item_state(message: Message, state: FSMContext): + models.Items.delete_item(message.from_user.id, message.text) + await message.answer(f"Вы успешно удалили {message.text}") await state.clear() diff --git a/keyboards.py b/keyboards.py index 2e6f365..e23ceec 100644 --- a/keyboards.py +++ b/keyboards.py @@ -2,11 +2,11 @@ InlineKeyboardMarkup, InlineKeyboardButton) main = [ - [KeyboardButton(text="/cases"), - KeyboardButton(text="/add_case")], + [KeyboardButton(text="💵CASES💵"), + KeyboardButton(text="➕ADD CASE➕")], [ - KeyboardButton(text="/clear"), - KeyboardButton(text="/vip")] + KeyboardButton(text="🗑CLEAR🗑"), + KeyboardButton(text="💎VIP💎")] ] main_kb = ReplyKeyboardMarkup(keyboard=main, resize_keyboard=True) cases_inline = [ @@ -71,9 +71,10 @@ ] admins_kb = ReplyKeyboardMarkup(keyboard=admin_keyboard, resize_keyboard=True) user_vip_keyboard = [ - [KeyboardButton(text="/add_item"), - KeyboardButton(text="/my_items")], - [KeyboardButton(text="/support"), - KeyboardButton(text="/vip_help")] + [KeyboardButton(text="➕ADD ITEM➕"), + KeyboardButton(text="📈MY ITEMS📈")], + [KeyboardButton(text="❌DELETE❌"), + KeyboardButton(text="⁉️SUPPORT⁉️"), + KeyboardButton(text="❓VIP HELP❓")] ] users_vip_kb = ReplyKeyboardMarkup(keyboard=user_vip_keyboard, resize_keyboard=True) diff --git a/models.py b/models.py index 7aec10b..a0cfb12 100644 --- a/models.py +++ b/models.py @@ -28,7 +28,7 @@ def add_user(telegram_id: int, username: str): session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: - print("User is already in database") + pass else: user = Users(telegram_id=telegram_id, username=username) Users.add_close(user, session) @@ -37,7 +37,6 @@ def add_close(user, session): session.add(user) session.commit() session.close() - print("Successful adding") def add_admin(telegram_id: int, username: str): session = Session() @@ -87,11 +86,11 @@ class Items(Base): hash_name = Column(String(length=30)) item_count = Column(Integer) - def add_item(telegram_id: int, hash_name: str, item_count: int) -> object: + def add_item(telegram_id: int, hash_name: str, item_count: int): session = Session() user_id = Users.get_id(telegram_id) item = session.query(Items).filter(Items.hash_name == hash_name).where(Items.user_id == user_id).first() - if item.hash_name is None: + if item is None: item = Items(user_id=user_id, hash_name=hash_name, item_count=item_count) session.add(item) session.commit() @@ -113,6 +112,13 @@ def user_items(telegram_id: int) -> object: user_item.update(u) return user_item + def delete_item(telegram_id: int, hash_name: str): + session = Session() + user_id = Users.get_id(telegram_id) + item = session.query(Items).filter(Items.hash_name == hash_name).where(Items.user_id == user_id).first() + session.delete(item) + session.commit() + # noinspection PyShadowingNames,PyMethodParameters class LogBase(Base): diff --git a/user_list.json b/user_list.json index b8dbe94..7c1a729 100644 --- a/user_list.json +++ b/user_list.json @@ -12,8 +12,5 @@ "960622004": [ "Snakebite Case", "Revolution Case" - ], - "736491563": [ - "Operation Breakout Weapon Case" ] } \ No newline at end of file