From: Edward Delaporte Date: Thu, 9 Apr 2026 22:08:09 +0000 (-0500) Subject: Fix for clear command X-Git-Url: https://apps.delaporte.us/gitweb/matrix-shop-bot.git/commitdiff_plain/b988f8c87df51797f52d20ae91c14c739459b758?hp=8b639943d820c97787fed92731f0ec8d13e9ac7e Fix for clear command --- diff --git a/matrix_shop_bot/bot.py b/matrix_shop_bot/bot.py index 037de7f..46ba972 100644 --- a/matrix_shop_bot/bot.py +++ b/matrix_shop_bot/bot.py @@ -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:]) diff --git a/matrix_shop_bot/db.py b/matrix_shop_bot/db.py index 60339ee..278d4a1 100644 --- a/matrix_shop_bot/db.py +++ b/matrix_shop_bot/db.py @@ -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: diff --git a/matrix_shop_bot/tasks.py b/matrix_shop_bot/tasks.py index 6b999bf..8d1125e 100644 --- a/matrix_shop_bot/tasks.py +++ b/matrix_shop_bot/tasks.py @@ -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