Compare commits
No commits in common. "1ca13a9451c0984eb73c1776f736beb7aaa0a270" and "2d923df965a17d93ca9c48ed4510de2f4eed4b33" have entirely different histories.
1ca13a9451
...
2d923df965
9
.vscode/launch.json
vendored
9
.vscode/launch.json
vendored
@ -4,6 +4,15 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "Python: Current project",
|
||||
"type": "python",
|
||||
|
@ -1,7 +1,3 @@
|
||||
# journal-bot
|
||||
|
||||
Sharing memories, the digital way...
|
||||
|
||||
|
||||
## Migration 10.03.24
|
||||
ALTER TABLE journalentry ADD COLUMN rating INTEGER;
|
@ -5,7 +5,7 @@ from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
import models
|
||||
|
||||
ENTRY_OPTIONS, CONTENT_ENTRY, DAY_RATING = range(3)
|
||||
ENTRY_OPTIONS, CONTENT_ENTRY = range(2)
|
||||
BUTTON_COUNT = 5
|
||||
|
||||
|
||||
@ -26,9 +26,6 @@ class JournalHandler(BaseHandler):
|
||||
CONTENT_ENTRY: [
|
||||
MessageHandler(filters.ALL, self.content_save),
|
||||
],
|
||||
DAY_RATING: [
|
||||
CallbackQueryHandler(self.day_rating_save),
|
||||
],
|
||||
},
|
||||
fallbacks=[],
|
||||
)
|
||||
@ -44,12 +41,21 @@ class JournalHandler(BaseHandler):
|
||||
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i)).date() for i in range(BUTTON_COUNT + 2)][::-1]
|
||||
# since there are two buttons additional buttons, we need to have two more days
|
||||
names = get_names(dates)
|
||||
names = [d.strftime("%d.%m.") for d in dates]
|
||||
callbacks = [d.strftime("%d%m%Y") for d in dates]
|
||||
names[-1] = "Today"
|
||||
names[-2] = "Yesterday"
|
||||
|
||||
options = [
|
||||
[InlineKeyboardButton(n, callback_data=c)] for n,c in zip(names[::-1], callbacks[::-1])
|
||||
] + [
|
||||
[
|
||||
InlineKeyboardButton(names[-1], callback_data=callbacks[-1])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(names[-2], callback_data=callbacks[-2])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(n, callback_data=c) for n,c in zip(names[:-2], callbacks[:-2])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=BUTTON_COUNT + 2)
|
||||
],
|
||||
@ -89,16 +95,16 @@ class JournalHandler(BaseHandler):
|
||||
delta = int(query.data)
|
||||
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i + delta)).date() for i in range(BUTTON_COUNT)][::-1]
|
||||
names = get_names(dates)
|
||||
names = [d.strftime("%d.%m.") for d in dates]
|
||||
callbacks = [d.strftime("%d%m%Y") for d in dates]
|
||||
|
||||
options = [
|
||||
[
|
||||
InlineKeyboardButton(">>", callback_data=delta - BUTTON_COUNT)
|
||||
]
|
||||
] + [
|
||||
[InlineKeyboardButton(n, callback_data=c)] for n,c in zip(names[::-1], callbacks[::-1])
|
||||
] + [
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(n, callback_data=c) for n,c in zip(names, callbacks)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=delta + BUTTON_COUNT)
|
||||
],
|
||||
@ -167,23 +173,7 @@ class JournalHandler(BaseHandler):
|
||||
|
||||
self.current_model.save()
|
||||
|
||||
options = [
|
||||
[InlineKeyboardButton(models.RATING_MAPPING[idx], callback_data=idx) for idx in [1,2,3,4,5]]
|
||||
]
|
||||
|
||||
await update.message.reply_text(f"Saved entry ✅. How was the day?", reply_markup=InlineKeyboardMarkup(options))
|
||||
|
||||
return DAY_RATING
|
||||
|
||||
|
||||
async def day_rating_save(self, update, context):
|
||||
query = update.callback_query
|
||||
await query.answer()
|
||||
rating = int(query.data)
|
||||
with models.db:
|
||||
self.current_model.rating = rating
|
||||
self.current_model.save()
|
||||
await query.edit_message_text(text="Rating saved ✅")
|
||||
await update.message.reply_text(f"Saved entry ✅")
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
@ -200,22 +190,3 @@ class JournalHandler(BaseHandler):
|
||||
self.current_model.delete_instance()
|
||||
context.chat_data["delete"] = False
|
||||
await update.message.reply_text(text="Entry deleted ✅")
|
||||
|
||||
|
||||
|
||||
### HELPERS
|
||||
|
||||
def get_names(dates: list):
|
||||
names = []
|
||||
for d in dates:
|
||||
suffix = ""
|
||||
if models.JournalEntry.get_or_none(date = d):
|
||||
suffix = " ✅"
|
||||
|
||||
if d == datetime.datetime.now().date():
|
||||
names.append("Today" + suffix)
|
||||
elif d == datetime.datetime.now().date() - datetime.timedelta(days = 1):
|
||||
names.append("Yesterday" + suffix)
|
||||
else:
|
||||
names.append(d.strftime("%d.%m.") + suffix)
|
||||
return names
|
||||
|
@ -69,22 +69,21 @@ class MemoryHandler(BaseHandler):
|
||||
matching_models = context.chat_data["kept_matches"]
|
||||
chosen_match = matching_models[ind]
|
||||
|
||||
rating_string = f" ({models.RATING_MAPPING[chosen_match.rating]})" if chosen_match.rating else ""
|
||||
|
||||
message_text = f"On {chosen_match.date_pretty}{rating_string}, " \
|
||||
f"{chosen_match.author} wrote: \n" \
|
||||
f"{chosen_match.spoiler_text}"
|
||||
|
||||
if chosen_match.media_path:
|
||||
# context.bot.sendPhoto()
|
||||
await update.effective_message.reply_photo(
|
||||
photo = chosen_match.media_path,
|
||||
caption = message_text,
|
||||
caption=
|
||||
f"On {chosen_match.date_pretty}, "
|
||||
f"{chosen_match.author} wrote: \n"
|
||||
f"{chosen_match.spoiler_text}",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
else:
|
||||
await query.edit_message_text(
|
||||
message_text,
|
||||
f"On {chosen_match.date_pretty}, "
|
||||
f"{chosen_match.author} wrote: \n"
|
||||
f"{chosen_match.spoiler_text}",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
|
||||
|
@ -42,24 +42,23 @@ class RandomMemoryJob():
|
||||
|
||||
chat_id = os.getenv("CHAT_ID")
|
||||
|
||||
rating_string = f" ({models.RATING_MAPPING[chosen_entry.rating]})" if chosen_entry.rating else ""
|
||||
|
||||
message_text = f"On {chosen_entry.date_pretty}{rating_string}, " \
|
||||
f"{chosen_entry.author} wrote: \n" \
|
||||
f"{chosen_entry.spoiler_text}"
|
||||
|
||||
|
||||
if chosen_entry.media_path:
|
||||
await self.bot.send_photo(
|
||||
chat_id = chat_id,
|
||||
photo = chosen_entry.media_path,
|
||||
caption = message_text,
|
||||
caption =
|
||||
f"On {chosen_entry.date_pretty}, "
|
||||
f"{chosen_entry.author} wrote: \n"
|
||||
f"{chosen_entry.spoiler_text}",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
else:
|
||||
await self.bot.send_message(
|
||||
chat_id = chat_id,
|
||||
text = message_text,
|
||||
text =
|
||||
f"On {chosen_entry.date_pretty}, "
|
||||
f"{chosen_entry.author} wrote: \n"
|
||||
f"{chosen_entry.spoiler_text}",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
|
||||
|
@ -10,14 +10,6 @@ ID_MAPPINGS = {
|
||||
}
|
||||
ID_MAPPINGS_REV = dict((v, k) for k, v in ID_MAPPINGS.items())
|
||||
|
||||
RATING_MAPPING = {
|
||||
1: "😵",
|
||||
2: "☹️",
|
||||
3: "😐",
|
||||
4: "😃",
|
||||
5: "🥰"
|
||||
}
|
||||
|
||||
MEDIA_DIR = Path(os.getenv("MEDIA_DIR"))
|
||||
MEDIA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@ -36,7 +28,7 @@ class JournalEntry(BaseModel):
|
||||
text = TextField(null=True)
|
||||
media_path = TextField(null=True)
|
||||
last_shown = DateField(null=True)
|
||||
rating = IntegerField(null=True) # mapped by RATING_MAPPING
|
||||
|
||||
|
||||
@property
|
||||
def media(self):
|
||||
@ -77,7 +69,7 @@ class JournalEntry(BaseModel):
|
||||
"("
|
||||
"(((?<=(\.|\!|\?)\s)[A-Z])|(^[A-Z]))" # beginning of a sentence
|
||||
"([^\.\!\?])+" # any character being part of a sentence
|
||||
"((\:\))|😇|😈|[Ss]ex)" # the smiley
|
||||
"((\:\))|😇|😈)" # the smiley
|
||||
"([^\.\!\?])*" # continuation of sentence
|
||||
"(\.|\!|\?|\,|$)" # end of the sentence
|
||||
")"
|
||||
|
Loading…
x
Reference in New Issue
Block a user