From 305f8542ab9414ada74861b1c95b6c3cd42581f7 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sun, 15 Dec 2024 00:35:39 +0330 Subject: [PATCH] Create Delete --- core/scripts/telegrambot/utils/deleteuser.py | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 core/scripts/telegrambot/utils/deleteuser.py diff --git a/core/scripts/telegrambot/utils/deleteuser.py b/core/scripts/telegrambot/utils/deleteuser.py new file mode 100644 index 0000000..f486a0c --- /dev/null +++ b/core/scripts/telegrambot/utils/deleteuser.py @@ -0,0 +1,25 @@ +from dotenv import load_dotenv +from telebot import types +from utils.command import * +from utils.common import * + + +@bot.callback_query_handler(func=lambda call: call.data == "cancel_delete") +def handle_cancel_delete(call): + bot.edit_message_text("Operation canceled.", chat_id=call.message.chat.id, message_id=call.message.message_id) + create_main_markup(call.message) + +@bot.message_handler(func=lambda message: is_admin(message.from_user.id) and message.text == 'Delete User') +def delete_user(message): + markup = types.InlineKeyboardMarkup() + cancel_button = types.InlineKeyboardButton("❌ Cancel", callback_data="cancel_delete") + markup.add(cancel_button) + + msg = bot.reply_to(message, "Enter username:", reply_markup=markup) + bot.register_next_step_handler(msg, process_delete_user) + +def process_delete_user(message): + username = message.text.strip().lower() + command = f"python3 {CLI_PATH} remove-user -u {username}" + result = run_cli_command(command) + bot.reply_to(message, result) \ No newline at end of file