]> apps.delaporte.us Git - matrix-goal-bot.git/blobdiff - bot.py
Add ability to complete tasks
[matrix-goal-bot.git] / bot.py
diff --git a/bot.py b/bot.py
index a6e7f65615c78ab051a406262d385fc60025c77d..649cfe69e753333464ed4dd65cb6ee02ad218a7b 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -4,7 +4,7 @@ import os
 
 import simplematrixbotlib as botlib
 
 
 import simplematrixbotlib as botlib
 
-from goals.db import Data
+from goals.db import Data, pretty_print
 
 
 SERVER = os.environ.get('MATRIX_SERVER')
 
 
 SERVER = os.environ.get('MATRIX_SERVER')
@@ -59,22 +59,25 @@ async def do_goal(match):
         goal_id = int(match.args()[1])
         logger.debug(f'Searching for goal {goal_id}...')
         goal,tasks = Data().get_goal(goal_id)
         goal_id = int(match.args()[1])
         logger.debug(f'Searching for goal {goal_id}...')
         goal,tasks = Data().get_goal(goal_id)
-
-        results = []
-        results.append(f' ## {goal}')
-        for task in tasks:
-            if(task.complete_date):
-                results.append(f' - [x] {task}')
-            else:
-                results.append(f' - [ ] {task}')
+        results = pretty_print(goal, tasks)
         return results
 
         return results
 
-    if match.command('done'):
+    if match.command('goal-done'):
         goal_id = int(match.args()[1])
         logger.debug(f'Searching for goal {goal_id}...')
         goal_id = int(match.args()[1])
         logger.debug(f'Searching for goal {goal_id}...')
-        result = Data().complete_goal(goal_id)
-        return [result]
+        Data().complete_goal(goal_id)
+        goal,tasks = Data().get_goal(goal_id)
+        results = pretty_print(goal, tasks)
+        return results
     
     
+
+    if match.command('done'):
+        task_id = int(match.args()[1])
+        goal_id = Data().complete_task(task_id)
+        goal,tasks = Data().get_goal(goal_id)
+        results = pretty_print(goal, tasks)
+        return results
+
     return __doc__
 
 
     return __doc__