diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-03-06 02:58:32 -0800 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-03-06 02:58:49 -0800 |
| commit | 0b2cf39d7b533342139f669ed41b5c4f11ba859c (patch) | |
| tree | 3c76ff9796cecb89d71e9b921b1041a08d680b05 /bot.py | |
init commit
Diffstat (limited to 'bot.py')
| -rw-r--r-- | bot.py | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -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() |
