X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-goal-bot.git/blobdiff_plain/f5b4674001d94e6aadbfbcd074fd730917e6c89d..20c4ba82eda7e71635190228655360ee9a37f6c3:/bot.py 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__