From 10dd20653d14706cc1c7689745f8bcd80c29fa2b Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 6 Jan 2021 20:42:21 -0800 Subject: [PATCH] Add an edit button next to each puzzle This will appear in both the Turbot home screen as well as in the output from the /hunt command. --- turbot/blocks.py | 8 ++++++++ turbot/hunt.py | 4 ++-- turbot/puzzle.py | 13 ++++++++++--- turbot/round.py | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/turbot/blocks.py b/turbot/blocks.py index 661cff3..cfef7f6 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -34,6 +34,14 @@ def button_block(label, name): "value": name } +def accessory_block(main, accessory): + return { + **main, + "accessory": { + **accessory + } + } + def input_block(label, name, placeholder, optional=False): return { "type": "input", diff --git a/turbot/hunt.py b/turbot/hunt.py index d6ca6b6..ccab28d 100644 --- a/turbot/hunt.py +++ b/turbot/hunt.py @@ -1,6 +1,6 @@ from turbot.blocks import section_block, text_block, divider_block from turbot.round import round_blocks -from turbot.puzzle import puzzle_block, puzzle_matches_all +from turbot.puzzle import puzzle_blocks, puzzle_matches_all from turbot.channel import channel_url from boto3.dynamodb.conditions import Key @@ -108,7 +108,7 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[]): 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)) + blocks += puzzle_blocks(puzzle) blocks.append(divider_block()) diff --git a/turbot/puzzle.py b/turbot/puzzle.py index 7db006b..3c85df4 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -1,4 +1,6 @@ -from turbot.blocks import section_block, text_block +from turbot.blocks import ( + section_block, text_block, button_block, accessory_block +) from turbot.channel import channel_url from boto3.dynamodb.conditions import Key import re @@ -24,7 +26,7 @@ def find_puzzle_for_url(turb, hunt_id, url): return response['Items'][0] -def puzzle_block(puzzle): +def puzzle_blocks(puzzle): """Generate Slack blocks for a puzzle The puzzle argument should be a dictionary as returned from the @@ -67,7 +69,12 @@ def puzzle_block(puzzle): ', '.join(links), state_str ) - return section_block(text_block(puzzle_text)) + return [ + accessory_block( + section_block(text_block(puzzle_text)), + button_block("✏", puzzle['puzzle_id']) + ) + ] def puzzle_matches_one(puzzle, pattern): """Returns True if this puzzle matches the given string (regexp) diff --git a/turbot/round.py b/turbot/round.py index 3c4042b..3a4266f 100644 --- a/turbot/round.py +++ b/turbot/round.py @@ -1,4 +1,4 @@ -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): @@ -26,6 +26,6 @@ def round_blocks(round, puzzles): continue if round not in puzzle['rounds']: continue - blocks.append(puzzle_block(puzzle)) + blocks += puzzle_blocks(puzzle) return blocks -- 2.43.0