Exemple #1
0
def news(bot, telegram):
    all_news = select_news()
    message_id = select_menu(telegram).get('message_id')
    if all_news == []:
        if telegram == 226665834:
            send_menu(bot, telegram, NEWS_EMPTY, 26)
        else:
            send_menu(bot, telegram, NEWS_EMPTY, 1)
        # reply_message(bot, telegram, message_id, NEWS_EMPTY, 1)
    else:
        new_text = ''
        all_news = all_news[::-1]
        last_news = []
        total = 10
        for new in all_news:
            last_news.append(new)
            total -= 1
            if total == 0:
                break

        last_news = last_news[::-1]

        for new in last_news:
            new_text += NEW.format(new.get('new'), new.get('added'))
        if telegram == 226665834:
            send_menu(bot, telegram, new_text, 26)
        else:
            send_menu(bot, telegram, new_text, 1)

    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    return
Exemple #2
0
def order(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    send_menu(bot, telegram, CHOOSE_GOOD, 11)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print(e)
Exemple #3
0
def skip(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    send_menu(bot, telegram, THANKS_FOR_ORDER_OUT + '\n' + MAIN_MENU, 1)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
Exemple #4
0
def write_adress(bot, telegram, menu):
    message_id = select_menu(telegram).get('message_id')
    for_street_menu(bot, telegram, select_last_street(telegram), menu, 0)
    # send_menu(bot, telegram, LOCATION, 7)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
Exemple #5
0
def instruction(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    send_menu(bot, telegram, NEED_HELP, 23)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    return
Exemple #6
0
def shop(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    # reply_message(bot, telegram, message_id, SELECT_PRODUCT, 16)
    send_menu(bot, telegram, SELECT_PRODUCT, 16)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    if users.get(telegram):
        users.pop(telegram)
Exemple #7
0
def add_n_skip(bot, telegram):
    message_id = select_menu(telegram).get('message_id')

    send_menu(bot, telegram, ADD_GOOD, 22)

    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print(e)
        back_to_main_menu_del(bot, telegram)
Exemple #8
0
def payment_success(bot, telegram, summa):
    message_id = select_menu(telegram).get('message_id')
    send_menu(bot, telegram, WISHES, 10)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print(e)
    user = select_user(telegram)
    report_about_paid(
        USER_PAID.format(user.get('name'), summa, user.get('telegram'),
                         user.get('phone')))
Exemple #9
0
def back_to_main_menu_del(bot, telegram):
    try:
        if users.get(telegram):
            users.pop(telegram)
    except Exception as e:
        print(e)

    message_id = select_menu(telegram).get('message_id')
    try:
        users.pop(telegram)
    except Exception as e:
        print('error', e)
    send_photo(bot, telegram, WATER_PHOTO, MAIN_MENU, 1)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
Exemple #10
0
def other_goods(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    # last_order = select_last_street(telegram)
    try:
        send_photo(bot, telegram, POMPA_PHOTO, OTHER_GOODS, 6)
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    if users[telegram].get('pompa'):
        users[telegram].pop('pompa')
    if users[telegram].get('pompaEL'):
        users[telegram].pop('pompaEL')
    if users[telegram].get('culer'):
        users[telegram].pop('culer')
Exemple #11
0
def show_sub_water(bot, telegram):
    message_id = select_menu(telegram).get('message_id')
    try:
        send_photo(
            bot, telegram, WATER_PHOTO,
            SHOW_SUB.format(users[telegram]['price'], users[telegram]['term'],
                            users[telegram]['how_much_sub'],
                            (users[telegram]['how_much_sub'] *
                             int(users[telegram]['price'])),
                            (users[telegram]['how_much_sub'] *
                             (150 - int(users[telegram]['price'])))), 13)
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
Exemple #12
0
def take_contact(bot, telegram, first_name, phone_number):
    # send_menu
    text = GREETINS.format(first_name)

    message_id = bot.send_photo(telegram,
                                WATER_PHOTO,
                                text,
                                reply_markup=menu[1].get('button'))

    try:
        del_menu(bot, telegram, users[telegram].get('mess_id'))
    except Exception as e:
        print('error', e)
        message_id = bot.send_message(telegram,
                                      NEED_PHONE_NUMBER,
                                      reply_markup=contact_menu())
        del_menu(bot, telegram, message_id.message_id)

    # adding user to users
    check_connect()
    user = select_user(telegram)
    if user == []:
        print(phone_number)
        if phone_number[0] == '+':
            phone_number = phone_number[1::]
        connect_mysql.insert(
            'users', **{
                'telegram': telegram,
                'name': first_name,
                'phone': phone_number
            })
        all_rows = select_list_of_users()
        report(NEW_USER.format(first_name, phone_number, all_rows))

    # adding user to menu
    user_menu = select_menu(telegram)
    if user_menu == []:
        connect_mysql.insert(
            'menu', **{
                'telegram': telegram,
                'message_id': message_id.message_id,
                'text': text.encode('utf-8'),
                'index': 1
            })
    else:
        update_menu(telegram, message_id.message_id, text, 1)
Exemple #13
0
def basket(bot, telegram, message_id):
    orders = select_orders(telegram)
    message_id = select_menu(telegram).get('message_id')
    if orders == []:
        send_menu(bot, telegram, BAKEST_EMPTY, 11)
        try:
            del_menu(bot, telegram, message_id)
        except Exception as e:
            print('error', e)
    else:
        text = build_orders(orders[::-1])
        # 'Корзина'
        send_menu(bot, telegram, text, 1)
        try:
            del_menu(bot, telegram, message_id)
        except Exception as e:
            print('error', e)
    return
Exemple #14
0
def show_selected_bottles(bot, telegram, product, index):
    message_id = select_menu(telegram).get('message_id')
    print('here')
    try:
        send_photo(
            bot, telegram, WATER_PHOTO,
            NAME_OF_GOOD.format(product_name.get(product)) + GOOD.format(
                users[telegram].get(product), product_price.get(product),
                (users[telegram].get(product) *
                 int(product_price.get(product)))), index)
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)

    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    return True
Exemple #15
0
def main_menu(bot, telegram, first_name):
    if check_user(telegram) == []:
        message_id = bot.send_message(telegram,
                                      NEED_PHONE_NUMBER,
                                      reply_markup=contact_menu())
        users.update({telegram: {'mess_id': message_id.message_id}})
        return True
    else:
        user_menu = select_menu(telegram)
        if user_menu == []:
            insert_menu(telegram)
        else:
            try:
                del_menu(bot, user_menu.get('telegram'),
                         user_menu.get('message_id'))
            except Exception as e:
                print('error', e)
    try:
        send_photo(bot, telegram, WATER_PHOTO, GREETINS.format(first_name), 1)
    except Exception as e:
        print('error', e)
Exemple #16
0
def confirm_menu(bot, telegram):
    try:
        text_for_confirm = DATES_FOR_CONFIRM.format(
            users[telegram].get('name'), users[telegram].get('phone'),
            users[telegram].get('street'))
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    total = 1

    prices_productes = []

    if users[telegram].get('water'):
        text_for_confirm += BOTTLE_FOR_CONFIRM.format(
            users[telegram].get('water'), product_price.get('water'),
            (users[telegram].get('water') * int(product_price.get('water'))))
        total = users[telegram].get('water') * int(product_price.get('water'))
        prices_productes.append(
            LabeledPrice(label='water',
                         amount=int(users[telegram].get('water')) *
                         int(product_price.get('water')) * 100))
    if users[telegram].get('pompa'):
        text_for_confirm += POMPA_FOR_CONFIRM.format(
            users[telegram].get('pompa'), product_price.get('pompa'),
            (users[telegram].get('pompa') * int(product_price.get('pompa'))))
        total += users[telegram].get('pompa') * int(product_price.get('pompa'))
        prices_productes.append(
            LabeledPrice(label='pompa',
                         amount=int(users[telegram].get('pompa')) *
                         int(product_price.get('pompa')) * 100))

    if users[telegram].get('pompaEL'):
        text_for_confirm += POMPA_FOR_CONFIRM.format(
            users[telegram].get('pompaEL'), product_price.get('pompaEL'),
            (users[telegram].get('pompaEL') *
             int(product_price.get('pompaEL'))))
        total += users[telegram].get('pompaEL') * int(
            product_price.get('pompaEL'))
        prices_productes.append(
            LabeledPrice(label='pompaEL',
                         amount=int(users[telegram].get('pompaEL')) *
                         int(product_price.get('pompaEL')) * 100))

    if users[telegram].get('culer'):
        text_for_confirm += CULER_FOR_CONFIRM.format(
            users[telegram].get('culer'), product_price.get('culer'),
            (users[telegram].get('culer') * int(product_price.get('culer'))))
        total += users[telegram].get('culer') * int(product_price.get('culer'))
        prices_productes.append(
            LabeledPrice(label='culer',
                         amount=int(users[telegram].get('culer')) *
                         int(product_price.get('culer')) * 100))

    prices.update({telegram: prices_productes})
    text_for_confirm += ITOG_CONFIRM.format(total)
    # if first:

    try:
        del_menu(bot, telegram, select_menu(telegram).get('message_id'))
    except Exception as e:
        print(e)

    send_menu(bot, telegram, text_for_confirm, 8)
Exemple #17
0
def check_answer(bot, telegram, text):
    if check_user(telegram) == []:
        message_id = bot.send_message(telegram,
                                      NEED_PHONE_NUMBER,
                                      reply_markup=contact_menu())
        users.update({telegram: {'mess_id': message_id.message_id}})
        return True
    users_menu = select_menu(telegram)

    if users_menu.get('index') == 0:
        try:
            try:
                users[telegram].update(street=text)
            except Exception as e:
                return back_to_main_menu_del(bot, telegram)
            if users[telegram].get('min_sub'):
                show_confirm_sub_water(bot, telegram)
            if users[telegram].get('water'):
                confirm_menu(bot, telegram)
        except Exception as e:
            print('error', e)
    elif users_menu.get('index') == 10:
        try:
            users[telegram].update(comment=text)
            edit_report(users[telegram].get('report') + COMMENT.format(text))
            skip(bot, telegram)
        except Exception as e:
            return back_to_main_menu_del(bot, telegram)

    elif users_menu.get('index') == 14:
        try:
            text = int(text)

            try:

                if users[telegram].get('min_sub') <= text:
                    users[telegram].update(how_much_sub=text)
                    show_sub_water(bot, telegram)
                else:
                    text_send = 'Мало бутылок, <b>в абонементе %s</b> минимальное количество бутылей равно <b>%s</b>' % \
                                (users[telegram].get('term'), users[telegram].get('min_sub'))
                    just_send_mes(bot, telegram, text_send)
                    print('not enough water')
            except Exception as e:
                print(e)
                return back_to_main_menu_del(bot, telegram)
        except Exception as e:
            print('error', e)
            message_id = select_menu(telegram).get('message_id')
            try:
                send_menu(
                    bot, telegram,
                    CIN_PACK_WATER.format(users[telegram].get('price'),
                                          users[telegram].get('min_sub'),
                                          users[telegram].get('term')), 14)
            except Exception as e:
                return back_to_main_menu_del(bot, telegram)
            try:
                del_menu(bot, telegram, message_id)
            except Exception as e:
                print('error', e)
    elif users_menu.get('index') == 24:
        look_up_question(bot, telegram, text)
    elif users_menu.get('index') == 25:
        insert_news(telegram, text)
        back_to_main_menu_del(bot, telegram)

        all_users = select_all_users()
        print('all_users', all_users)
        print('text', text)
        for user in all_users:
            print('user', user)
            just_send_mes(bot, user.get('telegram'),
                          'Новости\n{}'.format(text))
    elif users_menu.get('index') == 1:
        back_to_main_menu_del(bot, telegram)