From: Edward Delaporte Date: Tue, 31 Mar 2026 21:30:11 +0000 (-0500) Subject: Add filter command X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-chore-bot.git/commitdiff_plain/99f1517e1c2cd574b1969a79d5631769f789debb Add filter command --- diff --git a/matrix_chore_bot/bot.py b/matrix_chore_bot/bot.py index 7e33ade..c97be63 100644 --- a/matrix_chore_bot/bot.py +++ b/matrix_chore_bot/bot.py @@ -47,15 +47,24 @@ async def handle_chore(match): check - check status of a chore done - mark a chore as done list - print the chore list + filter TERM - list all chores that include TERM undo - mark a chore as undone ''' if match.command('list'): - results = ['## Listing chores...'] + results = ['## Listing all...'] for item in CHORES.list(): results.append(item) results.append('-- End of List --') return results + + if match.command('filter'): + term = ' '.join(match.args()[1:]) + results = [f'## List matching {term}'] + for item in CHORES.filter(term): + results.append(item) + results.append('-- End of List --') + return results if match.command('setup'): results = [] diff --git a/matrix_chore_bot/db.py b/matrix_chore_bot/db.py index 536c9c0..140f0a6 100644 --- a/matrix_chore_bot/db.py +++ b/matrix_chore_bot/db.py @@ -94,6 +94,17 @@ class Data(): results.append(Data.check_chore(session, chore.id)) return results + def filter(self, term): + results = [] + for item in self.list(): + if term in item: + results.append(item) + + return results + + + + def add(self, name): try: with Session(self.engine) as session: diff --git a/matrix_chore_bot/tasks.py b/matrix_chore_bot/tasks.py index 78d8d16..5a4eaa6 100644 --- a/matrix_chore_bot/tasks.py +++ b/matrix_chore_bot/tasks.py @@ -33,3 +33,10 @@ def list(c): result = Data().list() for item in result: print(f'{item}') + +@task +def filter(c, term): + result = Data().filter(term) + for item in result: + print(f'{item}') +