]> git.cworth.org Git - turbot/blobdiff - turbot/round.py
Add notes on how to update the Google sheets credentials
[turbot] / turbot / round.py
index 3c4042be6a6d0e94094ba3282c8cc0198ae403b3..73f23d75bc32aa3544b8f0b62569c84ccd10af1d 100644 (file)
@@ -1,7 +1,7 @@
-from turbot.puzzle import puzzle_block
+from turbot.puzzle import puzzle_blocks
 from turbot.blocks import section_block, text_block
 
-def round_blocks(round, puzzles):
+def round_blocks(round, puzzles, omit_header=False):
     """Generate Slack blocks for a round
 
     The 'round' argument should be the name of a round as it appears
@@ -15,17 +15,50 @@ def round_blocks(round, puzzles):
     channels and sheets, etc.).
     """
 
-    round_text = "*Round: {}*".format(round)
+    if omit_header:
+        blocks = []
+    else:
+        round_text = "*Round: {}*".format(round)
 
-    blocks = [
-        section_block(text_block(round_text)),
-    ]
+        blocks = [
+            section_block(text_block(round_text)),
+        ]
 
     for puzzle in puzzles:
         if 'rounds' not in puzzle:
             continue
         if round not in puzzle['rounds']:
             continue
-        blocks.append(puzzle_block(puzzle))
+        blocks += puzzle_blocks(puzzle)
 
     return blocks
+
+def round_quoted_puzzles_titles_answers(round, puzzles):
+    answers = []
+    for puzzle in puzzles:
+        if round:
+            if 'rounds' not in puzzle:
+                continue
+            if round not in puzzle['rounds']:
+                continue
+        else:
+            if 'rounds' in puzzle and len(puzzle['rounds']):
+                continue
+        answer = {}
+        answer['name'] = puzzle['name']
+        if puzzle['status'] == 'solved' and 'solution' in puzzle:
+            answer['solution'] = ", ".join(puzzle['solution'])
+        else:
+            answer['solution'] = ""
+        answers.append(answer)
+
+    if not answers:
+        return ""
+
+    longest = max(len(ans['name']) for ans in answers)
+
+    format = "%{}s: %s".format(longest)
+
+    return "```" + "\n".join(
+        [format % (ans['name'], ans['solution']) for ans in answers]
+    ) + "```"