]> apps.delaporte.us Git - matrix-goal-bot.git/blobdiff - goals/bot.py
Repack for easier reuse
[matrix-goal-bot.git] / goals / bot.py
similarity index 97%
rename from bot.py
rename to goals/bot.py
index d57358d09a4df26dc55ab9a92475ea595e50ec64..9b630f867e88de6479f1487a2524119b39a33344 100644 (file)
--- a/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()
-