コード例 #1
0
def create_extend_debs_text(debs, user_id):

    total_dolzhen = 0
    total_nedolzhen = 0
    nedolzhen = []
    dolzhen = []

    if debs:

        for deb in debs:
            if deb.user_id == user_id:
                dolzhen.append(deb)
                total_dolzhen += deb.amount
            else:
                nedolzhen.append(deb)
                total_nedolzhen += deb.amount

        out = []
        if nedolzhen:
            for deb in nedolzhen:
                user = is_user_exist(deb.user_id)
                order = order_status(deb.order_id)
                t = f'Тебе должна(ен) @{user.user_name} {round(deb.amount / 100, 2)}₽ за заказ "{order.text}"'
                out.append(t)
        if dolzhen:
            for deb in dolzhen:
                user = is_user_exist(deb.foreign_id)
                order = order_status(deb.order_id)
                t = f'Ты должна(ен) @{user.user_name} {round(deb.amount / 100, 2)}₽ за заказ "{order.text}"'
                out.append(t)

        text = ''

        for i in range(len(out)):
            t = f'{i + 1})' + out[i] + '\n'
            text += t

        if total_nedolzhen != 0:
            text += f'\nВсего должны: {round(total_nedolzhen / 100, 2)}₽'
            if total_dolzhen != 0:
                text += f'\n\nВсего должна(ен): {round(total_dolzhen / 100, 2)}₽'
        else:
            if total_dolzhen != 0:
                text += f'Всего должна(ен): {round(total_dolzhen / 100, 2)}₽'

        if nedolzhen:
            text += f'\n\nНажми на кнопку с номером долга, если тебе его уже вернули:'

        return text

    else:
        return 'Долгов пока нет...'
コード例 #2
0
def between_inline(user_id, flag):
    main = is_user_exist(user_id)

    users = db.get_access(user_id)
    if (len(users) % 2) != 0:
        n = (len(users) // 2) + 1
    else:
        n = len(users) // 2

    buttons = []
    for user in users:
        buttons.append(InlineKeyboardButton(text='@' + user.user_name,
                                            callback_data=split_callback.new(order_id=user.user_id)))

    buttons.append(InlineKeyboardButton(text='@' + main.user_name,
                                            callback_data=split_callback.new(order_id=main.user_id)))


    lis = []
    for i in range(n+1):
        lis.append([])
        for j in range(2 * i, 2 * i + 2):
            try:
                lis[i].append(buttons[j])
            except IndexError:
                pass
    if flag:
        if (len(users) % 2) != 0:
            lis[-1].append(InlineKeyboardButton(text='Делим!', callback_data=split_callback.new(order_id='split')))
        else:
            lis.append([InlineKeyboardButton(text='Делим!', callback_data=split_callback.new(order_id='split'))])

    between_ikb = InlineKeyboardMarkup(inline_keyboard=lis)
    return between_ikb
コード例 #3
0
async def process_start_command(message: types.Message):
    user_id = message.from_user.id
    user_name = message.from_user.username
    if not user_name:
        user_name = 'unknown'

    is_exit = db.is_user_exist(user_id)

    if not is_exit:
        db.create_user(user_id, user_name.lower())
    else:
        db.update_username(user_id, user_name.lower())

    if user_name == 'unknown':
        await bot.send_message(message.from_user.id, bad_greet)
    else:
        await bot.send_message(message.from_user.id, good_greet)
コード例 #4
0
async def alarm(order, user_id):
    user = is_user_exist(user_id)
    await bot.send_message(
        order.user_id, f'@{user.user_name} купил ваш заказ "{order.text}"')
コード例 #5
0
def create_lite_debs_text(debs, user_id):

    total_dolzhen = 0
    total_nedolzhen = 0
    nedolzhen = {}
    dolzhen = {}
    nedolzhenlist = []

    if debs:

        for deb in debs:

            if deb.user_id == user_id:
                user = is_user_exist(deb.foreign_id)
                if user.user_name not in dolzhen:
                    dolzhen[user.user_name] = deb.amount
                else:
                    dolzhen[user.user_name] += deb.amount
                total_dolzhen += deb.amount

            else:
                user = is_user_exist(deb.user_id)
                if user.user_name not in nedolzhen:
                    nedolzhen[user.user_name] = deb.amount
                else:
                    nedolzhen[user.user_name] += deb.amount

                if user.user_id not in nedolzhenlist:
                    nedolzhenlist.append(user.user_id)
                total_nedolzhen += deb.amount

        out = []

        if nedolzhen:
            for username, amount in nedolzhen.items():
                t = f'Тебе должна(ен) @{username} {round(amount / 100, 2)}₽'
                out.append(t)
        if dolzhen:
            for username, amount in dolzhen.items():
                t = f'Ты должна(ен) @{username} {round(amount / 100, 2)}₽'
                out.append(t)

        text = ''

        for i in range(len(out)):
            t = f'{i + 1})' + out[i] + '\n'
            text += t

        if total_nedolzhen != 0:
            text += f'\nВсего должны: {round(total_nedolzhen / 100, 2)}₽'
            if total_dolzhen != 0:
                text += f'\n\nВсего должна(ен): {round(total_dolzhen / 100, 2)}₽'
        else:
            if total_dolzhen != 0:
                text += f'Всего должна(ен): {round(total_dolzhen / 100, 2)}₽'

        if nedolzhenlist:
            text += f'\n\nНажми на кнопку с номером долга, если тебе его уже вернули:'

        return text, nedolzhenlist

    else:
        return 'Долгов пока нет...', None