mirror of
https://github.com/marcogll/vanessa_bot_vanity.git
synced 2026-01-13 21:35:16 +00:00
feat: Add /reset command for re-testing registration
This commit introduces a `/reset` command that allows users to clear their registration status. This is useful for testing the registration conversation flow multiple times without needing to restart the bot. The command works by removing the user's chat ID from the in-memory set of registered users and then displaying the main menu again.
This commit is contained in:
14
app/main.py
14
app/main.py
@@ -18,7 +18,7 @@ from telegram.ext import Application, Defaults, CommandHandler, ContextTypes
|
|||||||
# --- IMPORTAR HABILIDADES ---
|
# --- IMPORTAR HABILIDADES ---
|
||||||
from modules.flow_builder import load_flows
|
from modules.flow_builder import load_flows
|
||||||
from modules.logger import log_request
|
from modules.logger import log_request
|
||||||
from modules.database import chat_id_exists # Importar chat_id_exists
|
from modules.database import chat_id_exists, deregister_user
|
||||||
from modules.ui import main_actions_keyboard
|
from modules.ui import main_actions_keyboard
|
||||||
|
|
||||||
from modules.rh_requests import vacaciones_handler, permiso_handler
|
from modules.rh_requests import vacaciones_handler, permiso_handler
|
||||||
@@ -105,6 +105,17 @@ async def menu_principal(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def reset_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
|
"""Permite a un usuario eliminar su registro para reiniciar el flujo."""
|
||||||
|
user = update.effective_user
|
||||||
|
log_request(user.id, user.username, "reset", update.message.text)
|
||||||
|
|
||||||
|
deregister_user(user.id)
|
||||||
|
await update.message.reply_text("🔄 Tu registro ha sido eliminado. Ahora puedes volver a registrarte.")
|
||||||
|
# Llamar a menu_principal para mostrar el menú actualizado
|
||||||
|
await menu_principal(update, context)
|
||||||
|
|
||||||
|
|
||||||
async def post_init(application: Application):
|
async def post_init(application: Application):
|
||||||
# Mantén los comandos rápidos disponibles en el menú de Telegram
|
# Mantén los comandos rápidos disponibles en el menú de Telegram
|
||||||
await application.bot.set_my_commands(
|
await application.bot.set_my_commands(
|
||||||
@@ -146,6 +157,7 @@ def main():
|
|||||||
app.add_handler(CommandHandler("start", menu_principal))
|
app.add_handler(CommandHandler("start", menu_principal))
|
||||||
app.add_handler(CommandHandler("help", menu_principal))
|
app.add_handler(CommandHandler("help", menu_principal))
|
||||||
app.add_handler(CommandHandler("links", links_menu))
|
app.add_handler(CommandHandler("links", links_menu))
|
||||||
|
app.add_handler(CommandHandler("reset", reset_command))
|
||||||
|
|
||||||
# Handlers de módulos
|
# Handlers de módulos
|
||||||
app.add_handler(vacaciones_handler)
|
app.add_handler(vacaciones_handler)
|
||||||
|
|||||||
@@ -29,3 +29,14 @@ def register_user(user_data: dict) -> bool:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[MockDB] Register error: {e}")
|
logging.error(f"[MockDB] Register error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def deregister_user(chat_id: int) -> bool:
|
||||||
|
"""Mock deregister: removes user from in-memory set."""
|
||||||
|
try:
|
||||||
|
_REGISTERED_USERS.discard(int(chat_id))
|
||||||
|
logging.info(f"[MockDB] User {chat_id} deregistered from memory.")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"[MockDB] Deregister error: {e}")
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user