Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
ZhuchkaTriplesix authored Oct 25, 2023
2 parents 7148503 + 6dbcc6f commit 5573c62
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
45 changes: 29 additions & 16 deletions handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,20 +35,24 @@ 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)
models.Users.change_access(telegram_id, 1)
await message.answer("Вы успешно поменяли группу пользователя, на Vip.")
await state.clear()
telegram_id = int(message.text)
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")
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:
Expand All @@ -59,7 +62,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:
Expand All @@ -70,17 +73,22 @@ 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")
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:
Expand All @@ -91,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
4 changes: 2 additions & 2 deletions handlers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async def item_list(message: Message):

@router.callback_query()
async def answer(callback: CallbackQuery):
user_id = callback.message.chat.id
user_id = f"{user_id}"
models.LogBase.add(callback.from_user.id, callback.from_user.username, "add_callback")
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)
Expand Down
2 changes: 1 addition & 1 deletion handlers/vip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,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])
Expand Down
15 changes: 14 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -47,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 All @@ -64,6 +68,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
Expand Down Expand Up @@ -127,6 +139,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()
Expand Down
5 changes: 5 additions & 0 deletions user_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
"960622004": [
"Snakebite Case",
"Revolution Case"
],
"736491563": [
"Clutch Case",
"Danger Zone Case",
"CS20 Case"
]
}

0 comments on commit 5573c62

Please sign in to comment.