def count_handle(message):
    uid = str(message.from_user.id)
    cur_time = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
    print(str(cur_time) + " | " + uid + ": " + message.text)

    db = SQLighter(config.database_name)
    config.products_list = db.get_product_names()
    if message.text in config.products_list:
        m = count_markup(db)
        text = db.get_messages('count')[0]
        product_info = db.get_product_info(message.text)
        if product_info is not None:
            if len(product_info['price']) == 1:
                caption = message.text + "\n\n" + "Цена: " + product_info['price'][0] + " сум"
            else:
                caption = message.text + "\n\n" + "Большая: " + product_info['price'][
                    0] + " сум" + "\n" + "Маленькая: " + product_info['price'][1] + " сум"

            request[uid] = {}
            request[uid]['name'] = message.text
            request[uid]['size'] = 0  # по-умолчанию выбирается большая

            if len(product_info['price']) == 1:
                step[uid]['cur'] = message.text
            else:
                step[uid]['cur'] = 'Размер'
                text = db.get_messages('Размер')[0]
                m = big_small_markup(db)
                step[uid]['path'].append(message.text)

            step[uid]['path'].append(step[uid]['cur'])
            db.close()
            try:
                if product_info['fid'] is not None:
                    bot.send_photo(message.chat.id, product_info['fid'], caption=caption)
            except:
                pass
            bot.send_message(message.chat.id, text, reply_markup=m, parse_mode='HTML')
        else:
            step[uid]['cur'] = 'start'
            step[uid]['path'] = ['start']
            m = markup(db, step[uid]['cur'], uid)
            text = db.get_messages('db_error')[0]
            db.close()
            cur_time = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
            print(str(cur_time) + " | " + uid + ": Нет продукта {} в базе данных".format(message.text))
            bot.send_message(message.chat.id, text, reply_markup=m, parse_mode='HTML')
Exemplo n.º 2
0
    'Шашлык': '🍢',
    'Десерты': '🍰',
    'Закуски': '🍱',
    'Список': '⏩',
    'bread': '\U0001F35E'
}

conn = SQLighter(database_name)

step_list = conn.get_button_steps()
reserved = [
    'Контакт', 'Оставить отзыв', 'Дополнительно', 'Адрес', 'start', 'Оформить',
    'Оплата', 'Корзина', 'back'
]
for i in reserved:
    if i in step_list:
        step_list.remove(i)
# print(step_list)

type_list = conn.get_type_list()
# print(type_list)

products_list = conn.get_product_names()
# print(products_list)

conn.close()

COMMENT_LENGTH = 1024
MESSAGE_LENGTH = 512
LOYALTY_LOW_LIMIT = -15