]> git.cworth.org Git - turbot/blobdiff - turbot/interaction.py
Use empty list instead of empty tuple in a few places
[turbot] / turbot / interaction.py
index 4a36b71b9e074eead82ce4fbb1fbd51643825e5a..a6ef7d6851618bcd5138d56e9e8d73b51b2297be 100644 (file)
@@ -267,10 +267,11 @@ def edit_puzzle_submission(turb, payload, metadata):
         puzzle['type'] = 'meta'
     else:
         puzzle['type'] = 'plain'
-    rounds = [option['value'] for option in
-              state['rounds']['rounds']['selected_options']]
-    if rounds:
-        puzzle['rounds'] = rounds
+    if 'rounds' in state:
+        rounds = [option['value'] for option in
+                  state['rounds']['rounds']['selected_options']]
+        if rounds:
+            puzzle['rounds'] = rounds
     new_rounds = state['new_rounds']['new_rounds']['value']
     puzzle_state = state['state']['state']['value']
     if puzzle_state:
@@ -282,9 +283,10 @@ def edit_puzzle_submission(turb, payload, metadata):
     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']:
@@ -501,7 +503,6 @@ def new_hunt_command(turb, body):
 def new_hunt_button(turb, payload):
     """Handler for the action of user pressing the new_hunt button"""
 
-    print("In new_hunt_button with payload of: " + str(payload))
     trigger_id = payload['trigger_id']
 
     return new_hunt(turb, trigger_id)
@@ -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)