Example #1
0
def delete_item_handler(call):
    call_result = call.data.split(',')
    p_id = call_result[1]
    o_id = call_result[2]
    is_deleted = users.delete_item(p_id, o_id, call.from_user.id)
    if is_deleted:
        box = users.get_local_box(call.from_user.id)
        if not box:
            keyboard = keyboards.category_keyboard(data_instance.categories)
            caption = "Your box is empty please choose products"
            try:
                bot.edit_message_caption(caption=caption,
                                         chat_id=call.from_user.id,
                                         message_id=call.message.message_id,
                                         reply_markup=keyboard)
            except Exception:
                pass

        else:
            keyboard = keyboards.numeric_cancell_keyboard(box)
            try:
                bot.edit_message_reply_markup(
                    chat_id=call.from_user.id,
                    message_id=call.message.message_id,
                    reply_markup=keyboard)
            except Exception:
                pass
Example #2
0
def start_shopping(message):
    users.set_user_data(message)
    data_instance.init_or_refresh_data()
    keyboard = keyboards.category_keyboard(data_instance.categories)
    caption = txt.category
    bot.send_photo(chat_id=message.chat.id,
                   photo=main_photo,
                   caption=caption,
                   reply_markup=keyboard,
                   parse_mode="HTML")
Example #3
0
def back_cat_handling(call):
    print(call.data)
    keyboard = keyboards.category_keyboard(data_instance.categories)
    caption = 'Choose the category'
    try:
        bot.edit_message_media(media=types.InputMediaPhoto(main_photo,
                                                           caption=caption),
                               chat_id=call.from_user.id,
                               message_id=call.message.message_id,
                               reply_markup=keyboard)
    except Exception:
        pass
Example #4
0
def clear_box_handler(call):
    keyboard = keyboards.category_keyboard(data_instance.categories)
    is_cleared = users.clear_all_box_content(call.from_user.id)
    if is_cleared:
        caption = 'Your box has been cleared'
    else:
        caption = 'The box is already empty'
    try:
        bot.edit_message_caption(caption=caption,
                                 chat_id=call.from_user.id,
                                 message_id=call.message.message_id,
                                 reply_markup=keyboard)
    except Exception:
        pass
Example #5
0
def unit_buy_handler(call):
    print(call.data)
    call_result = call.data.split(",")
    product = data_instance.get_product_details(call_result[1])
    unit_amount = call_result[2]
    user_id = call.from_user.id
    caption = f"You have added {product['name']} succesifully to your box\n\nPlease choose the category"
    users.input_to_box(chat_id=user_id, product=product, amount=unit_amount)
    key = keyboards.category_keyboard(data_instance.categories)
    try:
        bot.edit_message_media(media=types.InputMediaPhoto(main_photo,
                                                           caption=caption),
                               chat_id=call.from_user.id,
                               message_id=call.message.message_id,
                               reply_markup=key)
    except Exception:
        pass
Example #6
0
def my_box_handler(message):
    print(message.chat.id)
    users.set_user_data(message)
    box = users.get_user_box(message.chat.id)
    if not box:
        keyboard = keyboards.category_keyboard(data_instance.categories)
        text = "Your Box is Empty"
        bot.send_photo(chat_id=message.chat.id,
                       photo=main_photo,
                       caption=text,
                       reply_markup=keyboard)
    else:
        keyboard = keyboards.box_actions()
        text = users.get_box_details(message.chat.id,
                                     data_instance.products_with_details)
        bot.send_photo(chat_id=message.chat.id,
                       photo=box_photo,
                       caption=text,
                       reply_markup=keyboard)
Example #7
0
def see_box_handler(call):
    keyboard = keyboards.box_actions()
    caption = users.get_box_details(call.from_user.id,
                                    data_instance.products_with_details)
    if not users.get_local_box(call.from_user.id):
        caption = "Your box is empty"
        keyboard = keyboards.category_keyboard(data_instance.categories)
        try:
            bot.edit_message_caption(caption=caption,
                                     chat_id=call.from_user.id,
                                     message_id=call.message.message_id,
                                     reply_markup=keyboard)
        except Exception:
            pass
    else:
        try:
            bot.edit_message_media(media=types.InputMediaPhoto(
                box_photo, caption=caption),
                                   chat_id=call.from_user.id,
                                   message_id=call.message.message_id,
                                   reply_markup=keyboard)
        except Exception:
            pass