]> apps.delaporte.us Git - matrix-goal-bot.git/commitdiff
Add try/except
authorEdward Delaporte <edward@delaporte.us>
Fri, 27 Mar 2026 05:38:28 +0000 (00:38 -0500)
committerEdward Delaporte <edward@delaporte.us>
Fri, 27 Mar 2026 05:38:28 +0000 (00:38 -0500)
bot.py
goals/db.py

diff --git a/bot.py b/bot.py
index 2891b821c391bac114bff25b3f68af19e9b039bf..d57358d09a4df26dc55ab9a92475ea595e50ec64 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -36,12 +36,13 @@ async def do_goal(match):
       add - add a goal
       add-task ID - add a task under the goal specified by ID
       add-vision - add a new vision (collection of goals)
+      close-goal ID - mark goal done by ID
+      close-vision ID - mark vision as complete by ID
       done ID - mark task done by ID
-      goal-done ID - mark goal done by ID
       list - list incomplete goals
       list-all - list everything
       list-done - list completed goals
-      print ID - print a goal and all tasks
+      print GOAL_ID - print a goal and all tasks
       print-vision ID - print a vision and all goals
       set-vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
       visions - list incomplete visions
@@ -100,13 +101,20 @@ async def do_goal(match):
         results = pretty_print(vision, goals)
         return results
 
-    if match.command('goal-done'):
+    if match.command('close-goal'):
         goal_id = int(match.args()[1])
-        Data().complete_goal(goal_id)
-        goal,tasks = Data().get_goal(goal_id)
-        results = pretty_print(goal, tasks)
+        vision_id = Data().complete_goal(goal_id)
+        vision,goals = Data().get_vision(vision_id)
+        results = pretty_print(vision, goals)
         return results
-    
+
+    if match.command('close-vision'):
+        vision_id = int(match.args()[1])
+        Data().complete_vision(vision_id)
+        vision,goals = Data().get_vision(vision_id)
+        results = pretty_print(vision, goals)
+        return results
+
 
     if match.command('done'):
         task_id = int(match.args()[1])
index 11b546773665e758eadcc77f478001892afb9e8b..dd87978ce7e753c9a413f13df2926dbffbace82b 100644 (file)
@@ -25,7 +25,7 @@ class Vision(SQLModel, table=True):
     complete_date: dt | None = Field(default=None)
     goals: list["Goal"] = Relationship(back_populates="vision")
     def __str__(self):
-        return f'{self.name} ({self.id})'
+        return f'{self.name} (Vision {self.id})'
 
 
 class Goal(SQLModel, table=True):
@@ -37,7 +37,7 @@ class Goal(SQLModel, table=True):
     tasks: list["Task"] = Relationship(back_populates="goal")
     vision: Vision = Relationship(back_populates="goals")
     def __str__(self):
-        return f'{self.name} ({self.id})'
+        return f'{self.name} (Goal {self.id})'
 
 class Task(SQLModel, table=True):
     id: int | None = Field(default=None, primary_key=True)
@@ -116,14 +116,22 @@ class Data():
 
 
     def complete_vision(self, id):
-        pass
+        with Session(self.engine) as session:
+            cmd = select(Vision).where(Vision.id == id)
+            vision = session.exec(cmd).first()
+            vision.complete_date = dt.today()
+            session.commit()
+
 
     def complete_goal(self, id):
+        vision_id = -1
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.id == id)
             goal = session.exec(cmd).first()
             goal.complete_date = dt.today()
+            vision_id = goal.vision_id
             session.commit()
+        return vision_id
 
     def complete_task(self, id):
         with Session(self.engine) as session: