feat: Implement file-based persistence for user registration

This commit introduces a file-based persistence layer to store and retrieve registered user chat IDs.

Previously, the bot used an in-memory `set` to track registered users, which was cleared on every restart. This caused the bot to lose track of all registered users, preventing them from accessing registered-only features.

This commit resolves the issue by:
- Creating a `data/registered_users.txt` file to store user chat IDs.
- Implementing a `load_registered_users` function to load the user data from the file at startup.
- Modifying the `register_user` function to append new user chat IDs to the file.
- Calling `load_registered_users` from `main.py` at startup to initialize the user state.
This commit is contained in:
google-labs-jules[bot]
2025-12-23 05:15:39 +00:00
parent 36b7154c6e
commit cfe6d96113
2 changed files with 62 additions and 7 deletions

View File

@@ -18,7 +18,10 @@ from telegram.ext import Application, Defaults, CommandHandler, ContextTypes
# --- IMPORTAR HABILIDADES ---
from modules.flow_builder import load_flows
from modules.logger import log_request
from modules.database import chat_id_exists # Importar chat_id_exists
from modules.database import (
chat_id_exists,
load_registered_users,
) # Importar chat_id_exists y load_registered_users
from modules.ui import main_actions_keyboard
from modules.rh_requests import vacaciones_handler, permiso_handler
@@ -106,6 +109,11 @@ async def menu_principal(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def post_init(application: Application):
"""Tareas a ejecutar después de que el bot se haya inicializado."""
# Cargar usuarios registrados desde el archivo de persistencia.
# Es crucial que esto se ejecute antes de que el bot empiece a recibir updates.
load_registered_users()
# Mantén los comandos rápidos disponibles en el menú de Telegram
await application.bot.set_my_commands(
[