From 84fef8d071e4253f41f29cce96a1a5f9b1be5e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lia=20Sch=C3=B6newei=C3=9F?= Date: Mon, 8 May 2023 11:50:07 +0200 Subject: [PATCH] added more reactions --- bot/commands/turtle.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/bot/commands/turtle.py b/bot/commands/turtle.py index 0ca43e0..9d3e058 100644 --- a/bot/commands/turtle.py +++ b/bot/commands/turtle.py @@ -3,6 +3,8 @@ 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 from .basehandler import BaseHandler @@ -15,19 +17,38 @@ TURTLE_VIDEOS = list(TURTLE_VIDEO_LOCATION.glob("*.mp4")) class TurtleHandler(BaseHandler): def __init__(self): self.entry_string = "Variation of hallo" - self.handler = MessageHandler(filters.Regex(r"Hallo|hallo"), self.entry_point) + 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: Update, context): await super().entry_point(update, context) msgtxt = update.message.text - if "hallo" in msgtxt: - vid = TURTLE_VIDEOS[0] - answertxt = "hallo1" - elif "Hallo" in msgtxt: - vid = TURTLE_VIDEOS[1] - answertxt = "Hallo2" + turtle_emoji = b"\xF0\x9F\x90\xA2".decode("utf8") - await update.message.reply_video(video=vid, caption=answertxt) - # await update.message.reply_text(text=answertxt) + 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: + await update.message.reply_video(video=vid, caption=answertxt) + else: + await update.message.reply_text(text=answertxt) \ No newline at end of file