From 4b3efe6fde2dd926f5b54eb357ed732e9e04d9e0 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 7 Jan 2021 09:05:34 -0800 Subject: [PATCH] Wire up a function to handle the edit_puzzle button It doesn't actually _do_ anything yet, but should at least prevent the warning sign which was appearing before. And this should let us see if the action_id field is a good way of plumbing the hunt_id and puzzle_id through to the handler for the press of the edit_puzzle button. --- turbot/blocks.py | 10 ++++++++-- turbot/interaction.py | 17 ++++++++++++++++- turbot/puzzle.py | 7 ++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/turbot/blocks.py b/turbot/blocks.py index cfef7f6..c037b03 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -23,8 +23,9 @@ def actions_block(*elements): "elements": list(elements) } -def button_block(label, name): - return { +def button_block(label, name, extra=None): + + block = { "type": "button", "text": { "type": "plain_text", @@ -34,6 +35,11 @@ def button_block(label, name): "value": name } + if extra: + block['action_id'] = extra + + return block + def accessory_block(main, accessory): return { **main, diff --git a/turbot/interaction.py b/turbot/interaction.py index b81541c..f9fcede 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -16,10 +16,16 @@ from turbot.slack import slack_send_message import shlex actions = {} +actions['button'] = {} commands = {} submission_handlers = {} # Hunt/Puzzle IDs are restricted to lowercase letters, numbers, and underscores +# +# Note: This restriction not only allows for hunt and puzzle ID values to +# be used as Slack channel names, but it also allows for '-' as a valid +# separator between a hunt and a puzzle ID (for example in the puzzle +# edit dialog where a single attribute must capture both values). valid_id_re = r'^[_a-z0-9]+$' lambda_ok = {'statusCode': 200} @@ -63,6 +69,15 @@ def multi_static_select(turb, payload): actions['multi_static_select'] = {"*": multi_static_select} +def edit_puzzle(turb, payload): + """Handler for the action of user pressing an edit_puzzle button""" + + print("DEBUG: In edit_puzzle with payload: {}".format(str(payload))) + + return lambda_ok + +actions['button']['edit_puzzle'] = edit_puzzle + def new_hunt(turb, payload): """Handler for the action of user pressing the new_hunt button""" @@ -88,7 +103,7 @@ def new_hunt(turb, payload): return lambda_ok -actions['button'] = {"new_hunt": new_hunt} +actions['button']['new_hunt'] = new_hunt def new_hunt_submission(turb, payload, metadata): """Handler for the user submitting the new hunt modal diff --git a/turbot/puzzle.py b/turbot/puzzle.py index 3c85df4..81e0630 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -69,10 +69,15 @@ def puzzle_blocks(puzzle): ', '.join(links), state_str ) + # Combining hunt ID and puzzle ID together here is safe because + # both IDs are restricted to not contain a hyphen, (see + # valid_id_re in interaction.py) + hunt_and_puzzle = "{}-{}".format(puzzle['hunt_id'], puzzle['puzzle_id']) + return [ accessory_block( section_block(text_block(puzzle_text)), - button_block("✏", puzzle['puzzle_id']) + button_block("✏", "edit_puzzle", hunt_and_puzzle) ) ] -- 2.43.0