From 64ba0845fc1a88f14c831efd8a71f63d6f297c1f Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Mon, 23 Oct 2023 18:20:40 +0600 Subject: [PATCH 01/16] fix --- handlers/admin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index ef0a5fb..c3886cf 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -86,13 +86,13 @@ async def delete_admin_state(message: Message, state: FSMContext): @router.message(F.text == "/admin_list") async def admin_list(message: Message): - owners = models.session.query(models.Users).where(models.Users.user_group == 3) - admins = models.session.query(models.Users).where(models.Users.user_group == 2) - bot_message = 'Список Админов:\n' + owners = models.session.query(models.Users).where(models.Users.group_id == 3) + admins = models.session.query(models.Users).where(models.Users.group_id == 2) + bot_message = 'Список Админов:\n\n' for admin in owners: - x = f"@{admin.nickname}: {admin.telegram_id} Owner\n" + x = f"@{admin.username}: {admin.telegram_id} Owner\n" bot_message += x for admin in admins: - x = f"@{admin.nickname}: {admin.telegram_id} Admin\n" + x = f"@{admin.username}: {admin.telegram_id} Admin\n" bot_message += x await message.answer(bot_message) From 2bb3f744361a35dd696893a760f01537f2c24465 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Mon, 23 Oct 2023 18:26:14 +0600 Subject: [PATCH 02/16] fix --- keyboards.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards.py b/keyboards.py index f3182f3..3adfe9c 100644 --- a/keyboards.py +++ b/keyboards.py @@ -71,8 +71,8 @@ ] admins_kb = ReplyKeyboardMarkup(keyboard=admin_keyboard, resize_keyboard=True) user_vip_keyboard = [ - [KeyboardButton(text="/steamid"), - KeyboardButton(text="/my_steamid")], + [KeyboardButton(text="/add_items"), + KeyboardButton(text="/my_items")], [KeyboardButton(text="/support"), KeyboardButton(text="/vip_help")] ] From a012c8a6eef6678133cce8f0c15117f6d4ee484d Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Mon, 23 Oct 2023 20:15:46 +0600 Subject: [PATCH 03/16] fix --- keyboards.py | 2 +- models.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/keyboards.py b/keyboards.py index 3adfe9c..2e6f365 100644 --- a/keyboards.py +++ b/keyboards.py @@ -71,7 +71,7 @@ ] admins_kb = ReplyKeyboardMarkup(keyboard=admin_keyboard, resize_keyboard=True) user_vip_keyboard = [ - [KeyboardButton(text="/add_items"), + [KeyboardButton(text="/add_item"), KeyboardButton(text="/my_items")], [KeyboardButton(text="/support"), KeyboardButton(text="/vip_help")] diff --git a/models.py b/models.py index 8023a0a..b0e9156 100644 --- a/models.py +++ b/models.py @@ -100,11 +100,15 @@ def add_item(telegram_id, hash_name, item_count): session = Session() user_id = get_id(telegram_id) item = session.query(Items).filter(Items.hash_name == hash_name).where(Items.user_id == user_id).first() - if item is None: + if item.hash_name is None: item = Items(user_id=user_id, hash_name=hash_name, item_count=item_count) session.add(item) session.commit() session.close() + else: + item.item_count = item_count + session.commit() + session.close() def user_items(telegram_id): From e96d211c17744723b262477b774fc849c5186dc4 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 11:15:53 +0600 Subject: [PATCH 04/16] Style --- handlers/admin.py | 4 ++-- user_list.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index c3886cf..7efa500 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -62,7 +62,7 @@ async def add_admin(message: Message, state: FSMContext): @router.message(ChangeAccessState.add_admin_id_state, F.text) async def add_admin_state(message: Message, state: FSMContext): telegram_id = int(message.text) - models.change_access(telegram_id, "Admin") + models.change_access(telegram_id, 2) await message.answer("Вы выдали админ доступ пользователю") await state.clear() @@ -79,7 +79,7 @@ async def delete_admin(message: Message, state: FSMContext): @router.message(ChangeAccessState.delete_admin_state, F.text) async def delete_admin_state(message: Message, state: FSMContext): telegram_id = message.text - models.change_access(telegram_id, "User") + models.change_access(telegram_id, 0) await message.answer("Вы удалили админ доступ у пользователя") await state.clear() diff --git a/user_list.json b/user_list.json index da113c0..c2b2d0c 100644 --- a/user_list.json +++ b/user_list.json @@ -23,6 +23,7 @@ "736491563": [ "Clutch Case", "Danger Zone Case", - "CS20 Case" + "CS20 Case", + "Operation Breakout Weapon Case" ] } \ No newline at end of file From a3ead924f79b91ee24b886188671aaf369386286 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 13:36:07 +0600 Subject: [PATCH 05/16] ref --- handlers/admin.py | 14 +++--- handlers/client.py | 4 +- handlers/vip.py | 4 +- models.py | 119 +++++++++++++++++++++------------------------ user_list.json | 15 ++---- 5 files changed, 71 insertions(+), 85 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index 7efa500..c564e0c 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -18,7 +18,7 @@ class ChangeAccessState(StatesGroup): @router.message(F.text == "/admin") async def admin_kb(message: Message): - if models.check_admin(message.from_user.id) is True: + if models.Users.check_admin(message.from_user.id) is True: await message.answer("Админ меню", reply_markup=kb.owners_kb) @@ -36,14 +36,14 @@ async def change_access(message: Message, state: FSMContext): async def change_user_access(message: Message, state: FSMContext): telegram_id = message.text telegram_id = int(telegram_id) - models.change_access(telegram_id, 1) + models.Users.change_access(telegram_id, 1) await message.answer("Вы успешно поменяли группу пользователя, на Vip") await state.clear() @router.message(F.text == "/kill") async def kill_process(message: Message): - if models.check_admin(message.from_user.id) is True: + if models.Users.check_admin(message.from_user.id) is True: await message.answer("Отключаюсь(..") sys.exit() else: @@ -52,7 +52,7 @@ async def kill_process(message: Message): @router.message(F.text == "/add_admin") async def add_admin(message: Message, state: FSMContext): - if models.check_admin(message.from_user.id) is True: + if models.Users.check_admin(message.from_user.id) is True: await message.answer("Введите айди пользователя") await state.set_state(ChangeAccessState.add_admin_id_state) else: @@ -62,14 +62,14 @@ async def add_admin(message: Message, state: FSMContext): @router.message(ChangeAccessState.add_admin_id_state, F.text) async def add_admin_state(message: Message, state: FSMContext): telegram_id = int(message.text) - models.change_access(telegram_id, 2) + models.Users.change_access(telegram_id, 2) await message.answer("Вы выдали админ доступ пользователю") await state.clear() @router.message(F.text == "/delete_admin") async def delete_admin(message: Message, state: FSMContext): - if models.check_admin(message.from_user.id) is True: + if models.Users.check_admin(message.from_user.id) is True: await message.answer("Введите айди пользователя") await state.set_state(ChangeAccessState.delete_admin_state) else: @@ -79,7 +79,7 @@ async def delete_admin(message: Message, state: FSMContext): @router.message(ChangeAccessState.delete_admin_state, F.text) async def delete_admin_state(message: Message, state: FSMContext): telegram_id = message.text - models.change_access(telegram_id, 0) + models.Users.change_access(telegram_id, 0) await message.answer("Вы удалили админ доступ у пользователя") await state.clear() diff --git a/handlers/client.py b/handlers/client.py index aa3b9a9..be52284 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -68,7 +68,7 @@ async def clear(message: Message): async def start(message: Message): telegram_id = message.from_user.id username = message.from_user.username - models.add_user(telegram_id, username) + models.Users.add_user(telegram_id, username) await message.answer("Ну привет", reply_markup=kb.main_kb) @@ -79,7 +79,7 @@ async def help_func(message: Message): @router.message(F.text == "/vip") async def get_vip(message: Message): - if models.check_vip(message.from_user.id) is True: + if models.Users.check_vip(message.from_user.id) is True: await message.answer("Вип меню", reply_markup=kb.users_vip_kb) else: await message.answer("У вас нет доступа к это команде") diff --git a/handlers/vip.py b/handlers/vip.py index 685474c..40a15ac 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -17,7 +17,7 @@ class AddInventory(StatesGroup): @router.message(F.text == "/support") async def support(message: Message): - if models.check_vip(message.from_user.id) is True: + if models.Users.check_vip(message.from_user.id) is True: await message.answer("Напишите - @ZhuchkaTriplesix") else: await message.answer("У вас нет доступа к этой команде") @@ -31,7 +31,7 @@ async def vip_help(message: Message): @router.message(F.text == "/my_items") async def my_cases(message: Message): - if models.check_vip(message.from_user.id) is True: + if models.Users.check_vip(message.from_user.id) is True: my_items = models.user_items(message.from_user.id) answer = 'Ваши предметы:\n\n' for key in my_items: diff --git a/models.py b/models.py index b0e9156..3a4b5ec 100644 --- a/models.py +++ b/models.py @@ -23,6 +23,60 @@ class Users(Base): created_date = Column(DateTime, default=datetime.datetime.utcnow) updated_at = Column(DateTime, default=datetime.datetime.utcnow) + def add_user(telegram_id, username): + session = Session() + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + if user is not None: + print("User is already in database") + else: + user = Users(telegram_id=telegram_id, username=username) + Users.add_close(user, session) + + def add_close(user, session): + session.add(user) + session.commit() + session.close() + print("Successful adding") + + def add_admin(telegram_id, username): + session = Session() + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + if user is not None: + print("User is already in database") + else: + user = Users(username=username, telegram_id=telegram_id, group_id=2) + Users.add_close(user, session) + + def change_access(telegram_id, group_id): + 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() + + def check_vip(telegram_id): + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + user_group = user.group_id + if user_group >= 1: + return True + else: + return False + + def check_admin(telegram_id): + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + user_group = user.group_id + if user_group >= 2: + return True + else: + return False + + def get_id(telegram_id): + user = session.query(Users).where(Users.telegram_id == telegram_id).first() + user_id = user.id + return user_id + class Items(Base): __tablename__ = "items" @@ -35,70 +89,9 @@ class Items(Base): Base.metadata.create_all(engine) -def add_close(user, session): - session.add(user) - session.commit() - session.close() - print("Successful adding") - - -def add_user(telegram_id, username): - session = Session() - user = session.query(Users).where(Users.telegram_id == telegram_id).first() - if user is not None: - print("User is already in database") - else: - user = Users(telegram_id=telegram_id, username=username) - add_close(user, session) - - -def add_admin(telegram_id, username): - session = Session() - user = session.query(Users).where(Users.telegram_id == telegram_id).first() - if user is not None: - print("User is already in database") - else: - user = Users(username=username, telegram_id=telegram_id, group_id=2) - add_close(user, session) - - -def change_access(telegram_id, group_id): - 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() - - -def check_vip(telegram_id): - user = session.query(Users).where(Users.telegram_id == telegram_id).first() - user_group = user.group_id - if user_group >= 1: - return True - else: - return False - - -def check_admin(telegram_id): - user = session.query(Users).where(Users.telegram_id == telegram_id).first() - user_group = user.group_id - if user_group >= 2: - return True - else: - return False - - -def get_id(telegram_id): - user = session.query(Users).where(Users.telegram_id == telegram_id).first() - user_id = user.id - return user_id - - def add_item(telegram_id, hash_name, item_count): session = Session() - user_id = get_id(telegram_id) + 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: item = Items(user_id=user_id, hash_name=hash_name, item_count=item_count) @@ -113,7 +106,7 @@ def add_item(telegram_id, hash_name, item_count): def user_items(telegram_id): session = Session() - user_id = get_id(telegram_id) + user_id = Users.get_id(telegram_id) items = session.query(Items).where(Items.user_id == user_id).all() user_item = {} for i in items: diff --git a/user_list.json b/user_list.json index c2b2d0c..b3c44f6 100644 --- a/user_list.json +++ b/user_list.json @@ -4,17 +4,6 @@ "Danger Zone Case", "Clutch Case" ], - "960622004": [ - "CS:GO Weapon Case", - "eSports 2013 Case", - "Operation Bravo Case", - "CS:GO Weapon Case 2", - "eSports 2013 Winter Case", - "Winter Offensive Weapon Case", - "CS:GO Weapon Case 3", - "Operation Phoenix Weapon Case", - "Huntsman Weapon Case" - ], "6643425631": [ "Danger Zone Case", "CS20 Case", @@ -25,5 +14,9 @@ "Danger Zone Case", "CS20 Case", "Operation Breakout Weapon Case" + ], + "960622004": [ + "Snakebite Case", + "Revolution Case" ] } \ No newline at end of file From 0baebe142fd4331a768036f10df73a96fa088727 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 14:47:18 +0600 Subject: [PATCH 06/16] ref --- handlers/vip.py | 6 +++--- models.py | 52 ++++++++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/handlers/vip.py b/handlers/vip.py index 40a15ac..764b3c1 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -32,7 +32,7 @@ async def vip_help(message: Message): @router.message(F.text == "/my_items") async def my_cases(message: Message): if models.Users.check_vip(message.from_user.id) is True: - my_items = models.user_items(message.from_user.id) + my_items = models.Items.user_items(message.from_user.id) answer = 'Ваши предметы:\n\n' for key in my_items: answer = answer + f"{key}: {my_items[key]}\n" @@ -43,7 +43,7 @@ async def my_cases(message: Message): @router.callback_query(F.data == "items_price") async def items_price(callback: CallbackQuery): - items = models.user_items(callback.from_user.id) + items = models.Items.user_items(callback.from_user.id) answer = 'Стоимость вашего инвентаря:\n\n' total = 0 for key in items: @@ -72,6 +72,6 @@ async def add_item_bd(message: Message, state: FSMContext): hash_name = mes[0] item_count = int(mes[1]) telegram_id = message.from_user.id - models.add_item(telegram_id, hash_name, item_count) + models.Items.add_item(telegram_id, hash_name, item_count) await message.answer(f"Вы добавили {hash_name}") await state.clear() diff --git a/models.py b/models.py index 3a4b5ec..6ac7237 100644 --- a/models.py +++ b/models.py @@ -85,33 +85,31 @@ class Items(Base): hash_name = Column(String(length=30)) item_count = Column(Integer) + def add_item(telegram_id, hash_name, item_count): + 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: + item = Items(user_id=user_id, hash_name=hash_name, item_count=item_count) + session.add(item) + session.commit() + session.close() + else: + item.item_count = item_count + session.commit() + session.close() -Base.metadata.create_all(engine) - - -def add_item(telegram_id, hash_name, item_count): - 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: - item = Items(user_id=user_id, hash_name=hash_name, item_count=item_count) - session.add(item) - session.commit() - session.close() - else: - item.item_count = item_count - session.commit() - session.close() + def user_items(telegram_id): + session = Session() + user_id = Users.get_id(telegram_id) + items = session.query(Items).where(Items.user_id == user_id).all() + user_item = {} + for i in items: + hash_name = i.hash_name + item_count = i.item_count + u = {hash_name: item_count} + user_item.update(u) + return user_item -def user_items(telegram_id): - session = Session() - user_id = Users.get_id(telegram_id) - items = session.query(Items).where(Items.user_id == user_id).all() - user_item = {} - for i in items: - hash_name = i.hash_name - item_count = i.item_count - u = {hash_name: item_count} - user_item.update(u) - return user_item +Base.metadata.create_all(engine) From c186d7590d9482413b51576da6bc269c62517d04 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 15:09:58 +0600 Subject: [PATCH 07/16] logs --- handlers/admin.py | 6 ++++++ handlers/client.py | 6 ++++++ handlers/vip.py | 4 ++++ models.py | 15 +++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/handlers/admin.py b/handlers/admin.py index c564e0c..8931129 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -18,12 +18,14 @@ class ChangeAccessState(StatesGroup): @router.message(F.text == "/admin") async def admin_kb(message: Message): + models.LogBase.add(message.from_user.id, message.from_user.username, "/admin") if models.Users.check_admin(message.from_user.id) is True: await message.answer("Админ меню", reply_markup=kb.owners_kb) @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.check_admin(telegram_id) is True: await message.answer("Введите айди пользователя") @@ -43,6 +45,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: await message.answer("Отключаюсь(..") sys.exit() @@ -52,6 +55,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: await message.answer("Введите айди пользователя") await state.set_state(ChangeAccessState.add_admin_id_state) @@ -69,6 +73,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: await message.answer("Введите айди пользователя") await state.set_state(ChangeAccessState.delete_admin_state) @@ -86,6 +91,7 @@ async def delete_admin_state(message: Message, state: FSMContext): @router.message(F.text == "/admin_list") async def admin_list(message: Message): + models.LogBase.add(message.from_user.id, message.from_user.username, "admin_list") owners = models.session.query(models.Users).where(models.Users.group_id == 3) admins = models.session.query(models.Users).where(models.Users.group_id == 2) bot_message = 'Список Админов:\n\n' diff --git a/handlers/client.py b/handlers/client.py index be52284..388313a 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -17,6 +17,7 @@ async def cases(message: Message): x = '' user_id = f"{message.from_user.id}" + models.LogBase.add(message.from_user.id, message.from_user.username, "/cases") data = json_support.read_inf(json_data) if user_id in data.keys() and len(data[user_id]) > 0: for case in data[user_id]: @@ -30,6 +31,7 @@ async def cases(message: Message): @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) @@ -57,6 +59,7 @@ async def answer(callback: CallbackQuery): @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) user_id = f"{message.from_user.id}" del data[user_id] @@ -66,6 +69,7 @@ async def clear(message: Message): @router.message(F.text == "/start") async def start(message: Message): + models.LogBase.add(message.from_user.id, message.from_user.username, "/start") telegram_id = message.from_user.id username = message.from_user.username models.Users.add_user(telegram_id, username) @@ -74,11 +78,13 @@ 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("Помогите...") @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: await message.answer("Вип меню", reply_markup=kb.users_vip_kb) else: diff --git a/handlers/vip.py b/handlers/vip.py index 764b3c1..281c2a4 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -17,6 +17,7 @@ class AddInventory(StatesGroup): @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: await message.answer("Напишите - @ZhuchkaTriplesix") else: @@ -25,12 +26,14 @@ async def support(message: Message): @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( "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/steam_id - Поменять стим айди (по умолчанию его нет)\n/my_steamid - Ваш стим айди") @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: my_items = models.Items.user_items(message.from_user.id) answer = 'Ваши предметы:\n\n' @@ -60,6 +63,7 @@ async def items_price(callback: CallbackQuery): @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( "Напишите название предмета на англ и через . кол-во\nПримеры написания:\nClutch Case.100\nFracture Case.10") await state.set_state(AddInventory.add_item_state) diff --git a/models.py b/models.py index 6ac7237..a684b97 100644 --- a/models.py +++ b/models.py @@ -112,4 +112,19 @@ def user_items(telegram_id): return user_item +class LogBase(Base): + __tablename__ = "functions_log" + id = Column(Integer, primary_key=True) + telegram_id = Column(BigInteger, index=True) + username = Column(String(length=32)) + function_name = Column(String(length=12)) + + def add(telegram_id, username, function_name): + session = Session() + func = LogBase(telegram_id=telegram_id, username=username, function_name=function_name) + session.add(func) + session.commit() + session.close() + + Base.metadata.create_all(engine) From 7dd6b248c0dd7f0a8f4463afecaf9ae3cd0af249 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 15:28:55 +0600 Subject: [PATCH 08/16] logs --- handlers/client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/handlers/client.py b/handlers/client.py index 388313a..603e3be 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -17,6 +17,7 @@ async def cases(message: Message): x = '' user_id = f"{message.from_user.id}" + models.Users.add_user(message.from_user.id, message.from_user.username) models.LogBase.add(message.from_user.id, message.from_user.username, "/cases") data = json_support.read_inf(json_data) if user_id in data.keys() and len(data[user_id]) > 0: @@ -70,9 +71,7 @@ async def clear(message: Message): @router.message(F.text == "/start") async def start(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/start") - telegram_id = message.from_user.id - username = message.from_user.username - models.Users.add_user(telegram_id, username) + models.Users.add_user(message.from_user.id, message.from_user.username) await message.answer("Ну привет", reply_markup=kb.main_kb) From 94236238486cc79b8e3d6ba5d3d57deaaab7ff23 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 15:59:42 +0600 Subject: [PATCH 09/16] ref --- handlers/vip.py | 2 +- user_list.json | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/handlers/vip.py b/handlers/vip.py index 281c2a4..8079751 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -28,7 +28,7 @@ async def support(message: Message): async def vip_help(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/vip_help") await message.answer( - "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/steam_id - Поменять стим айди (по умолчанию его нет)\n/my_steamid - Ваш стим айди") + "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - добавить предметы\n/my_items - ваши предметы") @router.message(F.text == "/my_items") diff --git a/user_list.json b/user_list.json index b3c44f6..e92a4a4 100644 --- a/user_list.json +++ b/user_list.json @@ -9,14 +9,13 @@ "CS20 Case", "Clutch Case" ], - "736491563": [ - "Clutch Case", - "Danger Zone Case", - "CS20 Case", - "Operation Breakout Weapon Case" - ], "960622004": [ "Snakebite Case", "Revolution Case" + ], + "736491563": [ + "Danger Zone Case", + "Clutch Case", + "CS20 Case" ] } \ No newline at end of file From 5174b006d7cc3f0e18cadb2f264ff1fd663da9c1 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:00:54 +0600 Subject: [PATCH 10/16] style --- handlers/vip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/vip.py b/handlers/vip.py index 8079751..812ab5a 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -28,7 +28,7 @@ async def support(message: Message): async def vip_help(message: Message): models.LogBase.add(message.from_user.id, message.from_user.username, "/vip_help") await message.answer( - "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - добавить предметы\n/my_items - ваши предметы") + "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - Добавить предметы\n/my_items - Ваши предметы") @router.message(F.text == "/my_items") From 6574dfcd10091cb91e68c81411743a57caff63b7 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:13:25 +0600 Subject: [PATCH 11/16] ref --- models.py | 18 +++++++++--------- user_list.json | 4 +--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/models.py b/models.py index a684b97..62f5fe9 100644 --- a/models.py +++ b/models.py @@ -23,7 +23,7 @@ class Users(Base): created_date = Column(DateTime, default=datetime.datetime.utcnow) updated_at = Column(DateTime, default=datetime.datetime.utcnow) - def add_user(telegram_id, username): + 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: @@ -38,7 +38,7 @@ def add_close(user, session): session.close() print("Successful adding") - def add_admin(telegram_id, username): + def add_admin(telegram_id: int, username: str): session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -47,7 +47,7 @@ def add_admin(telegram_id, username): user = Users(username=username, telegram_id=telegram_id, group_id=2) Users.add_close(user, session) - def change_access(telegram_id, group_id): + def change_access(telegram_id: int, group_id: int): session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -56,7 +56,7 @@ def change_access(telegram_id, group_id): session.commit() session.close() - def check_vip(telegram_id): + def check_vip(telegram_id: int) -> object: user = session.query(Users).where(Users.telegram_id == telegram_id).first() user_group = user.group_id if user_group >= 1: @@ -64,7 +64,7 @@ def check_vip(telegram_id): else: return False - def check_admin(telegram_id): + def check_admin(telegram_id: int) -> object: user = session.query(Users).where(Users.telegram_id == telegram_id).first() user_group = user.group_id if user_group >= 2: @@ -72,7 +72,7 @@ def check_admin(telegram_id): else: return False - def get_id(telegram_id): + def get_id(telegram_id: int) -> object: user = session.query(Users).where(Users.telegram_id == telegram_id).first() user_id = user.id return user_id @@ -85,7 +85,7 @@ class Items(Base): hash_name = Column(String(length=30)) item_count = Column(Integer) - def add_item(telegram_id, hash_name, item_count): + 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() @@ -99,7 +99,7 @@ def add_item(telegram_id, hash_name, item_count): session.commit() session.close() - def user_items(telegram_id): + def user_items(telegram_id: int): session = Session() user_id = Users.get_id(telegram_id) items = session.query(Items).where(Items.user_id == user_id).all() @@ -119,7 +119,7 @@ class LogBase(Base): username = Column(String(length=32)) function_name = Column(String(length=12)) - def add(telegram_id, username, function_name): + def add(telegram_id: int, username: str, function_name: str) -> object: session = Session() func = LogBase(telegram_id=telegram_id, username=username, function_name=function_name) session.add(func) diff --git a/user_list.json b/user_list.json index e92a4a4..b8dbe94 100644 --- a/user_list.json +++ b/user_list.json @@ -14,8 +14,6 @@ "Revolution Case" ], "736491563": [ - "Danger Zone Case", - "Clutch Case", - "CS20 Case" + "Operation Breakout Weapon Case" ] } \ No newline at end of file From 1ff580483316c967b3a1f2b28647676f7d763f56 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:16:56 +0600 Subject: [PATCH 12/16] ref --- handlers/admin.py | 2 +- models.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index 8931129..4e03179 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -27,7 +27,7 @@ async def admin_kb(message: Message): 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.check_admin(telegram_id) is True: + if models.Users.check_admin(telegram_id) is True: await message.answer("Введите айди пользователя") await state.set_state(ChangeAccessState.get_user_id_state) else: diff --git a/models.py b/models.py index 62f5fe9..b7680a0 100644 --- a/models.py +++ b/models.py @@ -23,7 +23,7 @@ class Users(Base): created_date = Column(DateTime, default=datetime.datetime.utcnow) updated_at = Column(DateTime, default=datetime.datetime.utcnow) - def add_user(telegram_id: int, username: str): + def add_user(telegram_id: int, username: str) -> object: session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -38,7 +38,7 @@ def add_close(user, session): session.close() print("Successful adding") - def add_admin(telegram_id: int, username: str): + def add_admin(telegram_id: int, username: str) -> object: session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -47,7 +47,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: @@ -85,7 +85,7 @@ 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): + def add_item(telegram_id: int, hash_name: str, item_count: int) -> object: 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() @@ -99,7 +99,7 @@ def add_item(telegram_id: int, hash_name: str, item_count: int): session.commit() session.close() - def user_items(telegram_id: int): + def user_items(telegram_id: int) -> object: session = Session() user_id = Users.get_id(telegram_id) items = session.query(Items).where(Items.user_id == user_id).all() From e8e1ff20f706816e305578e013253625ab30b2f7 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:20:57 +0600 Subject: [PATCH 13/16] style --- models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models.py b/models.py index b7680a0..7aec10b 100644 --- a/models.py +++ b/models.py @@ -14,6 +14,7 @@ conn = engine.connect() +# noinspection PyTypeChecker,PyMethodParameters,PyShadowingNames class Users(Base): __tablename__ = "users" id = Column(Integer, primary_key=True) @@ -23,7 +24,7 @@ class Users(Base): created_date = Column(DateTime, default=datetime.datetime.utcnow) updated_at = Column(DateTime, default=datetime.datetime.utcnow) - def add_user(telegram_id: int, username: str) -> object: + 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: @@ -38,7 +39,7 @@ def add_close(user, session): session.close() print("Successful adding") - def add_admin(telegram_id: int, username: str) -> object: + def add_admin(telegram_id: int, username: str): session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -47,7 +48,7 @@ def add_admin(telegram_id: int, username: str) -> object: 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) -> object: + def change_access(telegram_id: int, group_id: int): session = Session() user = session.query(Users).where(Users.telegram_id == telegram_id).first() if user is not None: @@ -78,6 +79,7 @@ def get_id(telegram_id: int) -> object: return user_id +# noinspection PyTypeChecker,PyShadowingNames,PyMethodParameters class Items(Base): __tablename__ = "items" id = Column(Integer, primary_key=True) @@ -112,6 +114,7 @@ def user_items(telegram_id: int) -> object: return user_item +# noinspection PyShadowingNames,PyMethodParameters class LogBase(Base): __tablename__ = "functions_log" id = Column(Integer, primary_key=True) @@ -119,7 +122,7 @@ class LogBase(Base): username = Column(String(length=32)) function_name = Column(String(length=12)) - def add(telegram_id: int, username: str, function_name: str) -> object: + def add(telegram_id: int, username: str, function_name: str): session = Session() func = LogBase(telegram_id=telegram_id, username=username, function_name=function_name) session.add(func) From 8c41453de9621afbc4f38e86e93b657e1b535e25 Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:24:07 +0600 Subject: [PATCH 14/16] style --- handlers/vip.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/handlers/vip.py b/handlers/vip.py index 812ab5a..c0ce687 100644 --- a/handlers/vip.py +++ b/handlers/vip.py @@ -31,6 +31,7 @@ async def vip_help(message: Message): "Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - Добавить предметы\n/my_items - Ваши предметы") +# noinspection PyTypeChecker @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") @@ -44,6 +45,7 @@ async def my_cases(message: Message): await message.answer("У вас нет доступа к этой команде") +# noinspection PyTypeChecker @router.callback_query(F.data == "items_price") async def items_price(callback: CallbackQuery): items = models.Items.user_items(callback.from_user.id) From cf39de7ac2bb3de8a654202b3f13e10fe123657b Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:24:46 +0600 Subject: [PATCH 15/16] style --- handlers/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/admin.py b/handlers/admin.py index 4e03179..b2f7cd1 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -83,7 +83,7 @@ async def delete_admin(message: Message, state: FSMContext): @router.message(ChangeAccessState.delete_admin_state, F.text) async def delete_admin_state(message: Message, state: FSMContext): - telegram_id = message.text + telegram_id = int(message.text) models.Users.change_access(telegram_id, 0) await message.answer("Вы удалили админ доступ у пользователя") await state.clear() From 469f65482a2dcaa98cfcaedf640c50c032fce56d Mon Sep 17 00:00:00 2001 From: JuntexZhuk Date: Tue, 24 Oct 2023 16:25:10 +0600 Subject: [PATCH 16/16] style --- handlers/client.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/handlers/client.py b/handlers/client.py index 603e3be..64cd5f7 100644 --- a/handlers/client.py +++ b/handlers/client.py @@ -1,13 +1,10 @@ from aiogram import F -from aiogram.fsm.state import StatesGroup, State from aiogram.types import Message, CallbackQuery import steammarket as sm from data import json_support, case_translation import keyboards as kb from aiogram import Router -from aiogram.fsm.context import FSMContext import models -from data.config import cases as constcases router = Router() json_data = "user_list.json"