Merge branch 'main' of ssh://git.kluster.moll.re:2222/remoll/journal-bot
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		| @@ -2,7 +2,7 @@ import datetime | ||||
| import os | ||||
| from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler | ||||
| from telegram import InlineKeyboardButton, InlineKeyboardMarkup | ||||
| ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT, DELETE_ENTRY = range(4) | ||||
| ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT = range(3) | ||||
|  | ||||
| from .basehandler import BaseHandler | ||||
|  | ||||
| @@ -23,10 +23,7 @@ class JournalHandler(BaseHandler): | ||||
|                     ], | ||||
|                 ADD_CONTENT: [ | ||||
|                     MessageHandler(filters.ALL, self.content_save), | ||||
|                     ], | ||||
|                 DELETE_ENTRY: [ | ||||
|                     MessageHandler(filters.ALL, self.delete_entry), | ||||
|                 ] | ||||
|                     ] | ||||
|             }, | ||||
|             fallbacks=[], | ||||
|         ) | ||||
| @@ -71,7 +68,7 @@ class JournalHandler(BaseHandler): | ||||
|             ) | ||||
|         if new: | ||||
|             await query.edit_message_text( | ||||
|                 text=f"What is your entry for {self.current_model.date.strftime('%A, %-d. %B %Y')}?" | ||||
|                 text=f"What is your entry for {self.current_model.date_pretty}?" | ||||
|             ) | ||||
|         else: | ||||
|             await query.edit_message_text(text="An entry already exists for this date") | ||||
| @@ -102,11 +99,11 @@ class JournalHandler(BaseHandler): | ||||
|                     date = date | ||||
|                 ) | ||||
|             if self.current_model: | ||||
|                 return DELETE_ENTRY | ||||
|                 await self.delete_entry(update, context) | ||||
|             else: | ||||
|                 await update.message.reply_text("No entry found for this date") | ||||
|                 context.chat_data["delete"] = False | ||||
|                 return ConversationHandler.END | ||||
|             return ConversationHandler.END | ||||
|         else: | ||||
|             with self.models.db: | ||||
|                 self.current_model, new = self.models.JournalEntry.get_or_create( | ||||
| @@ -116,7 +113,7 @@ class JournalHandler(BaseHandler): | ||||
|                 await update.message.reply_text("An entry already exists for this date") | ||||
|                 return ConversationHandler.END | ||||
|             else: | ||||
|                 await update.message.reply_text(f"What is your entry for {self.current_model.date.strftime('%A, %-d. %B %Y')}?") | ||||
|                 await update.message.reply_text(f"What is your entry for {self.current_model.date_pretty}?") | ||||
|                 return ADD_CONTENT | ||||
|  | ||||
|  | ||||
| @@ -156,5 +153,4 @@ class JournalHandler(BaseHandler): | ||||
|         with self.models.db: | ||||
|             self.current_model.delete_instance() | ||||
|         context.chat_data["delete"] = False | ||||
|         await update.callback_query.edit_message_text(text="Entry deleted ✅") | ||||
|         return ConversationHandler.END | ||||
|         await update.message.reply_text(text="Entry deleted ✅") | ||||
| @@ -53,7 +53,6 @@ class MemoryHandler(BaseHandler): | ||||
|          | ||||
|         return MEMORY_CHOICE | ||||
|  | ||||
|  | ||||
|     async def choose_memory(self, update: Update, context: CallbackContext): | ||||
|         query = update.callback_query | ||||
|         ind = int(query.data) | ||||
|   | ||||
| @@ -1,13 +1,66 @@ | ||||
| import os | ||||
| from pathlib import Path | ||||
| from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler | ||||
| from telegram import InlineKeyboardButton, InlineKeyboardMarkup | ||||
| from telegram import Update | ||||
| import re | ||||
| import random | ||||
| import time | ||||
|  | ||||
| from .basehandler import BaseHandler | ||||
|  | ||||
|  | ||||
| MEDIA_DIR = Path(os.getenv("MEDIA_DIR")) | ||||
| TURTLE_VIDEO_LOCATION = MEDIA_DIR / "turtle_reactions" | ||||
|  | ||||
| TURTLE_VIDEOS = list(TURTLE_VIDEO_LOCATION.glob("*.mp4")) | ||||
|  | ||||
| class TurtleHandler(BaseHandler): | ||||
|     def __init__(self): | ||||
|         self.handler = MessageHandler(filters.Regex(r"Hallo|hallo"), self.entry_point) | ||||
|         self.entry_string = "Variation of hallo" | ||||
|         self.handler = MessageHandler(filters.Regex(r"[hH]([aA]+|[eE]+)[lL]{2,}[oOöÖ]+(le)?|(chen)") |  # react to hello strings | ||||
|                                       filters.Regex(b"\xF0\x9F\x90\xA2".decode("utf8")) |               # react to turtle emoji | ||||
|                                       filters.Regex(r"[sS](childkröte)|[tT](urtle)"),                   # react to turtle string | ||||
|                                       self.entry_point) | ||||
|         pass | ||||
|  | ||||
|     async def entry_point(self, update, context): | ||||
|     async def entry_point(self, update: Update, context): | ||||
|         await super().entry_point(update, context) | ||||
|         update.message.reply_ | ||||
|         msgtxt = update.message.text | ||||
|         turtle_emoji = b"\xF0\x9F\x90\xA2".decode("utf8") | ||||
|  | ||||
|         if "hallo" in msgtxt:                                               # react to hallo | ||||
|             vid = TURTLE_VIDEOS[0] | ||||
|             answertxt = "Hallo!" | ||||
|         elif re.search("[eE][lL]{2,}[oO]", msgtxt):                         # react to hello | ||||
|             vid = TURTLE_VIDEOS[2] | ||||
|             answertxt = "Hello!"         | ||||
|         elif re.search("([aA]{4,}|[lL]{4,}|[oO]{4,}|[öÖ]{4,})", msgtxt):    # react to stretched hello | ||||
|             vid = TURTLE_VIDEOS[5] | ||||
|             answertxt = "That's a lot of letters!" | ||||
|         elif re.search(turtle_emoji, msgtxt):                               # react to turtle emoji | ||||
|             vid=TURTLE_VIDEOS[0] # TODO: choose video for smiley reaction | ||||
|             answertxt="Turtle detected! Self-destruction mode activated..." | ||||
|         elif re.search("[sS](childkröte)|[tT](urtle)", msgtxt):             # react to turtle string | ||||
|             vid=None | ||||
|             answertxt=turtle_emoji | ||||
|         else: | ||||
|             vid = random.choice(TURTLE_VIDEOS[1:2]+TURTLE_VIDEOS[3:5]+TURTLE_VIDEOS[6:]) | ||||
|             answertxt = "" | ||||
|  | ||||
|         if vid!=None: | ||||
|             if re.search(turtle_emoji, msgtxt): | ||||
|                 await update.message.reply_text(text=answertxt) | ||||
|                 time.sleep(1) | ||||
|                 await update.message.reply_text(text="3") | ||||
|                 time.sleep(1) | ||||
|                 await update.message.reply_text(text="2") | ||||
|                 time.sleep(1) | ||||
|                 await update.message.reply_text(text="1") | ||||
|                 time.sleep(1) | ||||
|                 await update.message.reply_video(video=vid, caption="Kaboom!") | ||||
|             else: | ||||
|                 await update.message.reply_video(video=vid, caption=answertxt) | ||||
|         else: | ||||
|             await update.message.reply_text(text=answertxt) | ||||
|          | ||||
| @@ -3,9 +3,10 @@ from telegram.ext import Application | ||||
| import logging | ||||
|  | ||||
| import models | ||||
| from commands import journal, status | ||||
| from commands import journal, status, turtle, memory | ||||
| from commands.list import list | ||||
| from cronjob import chat_photo | ||||
|  | ||||
| logging.basicConfig( | ||||
|     format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||||
|     level=logging.INFO | ||||
| @@ -27,6 +28,9 @@ def main() -> None: | ||||
|     application.add_handler(journal.JournalHandler("journal", models).handler) | ||||
|     application.add_handler(list.ListHandler("list", models).handler) | ||||
|     application.add_handler(status.StatusHandler("status", models).handler) | ||||
|     application.add_handler(turtle.TurtleHandler().handler) | ||||
|     application.add_handler(memory.MemoryHandler("memory", models).handler) | ||||
|  | ||||
|     # application.add_handler(CommandHandler("help", help_command)) | ||||
|     # on non command i.e message - echo the message on Telegram | ||||
|     # application.add_handler(InlineQueryHandler(inline_query)) | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| from peewee import * | ||||
| from pathlib import Path | ||||
| import os | ||||
| import datetime | ||||
|  | ||||
| ID_MAPPINGS = { | ||||
|     "Lia": 5603036217, | ||||
| @@ -52,6 +53,13 @@ class JournalEntry(BaseModel): | ||||
|         self.save() | ||||
|  | ||||
|  | ||||
|     @property | ||||
|     def date_pretty(self) -> str: | ||||
|         try: | ||||
|             return self.date.strftime('%A, %-d. %B %Y') | ||||
|         except ValueError: #fck windows | ||||
|             return self.date.strftime('%a, %d. %b %Y') | ||||
|  | ||||
|  | ||||
| def set_db(db_path): | ||||
|     db.initialize(SqliteDatabase(db_path)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lia Schöneweiß
					Lia Schöneweiß