From: Edward Delaporte Date: Tue, 24 Mar 2026 03:39:22 +0000 (-0500) Subject: Add ability to complete tasks X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-goal-bot.git/commitdiff_plain/20c4ba82eda7e71635190228655360ee9a37f6c3?ds=inline Add ability to complete tasks --- diff --git a/bot.py b/bot.py index a6e7f65..649cfe6 100644 --- a/bot.py +++ b/bot.py @@ -4,7 +4,7 @@ import os import simplematrixbotlib as botlib -from goals.db import Data +from goals.db import Data, pretty_print 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) - - 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 - if match.command('done'): + if match.command('goal-done'): 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__ diff --git a/goals/db.py b/goals/db.py index 6c3c332..2921bf0 100644 --- a/goals/db.py +++ b/goals/db.py @@ -46,6 +46,18 @@ class Task(SQLModel, table=True): 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 @@ -90,10 +102,15 @@ class Data(): goal = session.exec(cmd).first() goal.complete_date = dt.today() session.commit() - return self.get_goal(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