Merge branch 'feature/push-notifications'

This commit is contained in:
dasemu committed 2026-03-17 17:55:54 +01:00
commit 413489b590
3 files changed
+200

No files matched your search

+40
View File
@@ -407,6 +407,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)
@@ -501,6 +503,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
# ---------------------------------------------------------------------------
@@ -529,6 +567,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