lists working
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-21 22:05:27 +02:00
parent b5551eb596
commit e9d2582606
7 changed files with 216 additions and 36 deletions

View File

@@ -4,13 +4,14 @@ from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, fi
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
DATE_CHOICE, DATE_ENTRY, CONTENT = range(3)
from .basehandler import BaseHandler
class JournalHandler:
class JournalHandler(BaseHandler):
def __init__(self, entry_string, models):
self.models = models
self.entry_string = entry_string
self.handler = ConversationHandler(
entry_points=[CommandHandler(entry_string, self.start)],
entry_points=[CommandHandler(entry_string, self.entry_point)],
states={
DATE_CHOICE: [
CallbackQueryHandler(self.date_choice),
@@ -19,8 +20,7 @@ class JournalHandler:
MessageHandler(filters.TEXT, self.date_entry),
],
CONTENT: [
MessageHandler(filters.TEXT, self.content_text),
MessageHandler(filters.ATTACHMENT, self.content_media),
MessageHandler(filters.ALL, self.content_save),
],
},
fallbacks=[],
@@ -29,11 +29,8 @@ class JournalHandler:
self.current_model = None
async def start(self, update, context):
"""Send a message when the command /start is issued."""
print(f"User: {update.message.from_user.id}")
print(f"Chat: {update.message.chat_id}")
async def entry_point(self, update, context):
await super().entry_point(update, context)
if os.getenv("DOCKERIZED", "false") == "true" and os.getenv("CHAT_ID") != str(update.message.chat_id):
await update.message.reply_text("You are not authorized to use this bot")
return ConversationHandler.END
@@ -86,25 +83,23 @@ class JournalHandler:
return CONTENT
async def content_text(self, update, context):
self.current_model.text = update.message.text
self.current_model.author_id = update.message.from_user.id
self.current_model.save()
return ConversationHandler.END
async def content_media(self, update, context):
async def content_save(self, update, context):
self.current_model.author_id = update.message.from_user.id
if update.message.photo:
file = await update.message.effective_attachment[-1].get_file()
if update.message.text:
self.current_model.text = update.message.text
else:
file = await update.message.effective_attachment.get_file()
file_bytes = await file.download_as_bytearray()
file_path = file.file_path
self.current_model.save_media(file_bytes, file_path)
if update.message.photo:
file = await update.message.effective_attachment[-1].get_file()
else:
file = await update.message.effective_attachment.get_file()
file_bytes = await file.download_as_bytearray()
file_path = file.file_path
self.current_model.save_media(file_bytes, file_path)
self.current_model.text = update.message.caption
self.current_model.text = update.message.caption
self.current_model.save()
await update.message.reply_text(f"Saved entry for {self.current_model.date.strftime('%A, %-d. %B %Y')}")
return ConversationHandler.END