From b2820ce90229c71bb92dd43ec77fcee14949df25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lia=20Sch=C3=B6newei=C3=9F?= Date: Sat, 25 Nov 2023 15:57:47 +0100 Subject: [PATCH] bug fixes --- bot/commands/advent.py | 24 +++++++++++++++++------- bot/cronjob/random_memory.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/bot/commands/advent.py b/bot/commands/advent.py index d3845c6..9f9f59f 100644 --- a/bot/commands/advent.py +++ b/bot/commands/advent.py @@ -2,12 +2,21 @@ from datetime import date from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler, CallbackContext from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, InputMediaPhoto import random +import os +from pathlib import Path # ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT = range(3) ACTION, TUERCHEN_CHOICE = range(2) - from .basehandler import BaseHandler +MEDIA_DIR = Path(os.getenv("MEDIA_DIR")) +GIF_LOCATION = MEDIA_DIR / "advent" / "gifs" +GIFS = list(GIF_LOCATION.glob("*.mp4")) +STICKER_LOCATION = MEDIA_DIR / "advent" / "stickers" +STICKERS = list(STICKER_LOCATION.glob("*.tgs")) +PICTURE_LOCATION = MEDIA_DIR / "advent" / "pretty_pictures" +PICTURES = list(PICTURE_LOCATION.glob("*.jpg")) + class AdventsHandler(BaseHandler): def __init__(self, entry_string): self.entry_string = entry_string @@ -66,7 +75,7 @@ class AdventsHandler(BaseHandler): keyboard = [[InlineKeyboardButton("Bubo Küsschen", callback_data="kuss")], [InlineKeyboardButton("Türchen öffnen", callback_data="tuer")], [InlineKeyboardButton("Pretty Bubo Picture", callback_data="picture")]] reply_markup = InlineKeyboardMarkup(keyboard) - await update.message.reply_sticker(sticker=open(".bot_storage\stickers\stickerwhat.tgs", "rb")) + await update.message.reply_sticker(sticker=STICKER_LOCATION/"stickerwhat.tgs") await update.message.reply_text(text="Hallo, mein süßer Weihnachts-Bubo! Ich bin dein Adventskalender ^^. Was möchtest du tun?", reply_markup=reply_markup) return ACTION @@ -79,7 +88,7 @@ class AdventsHandler(BaseHandler): keyboard = [[InlineKeyboardButton("Kalendertürchen öffnen", callback_data="tuer")], [InlineKeyboardButton("Noch ein Küsschen!", callback_data="kuss")], [InlineKeyboardButton("Pretty Bubo Picture", callback_data="picture")], [InlineKeyboardButton("Bis zum nächsten Mal!", callback_data="bye")]] reply_markup = InlineKeyboardMarkup(keyboard) - await update.effective_message.reply_sticker(sticker=open(".bot_storage\stickers\stickerkiss.tgs", "rb")) + await update.effective_message.reply_sticker(sticker=STICKER_LOCATION/"stickerkiss.tgs") await update.effective_message.reply_text(text="Mua!", reply_markup=reply_markup) return ACTION @@ -101,7 +110,8 @@ class AdventsHandler(BaseHandler): reply_markup = InlineKeyboardMarkup(keyboard) picture_number = random.randint(1,31) - await update.effective_message.reply_photo(photo=open(".bot_storage\pretty_pictures\photo_"+f"{picture_number}"+"_2023-11-25_14-25-53.jpg", "rb"), caption="So ein cutes Foto!", reply_markup=reply_markup) + #print(picture_number-1) + await update.effective_message.reply_photo(photo=PICTURES[picture_number-1], caption="So ein cutes Foto!", reply_markup=reply_markup) return ACTION @@ -118,9 +128,9 @@ class AdventsHandler(BaseHandler): #if tuer_nummer <= int(date.today().strftime("%d")): if (tuer_nummer <= int(date.today().strftime("%d"))) and (int(date.today().strftime("%m"))==12): - await update.message.reply_document(document=open(".bot_storage\gifs\gif"+f"{tuer_nummer}"+".mp4", "rb"),caption=f"Türchen für den {tuer_nummer}. Dezember: \n" + self.tuerchen_texte[tuerchen], reply_markup=reply_markup) + await update.message.reply_document(document=GIFS[tuer_nummer-1], caption=f"Türchen für den {tuer_nummer}. Dezember: \n" + self.tuerchen_texte[tuerchen], reply_markup=reply_markup) else: - await update.message.reply_sticker(sticker=open(".bot_storage\stickers\stickerangry.tgs", "rb")) + await update.message.reply_sticker(sticker=STICKER_LOCATION/"stickerangry.tgs") await update.message.reply_text(text="Hey, nicht schummeln! Dieses Türchen darfst du noch nicht sehen.", reply_markup=reply_markup) return ACTION @@ -129,7 +139,7 @@ class AdventsHandler(BaseHandler): query = update.callback_query await query.answer() - await update.effective_message.reply_sticker(sticker=open(".bot_storage\stickers\stickerbye.tgs", "rb")) + await update.effective_message.reply_sticker(sticker=STICKER_LOCATION/"stickerbye.tgs") await update.effective_message.reply_text(text="Bye bye, Bubo! Hab dich ganz doll lieb! 😘") return ConversationHandler.END diff --git a/bot/cronjob/random_memory.py b/bot/cronjob/random_memory.py index ed61e23..43539aa 100644 --- a/bot/cronjob/random_memory.py +++ b/bot/cronjob/random_memory.py @@ -12,7 +12,7 @@ class RandomMemoryJob(): if os.getenv("DOCKERIZED", "false") != "true": # when running locally, annoy the programmer every 60 seconds <3 - job_queue.run_repeating(self.callback_memory, interval=60) + job_queue.run_repeating(self.callback_memory, interval=3600) self.min_age = 0 # do not filter messages: show them all else: # set the message sending time; include UTC shift +2