]> apps.delaporte.us Git - matrix-goal-bot.git/blob - app.py
a34d982950b96b4ce8e775f68f3de126857dd74c
[matrix-goal-bot.git] / app.py
1 import logging
2 import os
3
4 from matrix_goal_bot.bot import GoalBot
5
6 logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG)
7 logging.getLogger('nio').setLevel(logging.WARNING)
8 logging.getLogger('asyncio').setLevel(logging.WARNING)
9
10 logger = logging.getLogger(__name__)
11 logger.info("Starting goal bot...")
12
13 kwargs = {}
14 # How to connect to Matrix
15 kwargs['matrix_server'] = os.environ.get('MATRIX_SERVER')
16 kwargs['bot_name'] = os.environ.get('MATRIX_BOT')
17 kwargs['bot_pwd'] = os.environ.get('MATRIX_BOT_PWD')
18
19 # Prefix to listen for
20 kwargs['bot_prefix'] = os.environ.get('MATRIX_BOT_PREFIX', '!chore')
21
22 logger.info(f'Goal bot will connect to {kwargs["matrix_server"]} as {kwargs["bot_name"]}')
23
24 # Where to store data
25 DATA_DIR = os.environ.get('MATRIX_DATA_DIR', '')
26 DB_FILE = os.environ.get('MATRIX_DB_FILE', 'goal.db')
27 kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE)
28
29 logger.info(f'Goal bot will store data at {kwargs["db_file"]}')
30
31
32 goal_bot = GoalBot(**kwargs)
33
34 @goal_bot.bot.listener.on_message_event
35 async def do_bot_stuff(room, message):
36 '''Pass messages to our bot'''
37 await goal_bot.handle_message(room, message)
38
39 goal_bot.run()
40