]> git.cworth.org Git - turbot/blobdiff - turbot/interaction.py
Convert the solution data structure back to a list, (but still avoid dupes.)
[turbot] / turbot / interaction.py
index cbb8befe2bcb3eb4ebf3df0d7f3165fcf1f5e128..86f438c372b5358c8641d3497809d4d1b5b6ba3f 100644 (file)
@@ -187,7 +187,7 @@ def edit_puzzle(turb, puzzle, trigger_id):
         solved = True
 
     solution_str = None
-    solution_list = puzzle.get("solution", [])
+    solution_list = puzzle.get("solution", ())
     if solution_list:
         solution_str = ", ".join(solution_list)
 
@@ -280,12 +280,13 @@ def edit_puzzle_submission(turb, payload, metadata):
         puzzle['status'] = 'solved'
     else:
         puzzle['status'] = 'unsolved'
-    puzzle['solution'] = []
+    puzzle['solution'] = ()
     solution = state['solution']['solution']['value']
     if solution:
-        puzzle['solution'] = [
+        # Construct a list from a set to avoid any duplicates
+        puzzle['solution'] = list({
             sol.strip() for sol in solution.split(',')
-        ]
+        })
 
     # Verify that there's a solution if the puzzle is mark solved
     if puzzle['status'] == 'solved' and not puzzle['solution']:
@@ -1044,7 +1045,7 @@ def new_puzzle_submission(turb, payload, metadata):
     if rounds:
         puzzle['rounds'] = rounds
 
-    puzzle['solution'] = []
+    puzzle['solution'] = ()
     puzzle['status'] = 'unsolved'
 
     # Create a channel for the puzzle
@@ -1184,7 +1185,10 @@ def solved(turb, body, args):
 
     # Set the status and solution fields in the database
     puzzle['status'] = 'solved'
-    puzzle['solution'].append(args)
+
+    # Don't append a duplicate solution
+    if args not in puzzle['solution']:
+        puzzle['solution'].append(args)
     if 'state' in puzzle:
         del puzzle['state']
     turb.table.put_item(Item=puzzle)