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:
commit
3b4015e974
@ -3,7 +3,7 @@ type: kubernetes
|
|||||||
name: docker-build
|
name: docker-build
|
||||||
|
|
||||||
node_selector:
|
node_selector:
|
||||||
kubernetes.io/arch: arm64
|
kubernetes.io/arch: amd64
|
||||||
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -2,7 +2,7 @@ import datetime
|
|||||||
import os
|
import os
|
||||||
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler
|
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler
|
||||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
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
|
from .basehandler import BaseHandler
|
||||||
|
|
||||||
@ -23,9 +23,6 @@ class JournalHandler(BaseHandler):
|
|||||||
],
|
],
|
||||||
ADD_CONTENT: [
|
ADD_CONTENT: [
|
||||||
MessageHandler(filters.ALL, self.content_save),
|
MessageHandler(filters.ALL, self.content_save),
|
||||||
],
|
|
||||||
DELETE_ENTRY: [
|
|
||||||
MessageHandler(filters.ALL, self.delete_entry),
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
fallbacks=[],
|
fallbacks=[],
|
||||||
@ -71,7 +68,7 @@ class JournalHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
if new:
|
if new:
|
||||||
await query.edit_message_text(
|
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:
|
else:
|
||||||
await query.edit_message_text(text="An entry already exists for this date")
|
await query.edit_message_text(text="An entry already exists for this date")
|
||||||
@ -102,7 +99,7 @@ class JournalHandler(BaseHandler):
|
|||||||
date = date
|
date = date
|
||||||
)
|
)
|
||||||
if self.current_model:
|
if self.current_model:
|
||||||
return DELETE_ENTRY
|
await self.delete_entry(update, context)
|
||||||
else:
|
else:
|
||||||
await update.message.reply_text("No entry found for this date")
|
await update.message.reply_text("No entry found for this date")
|
||||||
context.chat_data["delete"] = False
|
context.chat_data["delete"] = False
|
||||||
@ -116,7 +113,7 @@ class JournalHandler(BaseHandler):
|
|||||||
await update.message.reply_text("An entry already exists for this date")
|
await update.message.reply_text("An entry already exists for this date")
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
else:
|
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
|
return ADD_CONTENT
|
||||||
|
|
||||||
|
|
||||||
@ -156,5 +153,4 @@ class JournalHandler(BaseHandler):
|
|||||||
with self.models.db:
|
with self.models.db:
|
||||||
self.current_model.delete_instance()
|
self.current_model.delete_instance()
|
||||||
context.chat_data["delete"] = False
|
context.chat_data["delete"] = False
|
||||||
await update.callback_query.edit_message_text(text="Entry deleted ✅")
|
await update.message.reply_text(text="Entry deleted ✅")
|
||||||
return ConversationHandler.END
|
|
@ -53,7 +53,6 @@ class MemoryHandler(BaseHandler):
|
|||||||
|
|
||||||
return MEMORY_CHOICE
|
return MEMORY_CHOICE
|
||||||
|
|
||||||
|
|
||||||
async def choose_memory(self, update: Update, context: CallbackContext):
|
async def choose_memory(self, update: Update, context: CallbackContext):
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
ind = int(query.data)
|
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.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler
|
||||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
from telegram import Update
|
||||||
|
import re
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
from .basehandler import BaseHandler
|
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):
|
class TurtleHandler(BaseHandler):
|
||||||
def __init__(self):
|
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
|
pass
|
||||||
|
|
||||||
async def entry_point(self, update, context):
|
async def entry_point(self, update: Update, context):
|
||||||
await super().entry_point(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 logging
|
||||||
|
|
||||||
import models
|
import models
|
||||||
from commands import journal, status
|
from commands import journal, status, turtle, memory
|
||||||
from commands.list import list
|
from commands.list import list
|
||||||
from cronjob import chat_photo
|
from cronjob import chat_photo
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||||
level=logging.INFO
|
level=logging.INFO
|
||||||
@ -27,6 +28,9 @@ def main() -> None:
|
|||||||
application.add_handler(journal.JournalHandler("journal", models).handler)
|
application.add_handler(journal.JournalHandler("journal", models).handler)
|
||||||
application.add_handler(list.ListHandler("list", models).handler)
|
application.add_handler(list.ListHandler("list", models).handler)
|
||||||
application.add_handler(status.StatusHandler("status", 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))
|
# application.add_handler(CommandHandler("help", help_command))
|
||||||
# on non command i.e message - echo the message on Telegram
|
# on non command i.e message - echo the message on Telegram
|
||||||
# application.add_handler(InlineQueryHandler(inline_query))
|
# application.add_handler(InlineQueryHandler(inline_query))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from peewee import *
|
from peewee import *
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
ID_MAPPINGS = {
|
ID_MAPPINGS = {
|
||||||
"Lia": 5603036217,
|
"Lia": 5603036217,
|
||||||
@ -52,6 +53,13 @@ class JournalEntry(BaseModel):
|
|||||||
self.save()
|
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):
|
def set_db(db_path):
|
||||||
db.initialize(SqliteDatabase(db_path))
|
db.initialize(SqliteDatabase(db_path))
|
||||||
|
@ -26,7 +26,7 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- name: MEDIA_DIR
|
- name: MEDIA_DIR
|
||||||
value: /journal/media
|
value: /journal/media
|
||||||
- name: tz
|
- name: TZ
|
||||||
value: Europe/Berlin
|
value: Europe/Berlin
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: journal-nfs
|
- name: journal-nfs
|
||||||
@ -41,8 +41,8 @@ kind: PersistentVolume
|
|||||||
metadata:
|
metadata:
|
||||||
namespace: journal
|
namespace: journal
|
||||||
name: "journal-data-nfs"
|
name: "journal-data-nfs"
|
||||||
labels:
|
# labels:
|
||||||
directory: "journal-data"
|
# directory: "journal-data"
|
||||||
spec:
|
spec:
|
||||||
storageClassName: fast
|
storageClassName: fast
|
||||||
capacity:
|
capacity:
|
||||||
@ -50,8 +50,8 @@ spec:
|
|||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
nfs:
|
nfs:
|
||||||
path: /journal-data
|
path: /export/kluster/journal-bot
|
||||||
server: 10.43.239.43 # assigned to nfs-server service. Won't change as long as service is not redeployed
|
server: 192.168.1.157
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@ -66,7 +66,7 @@ spec:
|
|||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: "5Gi"
|
storage: "5Gi"
|
||||||
selector:
|
# selector:
|
||||||
matchLabels:
|
# matchLabels:
|
||||||
directory: "journal-data"
|
# directory: "journal-data"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user