Skip to content

Commit

Permalink
Merge pull request #54 from ZhuchkaTriplesix/develop
Browse files Browse the repository at this point in the history
New Database logs
Refactor to oop
  • Loading branch information
ZhuchkaTriplesix authored Oct 24, 2023
2 parents 5851547 + 469f654 commit 21a70ec
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 126 deletions.
34 changes: 20 additions & 14 deletions handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class ChangeAccessState(StatesGroup):

@router.message(F.text == "/admin")
async def admin_kb(message: Message):
if models.check_admin(message.from_user.id) is True:
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:
if models.Users.check_admin(telegram_id) is True:
await message.answer("Введите айди пользователя")
await state.set_state(ChangeAccessState.get_user_id_state)
else:
Expand All @@ -36,14 +38,15 @@ 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:
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()
else:
Expand All @@ -52,7 +55,8 @@ 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:
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)
else:
Expand All @@ -62,14 +66,15 @@ 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.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:
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)
else:
Expand All @@ -78,21 +83,22 @@ 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")
telegram_id = int(message.text)
models.Users.change_access(telegram_id, 0)
await message.answer("Вы удалили админ доступ у пользователя")
await state.clear()


@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'
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'
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)
16 changes: 9 additions & 7 deletions handlers/client.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -17,6 +14,8 @@
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:
for case in data[user_id]:
Expand All @@ -30,6 +29,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)


Expand Down Expand Up @@ -57,6 +57,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]
Expand All @@ -66,20 +67,21 @@ async def clear(message: Message):

@router.message(F.text == "/start")
async def start(message: Message):
telegram_id = message.from_user.id
username = message.from_user.username
models.add_user(telegram_id, username)
models.LogBase.add(message.from_user.id, message.from_user.username, "/start")
models.Users.add_user(message.from_user.id, message.from_user.username)
await message.answer("Ну привет", reply_markup=kb.main_kb)


@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):
if models.check_vip(message.from_user.id) is True:
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:
await message.answer("У вас нет доступа к это команде")
Expand Down
18 changes: 12 additions & 6 deletions handlers/vip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ class AddInventory(StatesGroup):

@router.message(F.text == "/support")
async def support(message: Message):
if models.check_vip(message.from_user.id) is True:
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:
await message.answer("У вас нет доступа к этой команде")


@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 - Ваш стим айди")
"Команды для Vip пользователей:\n/support - Персональная помощь с ботом\n/add_item - Добавить предметы\n/my_items - Ваши предметы")


# noinspection PyTypeChecker
@router.message(F.text == "/my_items")
async def my_cases(message: Message):
if models.check_vip(message.from_user.id) is True:
my_items = models.user_items(message.from_user.id)
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'
for key in my_items:
answer = answer + f"{key}: {my_items[key]}\n"
Expand All @@ -41,9 +45,10 @@ 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.user_items(callback.from_user.id)
items = models.Items.user_items(callback.from_user.id)
answer = 'Стоимость вашего инвентаря:\n\n'
total = 0
for key in items:
Expand All @@ -60,6 +65,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)
Expand All @@ -72,6 +78,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()
4 changes: 2 additions & 2 deletions keyboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_item"),
KeyboardButton(text="/my_items")],
[KeyboardButton(text="/support"),
KeyboardButton(text="/vip_help")]
]
Expand Down
Loading

0 comments on commit 21a70ec

Please sign in to comment.