]> apps.delaporte.us Git - matrix-cadbury.git/blobdiff - app.py
Fixup
[matrix-cadbury.git] / app.py
diff --git a/app.py b/app.py
index 97b63eec771f40459dac4f96a9f0f43a9944887d..be5d586421ef8db1c2e41f48a2f5f0fd7e951caf 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1,14 +1,59 @@
-from matrix_goal_bot.bot import get_bot, goal_bot
-from matrix_chore_bot.bot import chore_bot
+import os
+
+from matrix_goal_bot.bot import GoalBot
+from matrix_shop_bot.bot import shop_bot
+from matrix_chore_bot.bot import ChoreBot
+
+kwargs = {}
+# How to connect to Matrix
+kwargs['matrix_server'] = os.environ.get('MATRIX_SERVER')
+kwargs['bot_name'] = os.environ.get('MATRIX_BOT')
+kwargs['bot_pwd'] = os.environ.get('MATRIX_BOT_PWD')
+
+# Prefix to listen for
+
+# Where to store data
+DATA_DIR = os.environ.get('MATRIX_DATA_DIR', '')
+DB_FILE = os.environ.get('CHORE_DB_FILE', 'chore.db')
+kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE)
+kwargs['bot_prefix'] = os.environ.get('CHORE_BOT_PREFIX', '!chore')
+chore_bot = ChoreBot(**kwargs) 
+
+
+# Re-use chore_bot's inner bot for goal and shopping
+bot = chore_bot.bot
+
+
+DB_FILE = os.environ.get('GOAL_DB_FILE', 'goal.db')
+kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE)
+kwargs['bot_prefix'] = os.environ.get('GOAL_BOT_PREFIX', '!goal')
+goal_bot = GoalBot(**kwargs) 
+goal_bot.bot = bot
+
+
+@bot.listener.on_message_event
+async def do_chore_stuff(room, message):
+    await chore_bot.handle_message(room, message)
 
-bot = get_bot()
 
 @bot.listener.on_message_event
 async def do_goal_stuff(room, message):
-    await goal_bot(room, message, bot)
+    await goal_bot.handle_message(room, message)
+
 
 @bot.listener.on_message_event
-async def do_chore_stuff(room, message):
-    await chore_bot(room, message, bot)
+async def do_shopping_stuff(room, message):
+    await shop_bot(room, message, bot)
+
+# Bot for daily school tasks, using ChoreBot source code
+kwargs['bot_prefix'] = os.environ.get('SCHOOL_BOT_PREFIX', '!school')
+DB_FILE = os.environ.get('SCHOOL_DB_FILE', 'school.db')
+kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE)
+school_bot = ChoreBot(**kwargs) 
+school_bot.bot = bot
+
+@bot.listener.on_message_event
+async def do_school_stuff(room, message):
+    await school_bot.handle_message(room, message)
 
-bot.run()
+chore_bot.run()