am stupid
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2023-04-24 22:19:15 +02:00
parent 9d700a8cfd
commit 24065171f7
3 changed files with 34 additions and 22 deletions

View File

@@ -14,10 +14,11 @@ class JournalHandler(BaseHandler):
entry_points=[CommandHandler(entry_string, self.entry_point)],
states={
DATE_CHOICE: [
CallbackQueryHandler(self.date_choice),
CallbackQueryHandler(self.date_choice, pattern="today|yesterday"),
CallbackQueryHandler(self.date_custom, pattern="custom"),
],
DATE_ENTRY: [
MessageHandler(filters.TEXT, self.date_entry),
MessageHandler(filters.ALL, self.date_entry),
],
CONTENT: [
MessageHandler(filters.ALL, self.content_save),
@@ -49,22 +50,34 @@ class JournalHandler(BaseHandler):
async def date_choice(self, update, context):
query = update.callback_query
await query.answer()
if query.data == "today" or query.data == "yesterday":
date = datetime.datetime.now().date() if query.data == "today" else datetime.datetime.now().date() - datetime.timedelta(days=1)
with self.models.db:
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
if not new:
await query.edit_message_text(text="An entry already exists for this date")
return ConversationHandler.END
if query.data == "today":
date = datetime.datetime.now().date()
elif query.data == "yesterday":
date = datetime.datetime.now().date() - datetime.timedelta(days=1)
else:
raise ValueError("Invalid date choice")
with self.models.db:
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
if new:
await query.edit_message_text(
text="Please enter the content for the entry"
)
return CONTENT
else:
await query.edit_message_text(text="Please enter the date in the format DDMMYYYY")
return DATE_ENTRY
await query.edit_message_text(text="An entry already exists for this date")
return ConversationHandler.END
return CONTENT
async def date_custom(self, update, context):
query = update.callback_query
await query.answer()
await query.edit_message_text(text="Please enter the date in the format DDMMYYYY")
return DATE_ENTRY
async def date_entry(self, update, context):
date = update.message.text
@@ -73,7 +86,6 @@ class JournalHandler(BaseHandler):
except ValueError:
await update.message.reply_text("Please enter the date in the format DDMMYYYY")
return DATE_ENTRY
self.logger.info(f"Date: {date}")
with self.models.db:
self.current_model, new = self.models.JournalEntry.get_or_create(