Бот для телеги, открывающий доступ в чатик по приглашениям.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
"""Славный модуль с бизнес-логикой."""
|
|
|
|
from models import Allowed_user
|
|
|
|
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
|
|
import settings
|
|
|
|
|
|
|
|
engine = create_engine("sqlite:///" + str(settings.DB_PATH))
|
|
|
|
Session = sessionmaker(bind=engine)
|
|
|
|
session = Session()
|
|
|
|
|
|
|
|
|
|
|
|
def auth(func):
|
|
|
|
"""Аутентификация.
|
|
|
|
|
|
|
|
Проверяем, что у юзера есть полномочия на выполнение действия - он
|
|
|
|
должен быть в белом списке.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
async def wrapper(message):
|
|
|
|
finded_user: Allowed_user
|
|
|
|
uid = message["from"]["id"]
|
|
|
|
|
|
|
|
finded_user = (
|
|
|
|
session.query(Allowed_user)
|
|
|
|
.filter(Allowed_user.user_id == uid)
|
|
|
|
.one_or_none()
|
|
|
|
)
|
|
|
|
|
|
|
|
if not finded_user:
|
|
|
|
return
|
|
|
|
return await func(message)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
def only_admins(func):
|
|
|
|
"""Действия только для админов."""
|
|
|
|
|
|
|
|
async def wrapper(message):
|
|
|
|
uid = message["from"]["id"]
|
|
|
|
|
|
|
|
if uid not in settings.ADMINS:
|
|
|
|
return
|
|
|
|
|
|
|
|
return await func(message)
|
|
|
|
|
|
|
|
return wrapper
|