Exemple #1
0
def new_category_data(msg: types.Message):
    user_id = msg.from_user.id
    bot.update_data({'new_category_data': msg.text}, user_id)
    bot.set_state(States.new_category_file.value, user_id)
    bot.send_message(
        user_id,
        'OK. Now send the DOCUMENT that the bot will give to the user after the purchase.',
        reply_markup=inline.add_doc_to_category())
Exemple #2
0
def manage_users_balance(call: types.CallbackQuery):
    bot.answer_callback_query(call.id, '💵')
    user_id = call.from_user.id
    msg_id = call.message.message_id
    call_splited = call.data.split('-')
    user = User.objects.get(user_id=call_splited[1])
    bot.set_data({'user_to_set_balance': user.user_id}, user_id)
    bot.set_state(States.manage_users_balance.value, user_id)
    bot.edit_message_text(f'Send value to set new balance to {user.full_name}',
                          user_id, msg_id)
Exemple #3
0
def addcategorywithout_doc(call: types.CallbackQuery):
    bot.answer_callback_query(call.id)
    user_id = call.from_user.id
    bot.update_data({'new_category_file': None}, user_id)
    bot.set_state(States.new_category_only_one_user.value, user_id)
    bot.edit_message_text(
        'OK, now tell me. Can different users buy this product?',
        user_id,
        call.message.message_id,
        reply_markup=inline.category_only_one_user())
Exemple #4
0
def edit_text_shop_policy(call: types.CallbackQuery):
    bot.answer_callback_query(call.id, '⚠')
    user_id = call.from_user.id
    msg_id = call.message.message_id
    bot.edit_message_text(
        'OK. Now send new text for shop policy\n\n'
        '(After restarting the bot will be reset to default)',
        user_id,
        msg_id,
        reply_markup=inline.back_admin_edit_text())
    bot.set_state(States.edit_text_shop_policy.value, user_id)
Exemple #5
0
def new_category_price(msg: types.Message):
    user_id = msg.from_user.id
    try:
        price = Decimal(msg.text)
        bot.update_data({'new_category_price': str(price)}, user_id)
        bot.send_message(
            user_id,
            'OK. Now send the data that the bot will give to the user after the purchase.'
        )
        bot.set_state(States.new_category_data.value, user_id)
    except InvalidOperation:
        bot.send_message(user_id, 'It\'s not like the price. Try again.')
Exemple #6
0
def new_category_file(msg: types.Message):
    user_id = msg.from_user.id
    content_type = msg.content_type
    if content_type == 'text':
        bot.send_message(user_id, 'It\'s not like the document. Try again.')
    if content_type == 'document':
        file_id = msg.document.file_id
        bot.update_data({'new_category_file': file_id}, user_id)
        bot.set_state(States.new_category_only_one_user.value, user_id)
        bot.send_message(
            user_id,
            'OK, now tell me. Can different users buy the products in the category??',
            reply_markup=inline.category_only_one_user())
Exemple #7
0
def select_category_parent(call: types.CallbackQuery):
    bot.answer_callback_query(call.id)
    user_id = call.from_user.id
    msg_id = call.message.message_id
    call_splited = call.data.split('-')

    if call_splited[2] != 'None':
        bot.update_data({'parent_category_id': int(call_splited[2])}, user_id)
    else:
        bot.update_data({'parent_category_id': None}, user_id)

    bot.edit_message_text('OK. Now send price ($) for this category.', user_id,
                          msg_id)
    bot.set_state(States.new_category_price.value, user_id)
Exemple #8
0
def admin____handler(call: types.CallbackQuery):
    bot.answer_callback_query(call.id)
    user_id = call.from_user.id
    if not User.objects.get(user_id=user_id).admin:
        bot.send_message(user_id,
                         'YOU ARE NOT AN ADMIN!!!',
                         reply_markup=reply.main_menu())
    if call.data == 'admin_add_category':
        bot.set_state(States.new_category_name.value, user_id)
        bot.send_message(user_id, 'OK. Send me the name for new category.')
    if call.data == 'admin_add_product':
        bot.set_state(States.new_product_name.value, user_id)
        bot.send_message(user_id, 'OK. Send me the name for new product.')
    if call.data == 'admin_del_category':
        bot.send_message(user_id,
                         'OK. Now select the category for delete.',
                         reply_markup=inline.del_category())
    if call.data == 'admin_del_product':
        bot.send_message(user_id,
                         'OK. Now select the product for delete.',
                         reply_markup=inline.del_product())
    if call.data == 'admin_manage_admins':
        text = 'OK.  Now select the user to grant or remove administrator rights.\n\n'
        text += '❗ If user have ✅ - user is admin ❗'
        bot.send_message(user_id,
                         text,
                         reply_markup=inline.manage_admins(user_id))

    text = 'OK.  Now select the menu where you want to change the text'
    if call.data == 'admin_edit_text':
        text = 'OK.  Now select the menu where you want to change the text'
        bot.send_message(user_id, text, reply_markup=inline.edit_text())
    elif call.data == 'back_admin_edit_text':
        bot.finish_user(user_id)
        bot.edit_message_text(text,
                              user_id,
                              call.message.message_id,
                              reply_markup=inline.edit_text())

    if call.data == 'admin_manage_banned_users':
        text = 'OK.  Now select the user to ban or unban.\n\n'
        text += '❗ If user have 🖍 - user is banned ❗'
        bot.send_message(user_id,
                         text,
                         reply_markup=inline.manage_banned_users(user_id))
    if call.data == 'admin_manage_users_balance':
        text = 'OK. Now select the user to set value of balance.'
        bot.send_message(user_id,
                         text,
                         reply_markup=inline.manage_users_balance(user_id))