From: Edward Delaporte Date: Sat, 28 Mar 2026 00:10:01 +0000 (-0500) Subject: Repack for easier reuse X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/commitdiff_plain/ec5ce64bec2a57f7b884d09b663c12f3447b3809?ds=inline Repack for easier reuse --- diff --git a/Makefile b/Makefile index 42608b6..a73de66 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ MODULE=goals .venv/bin/pip install . serve: .venv - .venv/bin/python bot.py + .venv/bin/python app.py clean: rm -rf .venv diff --git a/app.py b/app.py new file mode 100644 index 0000000..a4a6395 --- /dev/null +++ b/app.py @@ -0,0 +1,9 @@ +from goals.bot import get_bot, goal_bot + +bot = get_bot() + +@bot.listener.on_message_event +def do_bot_stuff(room, message): + goal_bot(room, message) + +bot.run() diff --git a/bot.py b/goals/bot.py similarity index 97% rename from bot.py rename to goals/bot.py index d57358d..9b630f8 100644 --- a/bot.py +++ b/goals/bot.py @@ -6,18 +6,19 @@ import simplematrixbotlib as botlib from goals.db import Data, pretty_print - SERVER = os.environ.get('MATRIX_SERVER') BOT_NAME = os.environ.get('GOAL_BOT') BOT_PWD = os.environ.get('GOAL_BOT_PWD') +def get_bot(): + creds = botlib.Creds(SERVER, BOT_NAME, BOT_PWD) + return botlib.Bot(creds) + DATE_FORMAT = '%Y-%m-%d' def today(): return dt.now().strftime(DATE_FORMAT) -creds = botlib.Creds(SERVER, BOT_NAME, BOT_PWD) -bot = botlib.Bot(creds) PREFIX = '!goal' logger = logging.getLogger(__name__) @@ -153,8 +154,7 @@ async def do_goal(match): return [do_goal.__doc__] -@bot.listener.on_message_event -async def goals(room, message): +async def goal_bot(room, message): match = botlib.MessageMatch(room, message, bot, PREFIX) if not match.is_not_from_this_bot() and match.prefix(): @@ -170,5 +170,3 @@ async def goals(room, message): return ['Ye cannot get ye flask.'] -bot.run() -