]> apps.delaporte.us Git - matrix-shop-bot.git/commitdiff
Fix for buying multiple items in one command
authorEdward Delaporte <edward@delaporte.us>
Thu, 9 Apr 2026 12:53:11 +0000 (07:53 -0500)
committerEdward Delaporte <edward@delaporte.us>
Sun, 7 Jun 2026 00:29:23 +0000 (19:29 -0500)
matrix_shop_bot/bot.py
matrix_shop_bot/db.py
matrix_shop_bot/tasks.py

index 387cf184af205789ef5e4a919701166600df73ed..37677c53bec9e3762b3327f87f27f545bea3aeec 100644 (file)
@@ -89,11 +89,11 @@ async def do_shop(match):
         return results
 
     if match.command('buy'):
-        item_id = ' '.join(match.args()[1:])
-        Data().purchase_item(item_id)
-        results = []
-        for item in Data().get_last_shopping_list():
-            results.append(str(item))
+        items = ' '.join(match.args()[1:])
+        results = Data().purchase_items(items)
+        # results = []
+        # for item in Data().get_last_shopping_list():
+        #    results.append(str(item))
         return results
 
     if match.command('clear'):
index 6f29260d7be08e8276cb0766b4c7a13cc3cd2d29..186350acfd606f2fd1c5d03da8f25e931341b040 100644 (file)
@@ -127,6 +127,18 @@ class Data():
                 pass # Already assigned
         return ['Success']
 
+
+    def purchase_items(self, item_ids):
+        results = []
+        with Session(self.engine) as session:
+            for item_id in item_ids.split(' '):
+                item = session.exec(_get_with_id(Item, item_id)).first()
+                if item:
+                    item.purchase_date = dt.today()
+                results.append(str(item))
+            session.commit()
+        return results
+
     def purchase_item(self, item_id):
         with Session(self.engine) as session:
             item = session.exec(_get_with_id(Item, item_id)).first()
index 73f57e253566a2bb8c0d30b44dd11b7784475272..29911a97f6b7e7482c402d9f3c175e80e6cd9d55 100644 (file)
@@ -31,8 +31,8 @@ def assign_to_store(c, item_id, store_id):
 
 
 @task
-def buy(c, item_id):
-    result = Data().purchase_item(item_id)
+def buy(c, items):
+    result = Data().purchase_items(items)
     print(result)
 
 @task