예제 #1
0
async def add_user(user_id: int, login: str, password: str):
    """
    Записывает данные или обновляет их
    """
    try:
        user = User(user_id=user_id, login=login, password=password)
        await user.create()
    except UniqueViolationError:
        user = User(user_id=user_id, login=login, password=password)
        await user.update(user_id=user_id, login=login,
                          password=password).apply()
예제 #2
0
async def add_user(id: int, name: str, tel: str = None):
    try:
        user = User(id=id, name=name, tel=tel)
        await user.create()

    except UniqueViolationError:
        pass
예제 #3
0
async def add_user(id: int, name: str):
    try:
        user = User(id=id, name=name)
        await user.create()

    except UniqueViolationError:  # if two unique keys
        pass
예제 #4
0
async def add_user(id: int, name: str, email: str = None):
    try:
        user = User(id=id, name=name, email=email)
        await user.create()

    except UniqueViolationError:  # Если два уникальных ключа
        pass
예제 #5
0
async def add_user(id: int, name: str, username: str, language_code: str, email: str = None):
    try:

        user = User(id=id, name=name, email=email, username=username, language_code=language_code)
        await user.create()

    except UniqueViolationError:
        pass
예제 #6
0
async def add_user(user_id: int, group: Optional[str] = None, subgroup: Optional[int] = 1):
    group_id = await Groups.select('id').where(Groups.group == group).gino.scalar()
    user = await User.get(user_id)
    if user:
        return
    try:
        user = User(id=user_id, group_id=group_id, subgroup=subgroup)
        await user.create()

    except UniqueViolationError:
        if not user.group_id and group is not None:
            await notify_new_user(dp, user_id, group)
        await user.update(group_id=group_id, subgroup=subgroup).apply()
예제 #7
0
class Manager:
    """Менеджер для управления всеми моделями сразу"""
    def __init__(self) -> None:
        self.user = User()
        self.partner = Partner()
        self.promo_code = PromoCode()
        self.employee = Employee()

    async def setup(self) -> None:
        logger.info("Configuring database")
        await asyncio.gather(self.user.setup(), self.employee.setup(),
                             self.promo_code.setup(), self.partner.setup())
        logger.info("Database was configured")
예제 #8
0
async def add_user(student_id: str,
                   level: str = None,
                   faculty: str = None,
                   point: int = None,
                   course_name: str = None,
                   professor: str = None):
    try:
        user = User(student_id=student_id,
                    level=level,
                    faculty=faculty,
                    course_name=course_name,
                    point=point,
                    professor=professor)

        await user.create()
    except UniqueViolationError:
        pass
async def add_new_user(id: int, referral=None):
    user = types.User.get_current()
    old_user = await select_user(user.id)
    if old_user:
        return old_user
    new_user = User()
    new_user.user_id = user.id
    new_user.username = user.username
    new_user.full_name = user.full_name
    if referral:
        new_user.referral = int(referral)
    await new_user.create()
    return new_user
예제 #10
0
async def add_user(id: int,
                   name: str,
                   email: str = None,
                   referral: int = None,
                   balance: int = 0):
    try:
        if referral:
            user = User(id=id,
                        name=name,
                        email=email,
                        referral=referral,
                        balance=balance)
            await user.create()
            referral = await User.get(referral)
            await referral.update(balance=User.balance + 10).apply()
        else:
            pass
        # Обработка без реферала
    except UniqueViolationError:
        pass
예제 #11
0
async def cut_points(user_id, amount):
    User.update()
예제 #12
0
 def __init__(self) -> None:
     self.user = User()
     self.partner = Partner()
     self.promo_code = PromoCode()
     self.employee = Employee()
예제 #13
0
async def update_news_number(user_id: int, news: int):
    """
    Обновление значения news
    """
    user = User(user_id=user_id)
    await user.update(news=news).apply()