mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
feat(bot): add daily push notification subscription system
Add /suscribir and /desuscribir commands to the Telegram bot so users can opt in to receive the next-day prediction automatically at 20:00 when the extended task fires. Subscribers are persisted in a new notification_subscribers SQLite table with soft-delete semantics.
This commit is contained in:
1 parent
5e2a22340f
commit
61b4d8334d
3 files changed
+200
No files matched your search
@@ -430,6 +430,8 @@ async def cmd_help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"/manana — Predicción de mañana para las tres estaciones\n"
|
||||
"/tresdias — Predicción de hoy y los dos días siguientes\n"
|
||||
"/semana — Predicción de los próximos siete días\n"
|
||||
"/suscribir — Recibir la predicción diaria a las 20:00\n"
|
||||
"/desuscribir — Dejar de recibir la predicción diaria\n"
|
||||
"/help — Mostrar esta ayuda\n"
|
||||
)
|
||||
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
|
||||
@@ -595,6 +597,42 @@ async def cmd_semana(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None
|
||||
)
|
||||
|
||||
|
||||
async def cmd_suscribir(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Handle the /suscribir command -- subscribe to daily notifications."""
|
||||
chat_id = update.effective_chat.id
|
||||
username = update.effective_user.username if update.effective_user else None
|
||||
logger.info("El usuario %s solicitó /suscribir", chat_id)
|
||||
|
||||
store = SQLiteStore()
|
||||
is_new = store.subscribe_notifications(chat_id, username)
|
||||
|
||||
if is_new:
|
||||
text = (
|
||||
"Te has suscrito a las notificaciones diarias.\n"
|
||||
"Recibirás la predicción de mañana cada día a las 20:00."
|
||||
)
|
||||
else:
|
||||
text = "Ya estás suscrito a las notificaciones diarias."
|
||||
|
||||
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
|
||||
|
||||
|
||||
async def cmd_desuscribir(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Handle the /desuscribir command -- unsubscribe from daily notifications."""
|
||||
chat_id = update.effective_chat.id
|
||||
logger.info("El usuario %s solicitó /desuscribir", chat_id)
|
||||
|
||||
store = SQLiteStore()
|
||||
was_subscribed = store.unsubscribe_notifications(chat_id)
|
||||
|
||||
if was_subscribed:
|
||||
text = "Has cancelado tu suscripción a las notificaciones diarias."
|
||||
else:
|
||||
text = "No estabas suscrito a las notificaciones diarias."
|
||||
|
||||
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Bot entry point
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -627,6 +665,8 @@ def create_bot_application(token: str | None = None) -> Application:
|
||||
app.add_handler(CommandHandler("manana", cmd_manana))
|
||||
app.add_handler(CommandHandler("tresdias", cmd_tresdias))
|
||||
app.add_handler(CommandHandler("semana", cmd_semana))
|
||||
app.add_handler(CommandHandler("suscribir", cmd_suscribir))
|
||||
app.add_handler(CommandHandler("desuscribir", cmd_desuscribir))
|
||||
|
||||
return app
|
||||
|
||||
|
||||
Reference in new issue
Block a user