From: Carl Worth Date: Thu, 22 Oct 2020 11:08:30 +0000 (-0700) Subject: Add a list of puzzles under each hunt on the Turbot home tab X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=94dcc9b3b2a1f0773a45e6dc7e7018afa9749e62;hp=26487f2823c7d0e3690017c9b96e11da314457d1;p=turbot Add a list of puzzles under each hunt on the Turbot home tab Giving a simple overview of all puzzles in one place, including an emoji indication of whether the puzzle is solved or not. --- diff --git a/turbot/blocks.py b/turbot/blocks.py index a18c055..27e69f4 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -1,3 +1,8 @@ +def divider_block(): + return { + "type": "divider" + } + def text_block(body): return { "text": { diff --git a/turbot/events.py b/turbot/events.py index eff5778..c054982 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -1,8 +1,9 @@ from turbot.blocks import ( - section_block, text_block, button_block, actions_block + section_block, text_block, button_block, actions_block, divider_block ) import turbot.sheets import turbot.slack +import itertools TURBOT_USER_ID = 'U01B9QM4P9R' @@ -11,13 +12,36 @@ events = {} lambda_success = {'statusCode': 200} lambda_error = {'statusCode': 400} -def hunt_block(hunt): +def puzzle_block(puzzle): + name = puzzle['name'] + status = puzzle['status'] + channel_id = puzzle['channel_id'] + status_emoji = '' + + if status == 'solved': + status_emoji = ":ballot_box_with_check:" + else: + status_emoji = ":white_square:" + + puzzle_text = "{} {}: <#{}>".format(status_emoji, name, channel_id) + + return section_block(text_block(puzzle_text)) + +def hunt_block(turb, hunt): name = hunt['name'] + hunt_id = hunt['hunt_id'] channel_id = hunt['channel_id'] - text = "{}: <#{}>".format(name, channel_id) + response = turb.db.Table(hunt_id).scan() + puzzles = response['Items'] + + hunt_text = "*{}*: <#{}>".format(name, channel_id) - return section_block(text_block(text)) + return [ + section_block(text_block(hunt_text)), + *[puzzle_block(puzzle) for puzzle in puzzles], + divider_block() + ] def home(turb, user_id): """Returns a view to be published as the turbot home tab for user_id @@ -32,11 +56,17 @@ def home(turb, user_id): except Exception: hunts = [] + hunt_blocks = [] + for hunt in hunts: + if hunt['active']: + hunt_blocks += hunt_block(turb, hunt) + return { "type": "home", "blocks": [ section_block(text_block("*Active hunts*")), - *[hunt_block(hunt) for hunt in hunts if hunt['active']], + divider_block(), + * hunt_blocks, actions_block(button_block("New hunt", "new_hunt")) ] }