Skip to content

Commit

Permalink
Merge pull request #56 from ZhuchkaTriplesix/develop
Browse files Browse the repository at this point in the history
Buttons + delete item
  • Loading branch information
ZhuchkaTriplesix authored Oct 25, 2023
2 parents 21a70ec + a9cab36 commit aede89d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 46 deletions.
45 changes: 27 additions & 18 deletions handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("У вас нет доступа к этой команде.")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions handlers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
38 changes: 30 additions & 8 deletions handlers/vip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -24,15 +25,15 @@ 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(
"Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - Добавить предметы\n/my_items - Ваши предметы")


# 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:
Expand Down Expand Up @@ -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(
Expand All @@ -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()
17 changes: 9 additions & 8 deletions keyboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
14 changes: 10 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions user_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
"960622004": [
"Snakebite Case",
"Revolution Case"
],
"736491563": [
"Operation Breakout Weapon Case"
]
}

0 comments on commit aede89d

Please sign in to comment.