summaryrefslogtreecommitdiffstats
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py45
1 files changed, 45 insertions, 0 deletions
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()
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage