def reset(message):
    if db.hasUser(message.chat.id):
        db.deleteUser(message.chat.id)
        bot.send_message(
            message.chat.id,
            answers.resetSuccess,
            reply_markup=keyboards.removeKeyBoard()
        )
    else:
        bot.send_message(
            message.chat.id,
            answers.resetFailure,
            reply_markup=keyboards.removeKeyBoard()
        )
def getProducts(message: Message):
    user = db.getUser(message.chat.id)

    if not user:
        db.createUser(message.chat.id, states.SHOW_PRODUCTS)
        user = db.getUser(message.chat.id)

    page = user[3]

    print(page)

    if page <= 0:
        db.changeUserState(message.chat.id, page=1)

        bot.send_message(message.chat.id,
                         answers.outOfRange,
                         reply_markup=keyboards.removeKeyBoard())

        return

    httpProduct = http.getProducts(user[2], page)

    if not len(httpProduct['data']):
        bot.send_message(message.chat.id, answers.noData)
        return

    for product in httpProduct['data']:
        helpers.sendProduct(message.chat.id, product)
def filterColor(message: Message):
    userFilters: dict = db.getUser(message.chat.id)[2]

    if message.text != '.':
        filters = http.getFilters()
        colors = filters['colors']

        if message.text in colors:
            # change db data
            userFilters['color'] = message.text

        else:
            bot.send_message(message.chat.id, answers.filterColorInvalid)

            return

    # set data to db
    db.changeUserState(message.chat.id,
                       state=states.FILTER_PRICE,
                       filters=userFilters)

    # send next step
    bot.send_message(message.chat.id,
                     answers.filterPrice,
                     reply_markup=keyboards.removeKeyBoard())
示例#4
0
def sendProduct(userID: str, product: dict):
    product['colors'] = ', '.join(
        loads(product['colors']) if isinstance(product['colors'], str
                                               ) else product['colors'])

    product['sizes'] = ', '.join(
        loads(product['sizes']) if isinstance(product['sizes'], str
                                              ) else product['sizes'])

    reply = keyboards.linkKeyboard(
        product['name'], f"{config.site_url}products/{product['slug']}")

    bot.send_photo(userID,
                   f"{config.images_base_url}/{product['photo']}",
                   reply_markup=keyboards.removeKeyBoard())
    #bot.send_photo(userID, 'https://i.insider.com/5eda82ae3ad8617d4e1c0b2e?width=1100&format=jpeg&auto=webp')

    bot.send_message(userID,
                     answers.productItem.format(**product),
                     reply_markup=reply)
def enterFind(message: Message):
    if not message.text:
        # send error message
        bot.send_message(message.chat.id, answers.findInvalid)
        return

    # change state to show
    db.changeUserState(message.chat.id, state=states.SHOW_PRODUCTS)

    # find products
    products: dict = http.findProducts(message.text)

    if not len(products.get('data')):
        bot.send_message(message.chat.id,
                         answers.notFound,
                         reply_markup=keyboards.removeKeyBoard())

    # show products
    for product in products.get('data'):
        helpers.sendProduct(message.chat.id, product)
def notFound(message):
    bot.reply_to(message, answers.notFound, reply_markup=removeKeyBoard())
def site(message: Message):
    bot.send_message(
        message.chat.id,
        answers.site,
        reply_markup=keyboards.removeKeyBoard()
    )
def contacts(message: Message):
    bot.send_message(
        message.chat.id,
        answers.contacts,
        reply_markup=keyboards.removeKeyBoard()
    )
def find(message: Message):
    db.changeUserState(message.chat.id, state=states.FIND)
    bot.send_message(message.chat.id,
                     answers.findMessage,
                     reply_markup=keyboards.removeKeyBoard())