Skip to content

Commit

Permalink
Merge pull request #1 from BaggerFast/feature/bober
Browse files Browse the repository at this point in the history
Feature/bober
  • Loading branch information
BaggerFast authored Jan 22, 2024
2 parents e858858 + 7b300d6 commit d4f50f5
Show file tree
Hide file tree
Showing 38 changed files with 293 additions and 600 deletions.
6 changes: 1 addition & 5 deletions telegram_bot/database/methods/create.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sqlalchemy.exc

from telegram_bot.database.main import Database
from telegram_bot.database.models import User, Session, Payment
from telegram_bot.database.models import User, Session


def create_user(telegram_id: int) -> None:
Expand All @@ -19,7 +19,3 @@ def create_session(user: User, user_bot_session: str) -> None:
session.commit()


def create_user_payment(user: User, key) -> None:
session = Database().session
session.add(Payment(user_id=user.id, key=key))
session.commit()
3 changes: 1 addition & 2 deletions telegram_bot/database/methods/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def get_sessions_count() -> int:
return Database().session.query(User.session).join(User.session).where(User.admin == 0).count()


def get_sessions_enable_count(vip: bool) -> int:
def get_sessions_enable_count() -> int:
return Database().session.query(User).filter(
User.vip == int(vip),
User.admin == 0,
User.session.has(Session.enable == 1)
).count()
12 changes: 0 additions & 12 deletions telegram_bot/database/methods/other.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
from telegram_bot.database.models import User
from telegram_bot.database.main import Database
from telegram_bot.database.methods.get import get_user_by_telegram_id


def is_vip(telegram_id) -> bool:
return bool(Database().session.query(User.vip).filter(User.telegram_id == telegram_id).one()[0])


def is_admin(telegram_id: int) -> bool:
return bool(Database().session.query(User.admin).filter(User.telegram_id == telegram_id).one()[0])


def switch_vip(telegram_id: int):
user = get_user_by_telegram_id(telegram_id)
if user:
user.vip = not user.vip
Database().session.commit()
5 changes: 0 additions & 5 deletions telegram_bot/database/methods/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
from telegram_bot.database.models import User


def set_vip(telegram_id: int) -> None:
Database().session.query(User).filter(User.telegram_id == telegram_id).update(values={User.vip: 1})
Database().session.commit()


def set_admin(telegram_id: int) -> None:
Database().session.query(User).filter(User.telegram_id == telegram_id).update(values={User.admin: 1})
Database().session.commit()
Expand Down
9 changes: 0 additions & 9 deletions telegram_bot/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class User(Database.BASE):
__tablename__ = 'USER'
id = Column(Integer, primary_key=True)
telegram_id = Column(Integer, nullable=False)
vip = Column(Integer, default=0)
admin = Column(Integer, default=0)
session = relationship('Session', uselist=False, backref="USER", passive_deletes=True)
payment = relationship('Payment', uselist=False, backref="USER", passive_deletes=True)


class Session(Database.BASE):
Expand All @@ -22,12 +20,5 @@ class Session(Database.BASE):
enable = Column(Integer, default=0)


class Payment(Database.BASE):
__tablename__ = 'PAYMENT'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('USER.id', ondelete='CASCADE'), unique=True)
key = Column(String, unique=True)


def register_models():
Database.BASE.metadata.create_all(Database().engine)
10 changes: 1 addition & 9 deletions telegram_bot/filters/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from aiogram.dispatcher.filters import Filter
from aiogram.types import Message

from telegram_bot.database.methods.other import is_admin, is_vip
from telegram_bot.database.methods.other import is_admin


class IsAdmin(Filter):
Expand All @@ -19,18 +19,10 @@ async def check(self, message: Message) -> bool:
return False if is_admin(message.from_user.id) else True


class NotVip(Filter):
key = "not_vip"

async def check(self, message: Message) -> bool:
return False if is_vip(message.from_user.id) else True


def register_all_filters(dp: Dispatcher):
filters = (
NotAdmin,
IsAdmin,
NotVip
)
for filter in filters:
dp.bind_filter(filter)
4 changes: 1 addition & 3 deletions telegram_bot/handlers/admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from aiogram.dispatcher import FSMContext
from aiogram.types import Message, CallbackQuery, ReplyKeyboardRemove

from telegram_bot.database.methods.update import set_admin, set_vip
from telegram_bot.database.methods.update import set_admin
from telegram_bot.filters.main import IsAdmin

from telegram_bot.utils.env import Env
Expand All @@ -25,7 +25,6 @@ async def __admin_auth(msg: Message, state: FSMContext):
if user_id != Env.ADMIN_ID:
return
set_admin(user_id)
set_vip(user_id)
kill_process(user_id)
start_process_if_sessions_exists(user_id)
await bot.send_message(user_id, "Добро пожаловать хозяин! 😜", reply_markup=get_main_keyboard(user_id))
Expand Down Expand Up @@ -54,7 +53,6 @@ def _get_auth_handlers(dp: Dispatcher) -> None:
dp.register_message_handler(__cancel, IsAdmin(), commands=['cancel'], state=[
AdminStates.INSERT_NEW_ADMIN,
AdminStates.INSERT_ADVERT_TEXT,
AdminStates.SET_VIP,
])
dp.register_message_handler(__admin, IsAdmin(), content_types=['text'], text='Admin 🤡', state=None)

Expand Down
11 changes: 2 additions & 9 deletions telegram_bot/handlers/admin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from aiogram.dispatcher import FSMContext
from aiogram.types import Message, CallbackQuery

from telegram_bot.database.methods.update import set_admin, set_vip
from telegram_bot.database.methods.update import set_admin
from telegram_bot.database.methods.get import get_all_telegram_id, get_sessions_enable_count, get_user_count, \
get_sessions_count
from telegram_bot.filters.main import IsAdmin

from telegram_bot.handlers.admin.vip import _get_vip_handlers
from telegram_bot.handlers.admin.auth import _get_auth_handlers

from telegram_bot.utils.states import AdminStates
Expand All @@ -33,7 +32,6 @@ async def __admin_insert_tg_id(msg: Message, state: FSMContext):
admin_id = int(msg.text)
try:
set_admin(admin_id)
set_vip(admin_id)
kill_process(admin_id)
start_process_if_sessions_exists(admin_id)
await state.finish()
Expand Down Expand Up @@ -79,16 +77,12 @@ async def __do_advertising(query: Message, state: FSMContext):
async def __analytic(query: CallbackQuery, state: FSMContext) -> None:
users_count = get_user_count()
user_session_count = get_sessions_count()
vip_session_enable_count = get_sessions_enable_count(True)
free_session_enable_count = get_sessions_enable_count(False)
session_enable_count = vip_session_enable_count + free_session_enable_count
session_enable_count = get_sessions_enable_count()

text = (
'Отчет:\n',
f'Кол-во пользователей: {users_count}',
f'Кол-во сессий: {user_session_count}\n',
f'VIP онлайн: {vip_session_enable_count}',
f'Free онлайн: {free_session_enable_count}',
f'Total онлайн: {session_enable_count}',
)
await query.answer('\n'.join(text), show_alert=True, cache_time=0)
Expand Down Expand Up @@ -117,4 +111,3 @@ def register_admin_handlers(dp: Dispatcher) -> None:
# endregion

_get_auth_handlers(dp)
_get_vip_handlers(dp)
67 changes: 0 additions & 67 deletions telegram_bot/handlers/admin/vip.py

This file was deleted.

64 changes: 0 additions & 64 deletions telegram_bot/handlers/user/buy_vip.py

This file was deleted.

4 changes: 1 addition & 3 deletions telegram_bot/handlers/user/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from aiogram import Dispatcher, Bot
from aiogram.types import Message

from telegram_bot.handlers.user.buy_vip import _register_vip_handlers
from telegram_bot.handlers.user.user_bot import _register_user_bot_handlers

from telegram_bot.utils import TgConfig
Expand All @@ -25,7 +24,7 @@ async def __teh_support(msg: Message) -> None:

async def __help(msg: Message) -> None:
bot: Bot = msg.bot
await bot.send_message(msg.from_user.id, "Выберите категорию команд:", reply_markup=KB_INFO)
await bot.send_message(msg.from_user.id, "Список комманд бота", reply_markup=KB_INFO)


def register_users_handlers(dp: Dispatcher) -> None:
Expand All @@ -42,5 +41,4 @@ def register_users_handlers(dp: Dispatcher) -> None:

# endregion

_register_vip_handlers(dp)
_register_user_bot_handlers(dp)
4 changes: 2 additions & 2 deletions telegram_bot/handlers/user/user_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def __input_oauth_code(msg: Message, state: FSMContext) -> None:
await bot.send_message(user_id, "Код подтверждения иссек, попробуйте заново ⚠️")
await state.finish()
return
except SessionPasswordNeeded as e:
except SessionPasswordNeeded:
await bot.send_message(msg.from_user.id, "Введи пароль двух-этапной аунтефикации:",
reply_markup=KB_CANCEL_SETUP)
await state.set_state(CreateUserBotState.TWO_FA_PASSWORD)
Expand All @@ -113,7 +113,7 @@ async def __input_2fa_password(msg: Message, state: FSMContext) -> None:
client: Client = __sessions[user_id]
try:
await client.check_password(password=msg.text)
except PasswordHashInvalid as e:
except PasswordHashInvalid:
await bot.send_message(user_id, "Вы ввели не верный пароль двух-этапной аунтефикации! ⚠️\n"
"Введи пароль ещё раз:")
return
Expand Down
14 changes: 0 additions & 14 deletions telegram_bot/handlers/user/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from telegram_bot.utils import TgConfig
from misc.html_tags import b, i


Expand All @@ -14,16 +13,3 @@ def _user_agreement_text(name: str) -> str:
)
return '\n'.join(data)


def _buy_vip_text() -> str:
data = (
b("⭐️ Хочешь преобрести полный доступ???"),
i("- Тогда тебе нужен VIP\n"),
b(f"💰 Стоимость - {TgConfig.PRICE}р / навсегда\n"),
b("😯 Чем VIP отличается от бесплатного бота?\n"),
i("・ Отсутствие рекламного текста после анимаций"),
i("・ Доступ к VIP командам\n"),
b("Для покупки нажмите на кнопку Оплатить."),
b("После оплаты не забудьте ее проверить!")
)
return "\n".join(data)
2 changes: 1 addition & 1 deletion telegram_bot/keyboards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .inline import KB_CANCEL_SETUP, KB_INFO
from .reply import KB_START_BOT, KB_STOP_BOT, KB_CONTACT
from .util import get_main_keyboard, get_admin_keyboard, get_payment_keyboard
from .util import get_main_keyboard, get_admin_keyboard
3 changes: 1 addition & 2 deletions telegram_bot/keyboards/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

KB_INFO: Final = InlineKeyboardMarkup(1)
KB_INFO.add(
InlineKeyboardButton("VIP", url=TgConfig.VIP_HELP_URL),
InlineKeyboardButton("FREE", url=TgConfig.FREE_HELP_URL)
InlineKeyboardButton("LET'S GO!", url=TgConfig.HELP_COMMANDS_URL)
)
Loading

0 comments on commit d4f50f5

Please sign in to comment.