From 0b2cf39d7b533342139f669ed41b5c4f11ba859c Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 6 Mar 2026 02:58:32 -0800 Subject: init commit --- bot.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bot.py (limited to 'bot.py') diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..0986d5f --- /dev/null +++ b/bot.py @@ -0,0 +1,45 @@ +import simplematrixbotlib as botlib +import os +from dotenv import load_dotenv +import constants +import restaurants + +load_dotenv() + +HOMESERVER = os.environ.get("HOMESERVER", "") +USERNAME = os.environ.get("USERNAME", "") +ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN", "") +TARGET_ROOM_ID = os.environ.get("TARGET_ROOM_ID", "") + +creds = botlib.Creds(homeserver=HOMESERVER, username=USERNAME, access_token=ACCESS_TOKEN) +bot = botlib.Bot(creds) + +restaurants.init_db() + + +@bot.listener.on_message_event +async def trigger_responses(room, message): + if message.sender == f"@{USERNAME}": + return + if room.room_id != TARGET_ROOM_ID: + return + + if await restaurants.handle_restaurant_command(bot.api, room.room_id, message.sender, message.body): + return + + msg_text = message.body.strip().lower() + cleaned = ''.join(ch if ch.isalnum() else ' ' for ch in msg_text) + words = cleaned.split() + normalized = ' ' + ' '.join(words) + ' ' + match = None + for key in constants.TRIGGERS: + key_str = str(key).lower() + key_clean = ''.join(ch if ch.isalnum() else ' ' for ch in key_str) + key_norm = ' ' + ' '.join(key_clean.split()) + ' ' + if key_norm and key_norm in normalized: + match = key + break + if match: + msg_text = match + await bot.api.send_text_message(room.room_id, f"{message.sender} {constants.TRIGGERS[msg_text]}") +bot.run() -- cgit v1.2.3