From bd066e3ca76bec28182a7f493f292f55fe2e6395 Mon Sep 17 00:00:00 2001 From: Fabio De Simone Date: Thu, 3 Jan 2019 18:01:43 +0100 Subject: [PATCH] Implemented date check for /calendar --- telegrambot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegrambot.py b/telegrambot.py index 6f6cd9f2..c0c7d867 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -485,6 +485,8 @@ def cmd_newevent(bot: Bot, update: Update): # Parse the timestring try: parsed_time = parse_timestring(timestring) + if parsed_time < datetime.datetime.now(): + raise PastDateError() except ValueError: bot.send_message(update.message.chat.id, "⚠ Non è stato possibile leggere la data.\n" "Sintassi corretta:\n" @@ -492,6 +494,10 @@ def cmd_newevent(bot: Bot, update: Update): "|{numero}{w|d|h|m}> \n" "[descrizione]```", parse_mode="Markdown") return + except PastDateError: + bot.send_message(update.message.chat.id, "⚠ La data inserita è una data passata.\n" + "per favore inserisci una data futura.\n", parse_mode="Markdown") + return # Create the event session = db.Session() telegram_user = session.query(db.Telegram)\