Merge branch 'feature/memory-redacted'
	
		
			
	
		
	
	
		
	
		
			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,6 +2,8 @@ import os | |||||||
| from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler, CallbackContext | from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler, CallbackContext | ||||||
| from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, InputMediaPhoto | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, InputMediaPhoto | ||||||
| import models | import models | ||||||
|  | from telegram.constants import ParseMode | ||||||
|  | # ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT = range(3) | ||||||
| MEMORY_CHOICE = range(1) | MEMORY_CHOICE = range(1) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -74,13 +76,15 @@ class MemoryHandler(BaseHandler): | |||||||
|                 caption= |                 caption= | ||||||
|                     f"On {chosen_match.date_pretty}, " |                     f"On {chosen_match.date_pretty}, " | ||||||
|                     f"{chosen_match.author} wrote: \n" |                     f"{chosen_match.author} wrote: \n" | ||||||
|                     f"{chosen_match.text}" |                     f"{chosen_match.spoiler_text}", | ||||||
|  |                 parse_mode=ParseMode.HTML | ||||||
|                 ) |                 ) | ||||||
|         else: |         else: | ||||||
|             await query.edit_message_text( |             await query.edit_message_text( | ||||||
|                 f"On {chosen_match.date_pretty}, " |                 f"On {chosen_match.date_pretty}, " | ||||||
|                 f"{chosen_match.author} wrote: \n" |                 f"{chosen_match.author} wrote: \n" | ||||||
|                 f"{chosen_match.text}" |                 f"{chosen_match.spoiler_text}", | ||||||
|  |                 parse_mode=ParseMode.HTML | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|         return ConversationHandler.END |         return ConversationHandler.END | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| from datetime import time, timedelta, timezone, datetime, date | from datetime import time, timedelta, timezone, datetime, date | ||||||
|  | from telegram.constants import ParseMode | ||||||
| import os | import os | ||||||
| from peewee import fn | from peewee import fn | ||||||
| import logging | import logging | ||||||
| @@ -48,7 +49,8 @@ class RandomMemoryJob(): | |||||||
|                 caption = |                 caption = | ||||||
|                     f"On {chosen_entry.date_pretty}, " |                     f"On {chosen_entry.date_pretty}, " | ||||||
|                     f"{chosen_entry.author} wrote: \n" |                     f"{chosen_entry.author} wrote: \n" | ||||||
|                     f"{chosen_entry.text}" |                     f"{chosen_entry.spoiler_text}", | ||||||
|  |                 parse_mode=ParseMode.HTML | ||||||
|                 ) |                 ) | ||||||
|         else: |         else: | ||||||
|             await self.bot.send_message( |             await self.bot.send_message( | ||||||
| @@ -56,6 +58,7 @@ class RandomMemoryJob(): | |||||||
|                 text = |                 text = | ||||||
|                     f"On {chosen_entry.date_pretty}, " |                     f"On {chosen_entry.date_pretty}, " | ||||||
|                     f"{chosen_entry.author} wrote: \n" |                     f"{chosen_entry.author} wrote: \n" | ||||||
|                     f"{chosen_entry.text}" |                     f"{chosen_entry.spoiler_text}", | ||||||
|  |                 parse_mode=ParseMode.HTML | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| from peewee import * | from peewee import * | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
|  | import re | ||||||
| import os | import os | ||||||
| import datetime | import datetime | ||||||
|  |  | ||||||
| @@ -60,6 +61,25 @@ class JournalEntry(BaseModel): | |||||||
|         except ValueError: #fck windows |         except ValueError: #fck windows | ||||||
|             return self.date.strftime('%a, %d. %b %Y') |             return self.date.strftime('%a, %d. %b %Y') | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def spoiler_text(self) -> str: | ||||||
|  |         """Returns the text with all the frisky details hidden away""" | ||||||
|  |         new_text = self.text.replace("<", "<").replace(">", ">").replace("&", "&") | ||||||
|  |         pattern = re.compile( | ||||||
|  |             "(" | ||||||
|  |             "(((?<=(\.|\!|\?)\s)[A-Z])|(^[A-Z]))" # beginning of a sentence | ||||||
|  |             "([^\.\!\?])+" # any character being part of a sentence | ||||||
|  |             "\:\)" # the smiley | ||||||
|  |             "([^\.\!\?])*" # continuation of sentence | ||||||
|  |             "(\.|\!|\?|\,|$)" # end of the sentence | ||||||
|  |             ")" | ||||||
|  |         ) | ||||||
|  |         matches = pattern.findall(new_text) | ||||||
|  |         for match in matches: | ||||||
|  |             group_to_replace = match[0] | ||||||
|  |             new_text = new_text.replace(group_to_replace, f"<tg-spoiler>{group_to_replace}</tg-spoiler>") | ||||||
|  |         return new_text | ||||||
|  |          | ||||||
|  |  | ||||||
| def set_db(db_path): | def set_db(db_path): | ||||||
|     db.initialize(SqliteDatabase(db_path)) |     db.initialize(SqliteDatabase(db_path)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Lia Schöneweiß
					Lia Schöneweiß