]> us-delaporte.pagekite.me Git - matrix-chore-bot.git/commitdiff
Add ability to run with separate prefix and database file
authorEdward Delaporte <edward@delaporte.us>
Tue, 31 Mar 2026 21:17:01 +0000 (16:17 -0500)
committerEdward Delaporte <edward@delaporte.us>
Tue, 31 Mar 2026 21:25:05 +0000 (16:25 -0500)
app.py
matrix_chore_bot/bot.py
matrix_chore_bot/db.py

diff --git a/app.py b/app.py
index ead7f4c99dc9ba8e0d6dc2151b5a2e0047e00061..fcc26524e1e055b4c0989906d08f72a825b9040d 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1,9 +1,22 @@
-from matrix_chore_bot.bot import get_bot, chore_bot
+import os
+
+import simplematrixbotlib as botlib
+
+from matrix_chore_bot.bot import chore_bot
+
+SERVER = os.environ.get('MATRIX_SERVER')
+BOT_NAME = os.environ.get('MATRIX_BOT')
+BOT_PWD = os.environ.get('MATRIX_BOT_PWD')
+BOT_PREFIX = os.environ.get('MATRIX_BOT_PREFIX', '!chore')
+
+def get_bot():
+    creds = botlib.Creds(SERVER, BOT_NAME, BOT_PWD)
+    return botlib.Bot(creds)
 
 bot = get_bot()
 
 @bot.listener.on_message_event
 async def do_bot_stuff(room, message):
 
 bot = get_bot()
 
 @bot.listener.on_message_event
 async def do_bot_stuff(room, message):
-    await chore_bot(room, message, bot)
+    await chore_bot(room, message, bot, BOT_PREFIX)
 
 bot.run()
 
 bot.run()
index 8a9e75585c63f8e39d3d6a6eec108d220f98ad23..7e33ade92560c452a0914aad5a0cceda0b6e6d47 100644 (file)
@@ -12,16 +12,12 @@ BOT_PWD = os.environ.get('MATRIX_BOT_PWD')
 
 CHORES = ChoreData()
 
 
 CHORES = ChoreData()
 
-def get_bot():
-    creds = botlib.Creds(SERVER, BOT_NAME, BOT_PWD)
-    return botlib.Bot(creds)
-
 logger = logging.getLogger(__name__)
 logging.basicConfig(filename='matrix-chore-bot.log', encoding='utf-8', level=logging.DEBUG)
 logging.getLogger('nio').setLevel(logging.WARNING)
 
 logger = logging.getLogger(__name__)
 logging.basicConfig(filename='matrix-chore-bot.log', encoding='utf-8', level=logging.DEBUG)
 logging.getLogger('nio').setLevel(logging.WARNING)
 
-async def chore_bot(room, message, bot):
-    match = botlib.MessageMatch(room, message, bot, '!chore')
+async def chore_bot(room, message, bot, prefix='!chore'):
+    match = botlib.MessageMatch(room, message, bot, prefix)
 
     if not match.is_not_from_this_bot() and match.prefix():
         return
 
     if not match.is_not_from_this_bot() and match.prefix():
         return
@@ -33,7 +29,7 @@ async def chore_bot(room, message, bot):
                 await bot.api.send_text_message(
                     room.room_id, str(line))
         except Exception as ex:
                 await bot.api.send_text_message(
                     room.room_id, str(line))
         except Exception as ex:
-            line = 'Ye flask must be load bearing, or something...'
+            line = f'Ye flask must be load bearing, or something... {str(ex)}'
             await bot.api.send_text_message(
                 room.room_id, str(line))
 
             await bot.api.send_text_message(
                 room.room_id, str(line))
 
index 8467d32b0edeefcf1628831a394e534018dcfdb2..536c9c08fb7640e056271763ab69d6bfb35acdfb 100644 (file)
@@ -13,6 +13,8 @@ DATE_FORMAT = '%Y-%m-%d'
 def today():
     return dt.now().strftime(DATE_FORMAT)
 
 def today():
     return dt.now().strftime(DATE_FORMAT)
 
+DEFAULT_DB_FILE = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'chores.db')
+DB_FILE = os.environ.get('MATRIX_CHORE_DB_FILE', DEFAULT_DB_FILE)
 
 logger = logging.getLogger(__name__)
 logging.basicConfig(filename='chore.log', encoding='utf-8', level=logging.DEBUG)
 
 logger = logging.getLogger(__name__)
 logging.basicConfig(filename='chore.log', encoding='utf-8', level=logging.DEBUG)
@@ -39,7 +41,7 @@ class Data():
     def __init__(self, db_file=None):
 
         if not db_file:
     def __init__(self, db_file=None):
 
         if not db_file:
-            db_file = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'chores.db')
+            db_file = DB_FILE
 
         self.file = db_file
         self.engine = self.get_engine()
 
         self.file = db_file
         self.engine = self.get_engine()
@@ -86,7 +88,7 @@ class Data():
             cmd = select(Chore)
             chores = session.exec(cmd).all()
             if(not chores):
             cmd = select(Chore)
             chores = session.exec(cmd).all()
             if(not chores):
-                retuls.append('None Found')
+                results.append('None Found')
 
             for chore in chores:
                 results.append(Data.check_chore(session, chore.id))
 
             for chore in chores:
                 results.append(Data.check_chore(session, chore.id))