From 99af120949f95dc808a99e4e32049da0dc8c064f Mon Sep 17 00:00:00 2001 From: Edward Delaporte Date: Thu, 9 Apr 2026 07:53:11 -0500 Subject: [PATCH] Fix for buying multiple items in one command --- matrix_shop_bot/bot.py | 10 +++++----- matrix_shop_bot/db.py | 12 ++++++++++++ matrix_shop_bot/tasks.py | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/matrix_shop_bot/bot.py b/matrix_shop_bot/bot.py index 387cf18..37677c5 100644 --- a/matrix_shop_bot/bot.py +++ b/matrix_shop_bot/bot.py @@ -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'): diff --git a/matrix_shop_bot/db.py b/matrix_shop_bot/db.py index 6f29260..186350a 100644 --- a/matrix_shop_bot/db.py +++ b/matrix_shop_bot/db.py @@ -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() diff --git a/matrix_shop_bot/tasks.py b/matrix_shop_bot/tasks.py index 73f57e2..29911a9 100644 --- a/matrix_shop_bot/tasks.py +++ b/matrix_shop_bot/tasks.py @@ -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 -- 2.47.3