]> git.cworth.org Git - turbot/blob - turbot/round.py
3a4266faae1483e4d2e68351de9a825f3eb1309f
[turbot] / turbot / round.py
1 from turbot.puzzle import puzzle_blocks
2 from turbot.blocks import section_block, text_block
3
4 def round_blocks(round, puzzles):
5     """Generate Slack blocks for a round
6
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.
11
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.).
16     """
17
18     round_text = "*Round: {}*".format(round)
19
20     blocks = [
21         section_block(text_block(round_text)),
22     ]
23
24     for puzzle in puzzles:
25         if 'rounds' not in puzzle:
26             continue
27         if round not in puzzle['rounds']:
28             continue
29         blocks += puzzle_blocks(puzzle)
30
31     return blocks