1 from turbot.puzzle import puzzle_blocks
2 from turbot.blocks import section_block, text_block
4 def round_blocks(round, puzzles, omit_header=False):
5 """Generate Slack blocks for a round
7 The 'round' argument should be the name of a round as it appears
8 in the datbase. The `puzzles` argument should be a list of
9 puzzles. The results will include only puzzles which have 'round'
10 in their 'rounds' attribute.
12 The return value is a list of bocks that can be used in any Slack
13 command acceepting blocks. It will provide all the details of the
14 puzzles in the given round, (their state, solutions, links to
15 channels and sheets, etc.).
21 round_text = "*Round: {}*".format(round)
24 section_block(text_block(round_text)),
27 for puzzle in puzzles:
28 if 'rounds' not in puzzle:
30 if round not in puzzle['rounds']:
32 blocks += puzzle_blocks(puzzle)
36 def round_quoted_puzzles_titles_answers(round, puzzles):
38 for puzzle in puzzles:
40 if 'rounds' not in puzzle:
42 if round not in puzzle['rounds']:
45 if 'rounds' in puzzle and len(puzzle['rounds']):
48 answer['name'] = puzzle['name']
49 if puzzle['status'] == 'solved' and 'solution' in puzzle:
50 answer['solution'] = ", ".join(puzzle['solution'])
52 answer['solution'] = ""
53 answers.append(answer)
58 longest = max(len(ans['name']) for ans in answers)
60 format = "%{}s: %s".format(longest)
62 return "```" + "\n".join(
63 [format % (ans['name'], ans['solution']) for ans in answers]