]> apps.delaporte.us Git - matrix-goal-bot.git/commitdiff
Add ability to complete tasks
authorEdward Delaporte <edward@delaporte.us>
Tue, 24 Mar 2026 03:39:22 +0000 (22:39 -0500)
committerEdward Delaporte <edward@delaporte.us>
Tue, 24 Mar 2026 03:39:22 +0000 (22:39 -0500)
bot.py
goals/db.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__
 
 
index 6c3c332b311859877560ce3c1f4f80b0ff69f404..2921bf044aad389cf135975d56a0729090e079f0 100644 (file)
@@ -46,6 +46,18 @@ class Task(SQLModel, table=True):
     def __str__(self):
         return f'{self.name} ({self.id})'
 
     def __str__(self):
         return f'{self.name} ({self.id})'
 
+
+def pretty_print(goal, tasks):
+    results = []
+    results.append(f' ## {goal}')
+    for task in tasks:
+        if(task.complete_date):
+            results.append(f' - [x] {task}')
+        else:
+            results.append(f' - [ ] {task}')
+    return results
+
+
 class Data():
     def __init__(self, db_file = DB_FILE):
         self.file = db_file
 class Data():
     def __init__(self, db_file = DB_FILE):
         self.file = db_file
@@ -90,10 +102,15 @@ class Data():
             goal = session.exec(cmd).first()
             goal.complete_date = dt.today()
             session.commit()
             goal = session.exec(cmd).first()
             goal.complete_date = dt.today()
             session.commit()
-        return self.get_goal(id)
 
     def complete_task(self, id):
 
     def complete_task(self, id):
-        pass
+        with Session(self.engine) as session:
+            cmd = select(Task).where(Task.id == id)
+            task = session.exec(cmd).first()
+            task.complete_date = dt.today()
+            goal_id = task.goal_id
+            session.commit()
+        return goal_id
 
     def add_with_name(self, cls, name):
         id = -1
 
     def add_with_name(self, cls, name):
         id = -1