Exemple #1
0
def admin_menu(msg: types.Message):
    user_id = msg.from_user.id
    if not check_admin(user_id):
        bot.send_message(user_id,
                         '❗ YOU ARE NOT AN ADMIN ❗',
                         reply_markup=reply.main_menu())
    else:
        bot.send_message(user_id, msg.text, reply_markup=inline.admin_menu())
Exemple #2
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))
Exemple #3
0
def sure_delete_product(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[0] == 'yes_delete_product':
        product_to_delete = Product.objects.get(id=call_splited[1])
        product_to_delete.delete()
        bot.edit_message_text(
            f'Product "{product_to_delete.name}" has been deleted!', user_id,
            msg_id)
    if call_splited[0] == 'no_delete_product':
        if not check_admin(user_id):
            bot.edit_message_text(user_id,
                                  '❗ YOU ARE NOT AN ADMIN ❗',
                                  user_id,
                                  msg_id,
                                  reply_markup=reply.main_menu())
        else:
            bot.edit_message_text('👨‍💻 ADMIN MENU ⚙',
                                  user_id,
                                  msg_id,
                                  reply_markup=inline.admin_menu())
Exemple #4
0
def start_cmd_handler(message: types.Message):
    user_id = message.from_user.id
    user = User.objects.filter(user_id=user_id)
    admin = False
    if not user.exists():
        first_name = message.from_user.first_name
        last_name = message.from_user.last_name
        username = message.from_user.username
        full_name = f'{first_name}'
        if last_name:
            full_name += f' {last_name}'
        new_user = User.objects.create(user_id=user_id, full_name=full_name, username=username)
    elif User.objects.get(user_id=user_id).admin:
        admin = True
    print(user_id)
    bot.send_message(message.from_user.id, strings.get('welcome_message'), reply_markup=reply.main_menu(admin))
    bot.finish_user(user_id)