]> us-delaporte.pagekite.me Git - matrix-shop-bot.git/commitdiff
Fix for clear command
authorEdward Delaporte <edward@delaporte.us>
Thu, 9 Apr 2026 22:08:09 +0000 (17:08 -0500)
committerEdward Delaporte <edward@delaporte.us>
Thu, 9 Apr 2026 22:08:09 +0000 (17:08 -0500)
matrix_shop_bot/bot.py
matrix_shop_bot/db.py
matrix_shop_bot/tasks.py

index 037de7fdcb461d6dc5b09a8ad536ec89272d00e8..46ba972de0b86c0fbaefdd3c9d84b3b0b65d7374 100644 (file)
@@ -97,16 +97,14 @@ async def do_shop(match):
         return results
 
     if match.command('clear'):
-        store_id = ' '.join(match.args()[1:])
-        Data().clear_list(store_id)
-        self.last_store_id = None
-        return ['Success']
+        store_name = ' '.join(match.args()[1:])
+        results = Data().clear_list(store_name)
+        return results
 
     if match.command('clear.all'):
-        store_id = ' '.join(match.args()[1:])
-        Data().clear_list(store_id, clear_all=True)
-        return ['Success']
-
+        store_name = ' '.join(match.args()[1:])
+        results = Data().clear_list(store_name, clear_all=True)
+        return results
 
     if match.command('at'):
         store_name = ' '.join(match.args()[1:])
index 60339ee13e9d290c71d6ea395046b733a63502d2..278d4a15b8e8b75bce37636a496af4efcd967975 100644 (file)
@@ -183,13 +183,20 @@ class Data():
         return results
 
 
-    def clear_list(self, store_id, clear_all=False):
+    def clear_list(self, store_name, clear_all=False):
+        results = []
         with Session(self.engine) as session:
-            store = session.exec(_get_with_id(Store, store_id)).first()
+            store = session.exec(_get_with_name(Store, store_name)).first()
+            if not store:
+                return [f'Store {store_name} not found.']
+
             for item in store.shopping_list:
                 if clear_all or item.purchase_date:
                     session.delete(item)
+
             session.commit()
+            results = store.get_pretty_shopping_list()
+        return results
 
     def get_stores(self):
         with Session(self.engine) as session:
index 6b999bfb192720fa4814f2568c80bd893468d92d..8d1125ee36ff3688ab3f0aa01515459d469b81d1 100644 (file)
@@ -46,12 +46,10 @@ def list_bought(c, store):
         print(str(item))
 
 @task
-def clear_all(c, store_id):
-    Data().clear_list(store_id, clear_all=True)
-
-@task
-def clear_list(c, store_id):
-    Data().clear_list(store_id)
+def clear(c, store_name, clear_all=False):
+    results = Data().clear_list(store_name, clear_all)
+    for item in results:
+        print(str(item))
 
 
 @task