]> git.cworth.org Git - turbot/blobdiff - turbot/hunt.py
Correct typo in hunt description verbiage
[turbot] / turbot / hunt.py
index 77c179771a17cd7e01eed6f5d3230bf554a225b6..b538ea578c1405798af2a3332c55e4833360af48 100644 (file)
@@ -23,13 +23,21 @@ def find_hunt_for_hunt_id(turb, hunt_id):
     else:
         return None
 
-def hunt_blocks(turb, hunt):
+def hunt_blocks(turb, hunt, puzzle_status='unsolved'):
     """Generate Slack blocks for a hunt
 
     The hunt argument should be a dictionary as returned from the
-    database. The return value can be used in a Slack command
-    expecting blocks to provide all the details of a hunt, (puzzles,
-    their state, solution, links to channels and sheets, etc.).
+    database.
+
+    Option 'puzzle_status' indicates which puzzles to include. If
+    either 'solved' or 'unsolved' only puzzles with that status from
+    the hunt will be included in the result. If any other value, all
+    puzzles in the hunt will be included.
+
+    The return value can be used in a Slack command expecting blocks to
+    provide all the details of a hunt, (puzzles, their state,
+    solution, links to channels and sheets, etc.).
+
     """
 
     name = hunt['name']
@@ -44,6 +52,10 @@ def hunt_blocks(turb, hunt):
     )
     puzzles = response['Items']
 
+    # Filter the set of puzzles according the the requested puzzle_status
+    if puzzle_status in ('solved', 'unsolved'):
+        puzzles = [p for p in puzzles if p['status'] == puzzle_status]
+
     # Compute the set of rounds across all puzzles
     rounds = set()
     for puzzle in puzzles:
@@ -65,7 +77,7 @@ def hunt_blocks(turb, hunt):
     # Also blocks for any puzzles not in any round
     stray_puzzles = [puzzle for puzzle in puzzles if 'rounds' not in puzzle]
     if len(stray_puzzles):
-        stray_text = "*Puzzles with no asigned round*"
+        stray_text = "*Puzzles with no assigned round*"
         blocks.append(section_block(text_block(stray_text)))
         for puzzle in stray_puzzles:
             blocks.append(puzzle_block(puzzle))