]> us-delaporte.pagekite.me Git - matrix-chore-bot.git/commitdiff
Add filter command
authorEdward Delaporte <edward@delaporte.us>
Tue, 31 Mar 2026 21:30:11 +0000 (16:30 -0500)
committerEdward Delaporte <edward@delaporte.us>
Tue, 31 Mar 2026 21:30:11 +0000 (16:30 -0500)
matrix_chore_bot/bot.py
matrix_chore_bot/db.py
matrix_chore_bot/tasks.py

index 7e33ade92560c452a0914aad5a0cceda0b6e6d47..c97be63659ba47f057b6b1f47aaee85bcc0966d9 100644 (file)
@@ -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 = []
index 536c9c08fb7640e056271763ab69d6bfb35acdfb..140f0a682b8ad4c99b530e4e66655df9bd63f6ce 100644 (file)
@@ -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:
index 78d8d16fbaba658a60a9af278475fe9c4b585649..5a4eaa6dadfa183cb28b81872912007f8266ac1e 100644 (file)
@@ -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}')
+