-.PHONY: serve test strict
+.PHONY: serve tail test strict
MODULE=goals
rm -rf .venv
rm session.txt # Reset session
+tail:
+ tail -f matrix-goal-bot.log
+
test: .venv
.venv/bin/pip install .[test]
.venv/bin/mypy -m $(MODULE)
+import logging
import os
from matrix_goal_bot.bot import GoalBot
+logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG)
+logging.getLogger('nio').setLevel(logging.WARNING)
+logging.getLogger('asyncio').setLevel(logging.WARNING)
+
+logger = logging.getLogger(__name__)
+logger.info("Starting goal bot...")
+
kwargs = {}
# How to connect to Matrix
kwargs['matrix_server'] = os.environ.get('MATRIX_SERVER')
# Prefix to listen for
kwargs['bot_prefix'] = os.environ.get('MATRIX_BOT_PREFIX', '!chore')
+logger.info(f'Goal bot will connect to {kwargs["matrix_server"]} as {kwargs["bot_name"]}')
+
# Where to store data
DATA_DIR = os.environ.get('MATRIX_DATA_DIR', '')
DB_FILE = os.environ.get('MATRIX_DB_FILE', 'goal.db')
kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE)
+logger.info(f'Goal bot will store data at {kwargs["db_file"]}')
+
+
goal_bot = GoalBot(**kwargs)
@goal_bot.bot.listener.on_message_event
return dt.now().strftime(DATE_FORMAT)
logger = logging.getLogger(__name__)
-logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG)
-logging.getLogger('nio').setLevel(logging.WARNING)
snark = [
'Ye cannot get ye flask.',
self.data = Data(db_file)
def run(self):
+ logger.debug('Running goal bot...')
self.bot.run()
async def handle_message(self, room, message):
+ logger.debug(f'Message: {message}')
match = botlib.MessageMatch(room, message, self.bot, self.prefix)
if not match.is_not_from_this_bot() and match.prefix():
from sqlmodel import Field, Session, SQLModel, create_engine, select, text, Relationship
+logger = logging.getLogger(__name__)
DATE_FORMAT = '%Y-%m-%d'
return dt.now().strftime(DATE_FORMAT)
-logger = logging.getLogger(__name__)
-logging.basicConfig(filename='goals.log', encoding='utf-8', level=logging.DEBUG)
-
-
class Vision(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str = Field(default=None, unique=True)
class Data():
def __init__(self, db_file=None):
if not db_file:
- db_file = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'goals.db')
+ db_file = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'goal.db')
self.file = db_file
self.engine = self.get_engine()