From: Edward Delaporte Date: Fri, 27 Mar 2026 05:38:28 +0000 (-0500) Subject: Add try/except X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/commitdiff_plain/fd24b58ca5172414e700747afc96b04a207f2d33 Add try/except --- diff --git a/bot.py b/bot.py index 2891b82..d57358d 100644 --- 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]) diff --git a/goals/db.py b/goals/db.py index 11b5467..dd87978 100644 --- a/goals/db.py +++ b/goals/db.py @@ -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: