]> apps.delaporte.us Git - matrix-shop-bot.git/blobdiff - matrix_shop_bot/bot.py
Fix error code
[matrix-shop-bot.git] / matrix_shop_bot / bot.py
index 12aaf794fcadac8845ff999522ff7e24c6b19bf6..f426663a8b8a6f42cb2a6f00a516e62ab13618c3 100644 (file)
@@ -65,8 +65,14 @@ async def do_shop(match):
     if match.command('assign'):
         store_id = int(match.args()[1])
         item_id  = int(match.args()[2])
-        result = Data().assign_store(store_id, item_id)
-        return [result]
+        Data().assign_store(store_id, item_id)
+
+        # Now print the list for the assigned store
+        items = Data().get_shopping_list(store_id)
+        results = ['Shopping List']
+        for item in items:
+            results.append(str(item))
+        return results
 
     if match.command('buy'):
         item_id = ' '.join(match.args()[1:])
@@ -76,6 +82,7 @@ async def do_shop(match):
     if match.command('clear'):
         store_id = ' '.join(match.args()[1:])
         Data().clear_list(store_id)
+        self.last_store_id = None
         return ['Success']
 
     if match.command('clear-all'):
@@ -85,7 +92,11 @@ async def do_shop(match):
 
     if match.command('list'):
         store_id = ' '.join(match.args()[1:])
+        if len(store_id) == 0:
+            store_id = None
+
         items = Data().get_shopping_list(store_id)
+        results = ['Shopping List']
         for item in items:
             results.append(str(item))
         return results
@@ -122,6 +133,9 @@ async def shop_bot(room, message, bot):
                 await bot.api.send_text_message(
                     room.room_id, str(line))
     except Exception as ex:
-        return ['You have:', '    no tea']
+        for line in ['You have:', '    no tea']:
+            await bot.api.send_text_message(
+                room.room_id, str(line))
+